Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shared sessionStrategy: UnknownError when getSession() called in second test method #53

Closed
Jodes81 opened this issue Jul 27, 2015 · 7 comments

Comments

@Jodes81
Copy link

Jodes81 commented Jul 27, 2015

I am running tests with PHPUnit, using Mink to write acceptance tests.

I have come across the error when modifying the "GeneralTest" class given in the examples.

To reproduce:

  1. I add this to the $browser array: 'sessionStrategy' => 'shared'
  2. I copy the method testUsingSession() and paste as testUsingSession2()

For now, the only workaround I have is to omit the shared session declaration and have a new browser window load for each test method (unnecessarily slow).

@aik099
Copy link
Member

aik099 commented Jul 27, 2015

Can you please describe what you want to achieve instead?

Following example should be working:

<?php
class ExampleTest extends BrowserTestCase
{

    public static $browsers = array(
        array(
            // ....
            'sessionStrategy' => 'shared',
            // ....
        )
    );

    public function testSomethingNeededForOtherTests()
    {
        $session = $this->getSession();
        $session->visit('http://www.google.com');

    }

    /*
     * @depends testSomethingNeededForOtherTests
     */
    public function testTwo()
    {
        $session = $this->getSession();

        // here you'll be on that http://www.google.com
    }
}

I don't know your usecase, because even with isolated session strategy same browser window is reused.

@aik099
Copy link
Member

aik099 commented Jul 27, 2015

Ah, I understand now why you started to use shared sessionStrategy - to reuse same browser window. This however also reuses all cookies that are set in each test, which results in tests not being so isolated anymore.

Maybe it would be best if you can implement #5 feature instead?

@Jodes81
Copy link
Author

Jodes81 commented Jul 27, 2015

Thanks, I will investigate the #5 feature.

But your ExampleTest code does not run, I get the same error:

"C:\wamp\bin\php\php5.4.12\php.exe" "C:\phpbin\phpunit.phar" "--colors" "--log-junit" "C:\Users\jody\AppData\Local\Temp\nb-phpunit-log.xml" "C:\Users\jody\AppData\Roaming\NetBeans\8.0.1\phpunit\NetBeansSuite.php" "--run=C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\ExampleTest.php"
PHPUnit 4.7.7 by Sebastian Bergmann and contributors.

.E

Time: 4.44 seconds, Memory: 16.25Mb

There was 1 error:

1) ExampleTest::testTwo
WebDriver\Exception\UnknownError: Build info: version: '2.46.0', revision: '87c69e2', time: '2015-06-04 16:16:47'
System info: host: 'jody8', ip: '192.168.56.1', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.8.0_45'
Driver info: driver.version: unknown

C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\instaclick\php-webdriver\lib\WebDriver\Exception.php:155
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\instaclick\php-webdriver\lib\WebDriver\AbstractWebDriver.php:140
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\instaclick\php-webdriver\lib\WebDriver\Session.php:273
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\behat\mink-selenium2-driver\src\Behat\Mink\Driver\Selenium2Driver.php:423
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\behat\mink\src\Session.php:283
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\aik099\phpunit-mink\library\aik099\PHPUnit\Session\SharedSessionStrategy.php:131
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\aik099\phpunit-mink\library\aik099\PHPUnit\Session\SharedSessionStrategy.php:103
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\aik099\phpunit-mink\library\aik099\PHPUnit\BrowserTestCase.php:289
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\ExampleTest.php:33
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\aik099\phpunit-mink\library\aik099\PHPUnit\BrowserTestCase.php:371
C:\Users\jody\Documents\NetBeansProjects\DabbleLabs_v0.04.XXX\tests\acceptance\vendor\aik099\phpunit-mink\library\aik099\PHPUnit\BrowserTestCase.php:319

FAILURES!
Tests: 2, Assertions: 0, Errors: 1.
Done.

I'm not sure what you mean by my usecase, but regarding your comment "because even with isolated session strategy same browser window is reused", it is not true for me: For each test, the browser opens (taking 4 seconds or so each time) and then closes before the next test.

@aik099
Copy link
Member

aik099 commented Jul 27, 2015

But your ExampleTest code does not run, I get the same error:

Does this work if you try different browser (or different browser version) and different Selenium server version. It can be bug in latest Selenium server version as well.

because even with isolated session strategy same browser window is reused

That maybe is how I wanted it to happen, but after finding #5 I realized that this isn't the case.

After a bit of debugging I've found a bug, that only happens, when you've have, within same test suite:

  • some tests using shared session strategy
  • some tests using isolated session strategy

Then end of test using shared session strategy triggers isolated session strategy by mistake, which ends the session, when it shouldn't.

@aik099
Copy link
Member

aik099 commented Jul 27, 2015

I've created #54 . Please test, by applying changes made there locally, if that does solve the problem you're describing?

If it does, then @depends comments aren't needed if the only purpose for using shared session strategy is to get less browser windows opened.

@Jodes81
Copy link
Author

Jodes81 commented Jul 27, 2015

I'm still grappling understanding all this, but AFAIK all the tests are using shared session - I have only been running ExampleTest on its own.

But there was success with #54, I copied over the replacement IsolatedSessionStrategy.php and SharedSessionStrategy.php , and now it works as expected.

Thanks!

@aik099
Copy link
Member

aik099 commented Aug 1, 2015

I've released 2.1.1 version (see https://github.com/minkphp/phpunit-mink/releases/tag/v2.1.1). I recommend updating to that version in the composer.json (usually doing composer update is fine) instead of manually overwriting files from vendor folder as you told you did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants