phpunit-mink icon indicating copy to clipboard operation
phpunit-mink copied to clipboard

Session doesn't work with Selenium2 driver

Open JohnnyEvo opened this issue 8 years ago • 5 comments

Hi,

I work with PHP7 and PHPUnit >5 .

This is my composer.json :

"phpunit/phpunit": "~5.4",
"behat/mink": "^1.7",
"behat/mink-goutte-driver": "^1.2",
"behat/mink-selenium2-driver": "^1.3",
"aik099/phpunit-mink": "~2.0",
"behat/mink-extension": "*"

This is my test :

<?php

use aik099\PHPUnit\BrowserTestCase;

/**
 * Test du navigateur
 *
 * @author  Johnny Charcosset <[email protected]>
 *
 * @group   Browser
 *
 * @coversNothing
 */
class BrowserTest extends BrowserTestCase
{
    /**
     * @var array
     */
    public static $browsers = array(
        array(
            'port' => 80
        ),
    );

    /**
     *
     * @author Johnny Charcosset <[email protected]>
     */
    public function testUsingSession()
    {
        // This is Mink's Session.
        $session = $this->getSession();

        // Go to a page.
        $session->visit('http://localhost/app_dev.php/fr_FR/login');

        // Validate text presence on a page.
        var_dump($session->getCurrentUrl());
        var_dump($session->getPage()->getContent());
        var_dump($this->getBrowser()->getBrowserName());
        $this->assertTrue(true);
    }
}

And the output :

NULL
string(0) ""
string(7) "firefox"

I update the phpunit-mink to work with PHP7 & PHPUnit >5 : https://github.com/JohnnyEvo/phpunit-mink/blob/master/library/aik099/PHPUnit/BrowserTestCase.php#L33 (based on stof work from mink)

With Goutte driver it's ok.

Why $session->visit returns NULL value ? Update : Why $session->getCurrentUrl() returns NULL value ?

Regards, Johnny

JohnnyEvo avatar May 17 '17 15:05 JohnnyEvo

Because that's how it works in Mink: https://github.com/minkphp/Mink/blob/master/src/Session.php#L141-L149 . I haven't changed that Mink behavior in this library.

The only way to see if you're on the page you're going to is to compare current url in browser with the one you're going to.

aik099 avatar May 17 '17 18:05 aik099

I update the phpunit-mink to work with PHP7 & PHPUnit >5 : https://github.com/JohnnyEvo/phpunit-mink/blob/master/library/aik099/PHPUnit/BrowserTestCase.php#L33 (based on stof work from mink)

Can you please send a PR with it. I wonder why it's not included in release already.

aik099 avatar May 17 '17 18:05 aik099

I was wrong, I speak getCurrentUrl() method and not visit() method 😞 : https://github.com/minkphp/Mink/blob/master/src/Session.php#L237-L245 It should return me the address "http://localhost/app_dev.php/fr_FR/login" but it returns NULL

Can you please send a PR with it. I wonder why it's not included in release already.

I look to make a pull request

JohnnyEvo avatar May 18 '17 06:05 JohnnyEvo

Since you're running MinkSelenium2Driver which controls real web browser you can actually see if ->visit( call had opened that page. If it didn't (e.g. the browser access permission dialog was opened instead) then it explains why getCurrentUrl method returns null.

P.S. This library is managing sessions for Mink and provides neat access to developer. If Mink methods doesn't work for specific driver/page then you should be placing issue in corresponding driver repo with reproducible standalone test case.

aik099 avatar May 18 '17 07:05 aik099

Maybe related: https://github.com/minkphp/MinkSelenium2Driver/issues/267

aik099 avatar May 19 '17 12:05 aik099

Without a reproducible example I can't implement any fix. Closing.

aik099 avatar Mar 15 '24 19:03 aik099