Warm tip: This article is reproduced from serverfault.com, please click

how to get current url from codeception & phantomjs test?

发布于 2016-04-14 15:05:41

I am creating product in estore with my test, and need to get url after submitting a form.

Is it possible to get url in the test scope after submitting button ?

$I->click('#formSubmit');
$I->wait(5); // wait for redirect to new url
$url = $I->someFunctionToGetCurrentUrl()`

I am running this test from console, not from the web browser, so I don't have access to $_SERVER that is on the server's side.

But if I have some methods like $I->canSeeCurrentUrlEquals() in codeception framework then i should somehow be able to access current url...

how to do it?

Questioner
Ilja
Viewed
0
Ilja 2016-04-15 02:45:06

The solution was to add a helper method to AcceptanceHelper in _support/AcceptanceHelper.php file:

    class AcceptanceHelper extends \Codeception\Module
    {

        /**
         * Get current url from WebDriver
         * @return mixed
         * @throws \Codeception\Exception\ModuleException
         */
        public function getCurrentUrl()
        {
            return $this->getModule('WebDriver')->_getCurrentUri();
        }

    }

and then use it in test:

$url = $I->getCurrentUrl();