简体   繁体   中英

Selenium2 with PhantomJS and PHPUnit - session/cookie issue

I have setup my current project to run with Selenium and PhantomJS. (Similar setup to http://www.nuanced.it/2015/05/using-phantomjs-with-phpunit.html )

However I keep on getting following error

{"errorMessage":"Can only set Cookies for the current domain","request":{"headers":{"Accept":"application/json;charset=UTF-8","Content-Length":"135","Content-type":"application/json;charset=UTF-8","Host":"127.0.0.1:8080"},"httpVersion":"1.1","method":"POST","post":"{\"cookie\":{\"name\":\"PHPUNIT_SELENIUM_TEST_ID\",\"value\":\"PepperLeaf\\\\WebBundle\\\\Tests\\\\MyProject\\\\TestFirstTest__testTitle\",\"secure\":false}}","url":"/cookie","urlParsed":{"anchor":"","query":"","file":"cookie","directory":"/","path":"/cookie","relative":"/cookie","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/cookie","queryKey":{},"chunks":["cookie"]},"urlOriginal":"/session/0d022670-4f79-11e5-abbe-01f06bc40b42/cookie"}}

Output from PhantomJS

[INFO  - 2015-08-31T00:41:02.249Z] HUB Register - register - Registered with grid hub: http://127.0.0.1:4444/ (ok)
[INFO  - 2015-08-31T00:41:43.258Z] Session [0d022670-4f79-11e5-abbe-01f06bc40b42] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.0.0 Safari/538.1","webSecurityEnabled":true}
[INFO  - 2015-08-31T00:41:43.258Z] Session [0d022670-4f79-11e5-abbe-01f06bc40b42] - page.customHeaders:  - {}
[INFO  - 2015-08-31T00:41:43.258Z] Session [0d022670-4f79-11e5-abbe-01f06bc40b42] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.0.0","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"mac-10.9 (Mavericks)-64bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":false,"databaseEnabled":false,"locationContextEnabled":false,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2015-08-31T00:41:43.258Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 0d022670-4f79-11e5-abbe-01f06bc40b42

Code that I run on PHPUnit

class TestFirstTest extends \PHPUnit_Extensions_Selenium2TestCase {

    /**
     * {@inheritDoc}
     */
    protected function setUp()
    {
        $this->setBrowser('phantomjs');
        $this->setHost("127.0.0.1");
        $this->setPort(8080);
        $this->setBrowserUrl('http://www.mywebsite.dev/');
    }

    public function testTitle()
    {
        $this->url('/');
        $this->assertTitle('Example WWW Page');
    }
}

Disclaimer: I'm quite new to front end testing, this is my first go at this. I'm confused why this would be happening as I'm not setting up nor creating any cookies/sessions.

I'm not sure exactly what has caused this problem. However, this is my symfony/phpunit.xml (this is what has caused problems)

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
        backupGlobals               = "false"
        backupStaticAttributes      = "false"
        colors                      = "false"
        convertErrorsToExceptions   = "true"
        convertNoticesToExceptions  = "true"
        convertWarningsToExceptions = "true"
        processIsolation            = "false"
        stopOnFailure               = "false"
        syntaxCheck                 = "false"
        bootstrap                   = "../app/bootstrap.php.cache" >

    <testsuites>
        <testsuite name="PepperLeaf">
            <directory>../src/*/*Bundle/Tests</directory>
            <directory>../src/*/Bundle/*Bundle/Tests</directory>
        </testsuite>
    </testsuites>

    <php>
        <server name="KERNEL_DIR" value="app/" />
        <ini name="memory_limit" value="2048M" />
        <ini name="xdebug.max_nesting_level" value="500" />
    </php>

    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">../src</directory>
            <exclude>
                <directory>../src/*/*Bundle/Resources</directory>
                <directory>../src/*/*Bundle/Tests</directory>
                <directory>../src/*/Bundle/*Bundle/Resources</directory>
                <directory>../src/*/Bundle/*Bundle/Tests</directory>
                <directory>../src/*/Bundle/*Bundle/FrontTests</directory>
                <directory>../src/*/Bundle/*Bundle/DataFixtures</directory>
            </exclude>
        </whitelist>
    </filter>

    <logging>
        <log type="coverage-html" target="coverage" />
        <log type="coverage-xml" target="coverage/xml" />
        <log type="coverage-clover" target="logs/clover.xml" />
        <log type="coverage-crap4j" target="logs/crap4j.xml" />
        <log type="junit" target="logs/junit.xml" logIncompleteSkipped="false" />
    </logging>
</phpunit>

This is updated (working phpunit.xml script that WORKS). I'm not sure what exactly caused the problem above.

<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit>

    <testsuites>
        <testsuite name="PepperLeaf_Frontend">
            <directory>../src/*/*Bundle/FrontTests</directory>
        </testsuite>
    </testsuites>

    <php>
        <server name="KERNEL_DIR" value="app/" />
        <ini name="memory_limit" value="2048M" />
        <ini name="xdebug.max_nesting_level" value="500" />
    </php>

    <filter>
        <whitelist addUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">../src</directory>
            <exclude>
                <directory>../src/*/*Bundle/Resources</directory>
                <directory>../src/*/*Bundle/Tests</directory>
                <directory>../src/*/Bundle/*Bundle/Resources</directory>
                <directory>../src/*/Bundle/*Bundle/Tests</directory>
                <directory>../src/*/Bundle/*Bundle/DataFixtures</directory>
                <directory>../src/*/*Bundle/FrontTests</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM