module-webdriver icon indicating copy to clipboard operation
module-webdriver copied to clipboard

Verifying Full URL with domain and protocol

Open jltoo opened this issue 9 years ago • 10 comments

What are you trying to achieve?

To verify the page url by passing a FULL url with its protocol and domain. E.g. $I->seeInCurrentUrl("http://www.test.com");

What do you get instead?

I already tried seeCurrentUrlEquals and seeInCurrentUrl, only the path after the domain was able to be verified.

jltoo avatar Sep 29 '16 04:09 jltoo

You can create your own helper method:

public function seeFullUrlEquals($expected)
{
  $actual = $this->getModule('WebDriver')->webDriver->getCurrentURL();
  $this->assertEquals($expected, $actual);
}

@DavertMik this is the 3rd time when I posted this method, I think that it is a good candidate for adding to InnerBrowser.

Naktibalda avatar Sep 29 '16 17:09 Naktibalda

@Naktibalda how about for soft assertion only? Since I'll be doing a for loop for checking multiple links, and I don't want it to stop just because of 1 fail link.

jltoo avatar Sep 29 '16 23:09 jltoo

if your method is named seeFullUrlEquals, you can call canSeeFullUrlEquals, Codeception handles that automatically.

Naktibalda avatar Sep 30 '16 11:09 Naktibalda

Thanks! It works :) @Naktibalda

jltoo avatar Sep 30 '16 23:09 jltoo

Yes, please add this :-)
It has been asked here too: https://stackoverflow.com/a/38855743/1668200

Reason: Since you cannot access external URL's with Functional Tests, there are only Acceptance Tests left to achieve that. So in Acceptance Tests , getting the full URL should be standard, and just the local part should be the exception. So I would go so far as to delete this line https://github.com/Codeception/Codeception/blob/2.3/src/Codeception/Module/WebDriver.php#L597 and maybe create a new method called something like seeInLocalUrl() for that.

BTW: The documentation might be wrong at http://codeception.com/docs/modules/WebDriver#seeCurrentUrlEquals
What does this only matches the full URL mean? It only matches the local part (i.e. after http://www.example.com) - I wouldn't call that "full url".

ThomasLandauer avatar May 31 '17 13:05 ThomasLandauer

so I tried this:

class FunctionalTester extends \Codeception\Actor
{
    use _generated\FunctionalTesterActions;

   /**
    * Define custom actions here
    */
    public function seeFullUrlEquals($expected)
    {
      $actual = $this->getModule('WebDriver')->webDriver->getCurrentURL();
      $this->assertEquals($expected, $actual);
    }

}

and it can find the method, but then it fails because: $this->getModule('WebDriver') is not available there.

Anybody who really can give a good working solution for the latest codeception?

marcelloh avatar Oct 18 '17 13:10 marcelloh

a) Move this method to helper class. b) Do you actually use WebDriver in functional suite?

Naktibalda avatar Oct 18 '17 14:10 Naktibalda

We could also need this. Is a PR welcome?

DanielRuf avatar May 08 '19 17:05 DanielRuf

Related feature requests:

  • https://github.com/Codeception/Codeception/issues/3423
  • https://github.com/Codeception/Codeception/issues/5122
  • https://github.com/Codeception/Codeception/issues/5115

ThomasLandauer avatar Jan 10 '21 20:01 ThomasLandauer

synfony version:

    public function seeCurrentFullUrlEquals(string $expectedUrl): void
    {
        $client = $this->getModule('Symfony')->client;
        $actualFullUrl = $client->getHistory()->current()->getUri();
        $this->assertEquals($expectedUrl, $actualFullUrl);
    }

c33s avatar Nov 15 '22 22:11 c33s