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

Chrome driver 2.8/2.9 fails to run if coverage enabled

Open spencer-aerian opened this issue 11 years ago • 9 comments

I'm using selenium standalone 2.39 or 2.4 with Chromedriver 2.8 or 2.9 and Chrome 33 on ubuntu-64bit. The selenium system works ok if I run the python web driver so I've narrowed it down to this extension.

If I have coverage enabled in the phpunit.xml file or on the command line, the chrome browser fails to run properly with the error

Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs.

The browser starts with data:; as the start URL, but then crashes out without changing the URL.

I've notionally pinned this down to around line 289 of Selenium2TestCase.php where a session cookie is set, and the driver is failing at this point.

Whilst its not completely necessary for my requirements to have coverage for selenium tests, as part of a larger suite its a PITA.

I'm not sure how you'd go about modifying the code. Perhaps an edge case check for Chrome in prepareSession()?

spencer-aerian avatar Mar 05 '14 09:03 spencer-aerian

What is the nature of the error? If we catch the exception we must show the user the failure someway, otherwise he who expects coverage will have to open up the code to see that has happened.

giorgiosironi avatar Mar 09 '14 17:03 giorgiosironi

I agree we should catch the error. I can work around it at the moment by disabling coverage in my phpunit.xml file before running selenium2 tests for chrome. My query though is should the driver handle the fact (that it appears to me anyhow) that you can't set a cookie via the chrome driver until you've got the page loaded?

spencer-aerian avatar Mar 10 '14 10:03 spencer-aerian

Seeing this as well with coverage enabled...

nijel avatar Mar 26 '14 17:03 nijel

In the end I've workarounded it by opening URL in prepareSession: https://github.com/phpmyadmin/phpmyadmin/blob/master/test/selenium/TestBase.php#L148

Anyway I think setting cookie without actually opening some URL is wrong, you don't know for which domain it will be stored.

nijel avatar Mar 27 '14 11:03 nijel

Second nijel's comment - settting cookie without opening URL is wrong.

spencer-aerian avatar Mar 27 '14 13:03 spencer-aerian

This issue was fixed in https://github.com/sebastianbergmann/phpunit-selenium/pull/289 So the correct domain should be opened before the cookie is set.

julianseeger avatar Mar 27 '14 16:03 julianseeger

I was able to reproduce this with the latest version (1.4.2) using the 13.3 example in the PHPUnit docs with only a minor modification; i used chrome instead of firefox.

side note: I ran the test on Debian 8 with chrome 42.0

emkookmer avatar May 07 '15 08:05 emkookmer

There is an opened issue in ChromeDriver that talk about this exact problem. If you still experience it, it might be of interest to vote for it.

Meanwhile I use prepareSession() as suggested by @nijel. So in my test class I override that method with:

    public function prepareSession()
    {
        $session = parent::prepareSession();
        $this->url('/');

        return $session;
    }

PowerKiKi avatar Nov 09 '16 11:11 PowerKiKi

I've tried to integrate selenium testing in my local machine. Unfortunately, it fails for "chrome".

Installed Versions:

  • Selenium - 3.0.1
  • ChromeDriver 2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac)
  • geckodriver 0.11.1
  • phpunit/phpunit-selenium 3.0.2
  • Below is my test class
namespace ApplicationTest;
use PHPUnit_Extensions_Selenium2TestCase;
class MyTest extends PHPUnit_Extensions_Selenium2TestCase
{
    public function setUp()
    {
        $this->setBrowser('firefox'); // passed
        $this->setBrowser('chrome'); // failed
        $this->setBrowserUrl('http://localhost/');
    }
    public function testSimple()
    {
        $this->url('/login');
        $this->assertEquals('Login', $this->title());
    }
}

Following is the error:

PHPUnit_Extensions_Selenium2TestCase_WebDriverException: <unknown>: Failed to set the 'cookie' property on 'Document': Cookies are disabled inside 'data:' URLs.
  (Session info: chrome=55.0.2883.87)
  (Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.8.13-300.fc25.x86_64 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 13 milliseconds
Build info: version: '3.0.1', revision: '1969d75', time: '2016-10-18 09:48:19 -0700'
System info: host: 'localhost.localdomain', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.8.13-300.fc25.x86_64', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac), userDataDir=/tmp/.org.chromium.Chromium.AqtCMr}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, hasTouchScreen=false, version=55.0.2883.87, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true, unexpectedAlertBehaviour=}]
Session ID: c5990b5457ee0af2637003ff8699319f

as @PowerKiKi and @nijel suggests, it now works by adding the prepareSession() method. Both chrome and firefox are passing.

namespace ApplicationTest;

use PHPUnit_Extensions_Selenium2TestCase;

class SampleSeleniumTest extends PHPUnit_Extensions_Selenium2TestCase
{
    public function setUp()
    {
        $this->setBrowser('firefox');
        $this->setBrowser('chrome');
        $this->setBrowserUrl('http://localhost/');
    }

    public function testSimple()
    {
        $this->url('/login');
        $this->assertEquals('Login', $this->title());
    }
    
    public function prepareSession()
    {
        $session = parent::prepareSession();
        $this->url('/login');

        return $session;
    }
}

gabbydgab avatar Dec 13 '16 16:12 gabbydgab