Verifying Full URL with domain and protocol
jltoo opened this issue · 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.
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 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.
if your method is named seeFullUrlEquals
,
you can call canSeeFullUrlEquals
, Codeception handles that automatically.
Thanks! It works :) @Naktibalda
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".
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?
a) Move this method to helper class.
b) Do you actually use WebDriver in functional suite?
We could also need this. Is a PR welcome?
Related feature requests:
synfony version:
public function seeCurrentFullUrlEquals(string $expectedUrl): void
{
$client = $this->getModule('Symfony')->client;
$actualFullUrl = $client->getHistory()->current()->getUri();
$this->assertEquals($expectedUrl, $actualFullUrl);
}