I've been struggling for hours, but just cannot get my build to work.
I want to run some Selenium tests, using Facebook's PHPWebdriver and PhantomJS. It works fine locally, it works fine if I run everything from within the specific Docker image myself, but it keeps failing in Pipelines.
Here's my bitbucket-pipelines.yml file:
pipelines: default: # Run unit tests. - step: image: wadmiraal/bitbucket_pipelines_php:7.1 caches: - composer artifacts: - clover.xml - junit.log script: # Install dependencies. - composer install - cd tests - npm install # Run the development server and PhantomJS. - php -S localhost:9000 -t www/ router.php & - ./node_modules/phantomjs/lib/phantom/bin/phantomjs --webdriver=localhost:8910 & # Run the tests. - cd .. - vendor/bin/phpunit --coverage-clover clover.xml --log-junit junit.log
I've tried numerous ways to start PhantomJS, but it just doesn't work. I've thrown some "ps aux" calls in there to make sure it's running, and it is.
At first, I piped all stderr and stdout to /dev/null, but even with the above config (you see PhantomJS' output during the PHPUnit execution), there are no error messages.
And yet, Webdriver keeps on complaining: "Failed to connect to localhost port 8910: Connection refused"
Here's a sample of the output when running PHPUnit:
PHPUnit 6.5.4 by Sebastian Bergmann and contributors.
EEEEEEEEEEEEEEE...E..E..E[INFO - 2018-01-29T16:48:46.169Z] GhostDriver - Main - running on port 8910
[INFO - 2018-01-29T16:48:46.176Z] Session [45b450d0-0514-11e8-8810-7f18091449bd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO - 2018-01-29T16:48:46.176Z] Session [45b450d0-0514-11e8-8810-7f18091449bd] - page.customHeaders: - {}
[INFO - 2018-01-29T16:48:46.176Z] Session [45b450d0-0514-11e8-8810-7f18091449bd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-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 - 2018-01-29T16:48:46.176Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 45b450d0-0514-11e8-8810-7f18091449bd
[Mon Jan 29 16:48:46 2018] ::1:40182 [200]: /long_page.html
.[INFO - 2018-01-29T16:48:46.566Z] Session [45effa40-0514-11e8-8810-7f18091449bd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO - 2018-01-29T16:48:46.567Z] Session [45effa40-0514-11e8-8810-7f18091449bd] - page.customHeaders: - {}
[INFO - 2018-01-29T16:48:46.567Z] Session [45effa40-0514-11e8-8810-7f18091449bd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-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 - 2018-01-29T16:48:46.567Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 45effa40-0514-11e8-8810-7f18091449bd
[Mon Jan 29 16:48:46 2018] ::1:40188 [200]: /long_page.html
.[INFO - 2018-01-29T16:48:46.956Z] Session [462b7ca0-0514-11e8-8810-7f18091449bd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO - 2018-01-29T16:48:46.956Z] Session [462b7ca0-0514-11e8-8810-7f18091449bd] - page.customHeaders: - {}
[INFO - 2018-01-29T16:48:46.956Z] Session [462b7ca0-0514-11e8-8810-7f18091449bd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-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 - 2018-01-29T16:48:46.956Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 462b7ca0-0514-11e8-8810-7f18091449bd
[Mon Jan 29 16:48:47 2018] ::1:40196 [200]: /long_page.html
.[INFO - 2018-01-29T16:48:47.329Z] Session [466466f0-0514-11e8-8810-7f18091449bd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO - 2018-01-29T16:48:47.329Z] Session [466466f0-0514-11e8-8810-7f18091449bd] - page.customHeaders: - {}
[INFO - 2018-01-29T16:48:47.329Z] Session [466466f0-0514-11e8-8810-7f18091449bd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-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 - 2018-01-29T16:48:47.329Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 466466f0-0514-11e8-8810-7f18091449bd
[Mon Jan 29 16:48:47 2018] ::1:40202 [200]: /long_page.html
.[INFO - 2018-01-29T16:48:47.473Z] Session [467a5ff0-0514-11e8-8810-7f18091449bd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO - 2018-01-29T16:48:47.473Z] Session [467a5ff0-0514-11e8-8810-7f18091449bd] - page.customHeaders: - {}
[INFO - 2018-01-29T16:48:47.473Z] Session [467a5ff0-0514-11e8-8810-7f18091449bd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-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 - 2018-01-29T16:48:47.473Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 467a5ff0-0514-11e8-8810-7f18091449bd
[Mon Jan 29 16:48:47 2018] ::1:40208 [200]: /long_page.html
.[INFO - 2018-01-29T16:48:47.863Z] Session [46b5e250-0514-11e8-8810-7f18091449bd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO - 2018-01-29T16:48:47.863Z] Session [46b5e250-0514-11e8-8810-7f18091449bd] - page.customHeaders: - {}
[INFO - 2018-01-29T16:48:47.863Z] Session [46b5e250-0514-11e8-8810-7f18091449bd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-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 - 2018-01-29T16:48:47.863Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 46b5e250-0514-11e8-8810-7f18091449bd
[Mon Jan 29 16:48:47 2018] ::1:40220 [200]: /long_page.html
.[INFO - 2018-01-29T16:48:48.287Z] Session [46f66dc0-0514-11e8-8810-7f18091449bd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO - 2018-01-29T16:48:48.287Z] Session [46f66dc0-0514-11e8-8810-7f18091449bd] - page.customHeaders: - {}
[INFO - 2018-01-29T16:48:48.287Z] Session [46f66dc0-0514-11e8-8810-7f18091449bd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-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 - 2018-01-29T16:48:48.287Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 46f66dc0-0514-11e8-8810-7f18091449bd
[Mon Jan 29 16:48:48 2018] ::1:40226 [200]: /long_page.html
.[INFO - 2018-01-29T16:48:48.773Z] Session [47409620-0514-11e8-8810-7f18091449bd] - page.settings - {"XSSAuditingEnabled":false,"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,"userAgent":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1","webSecurityEnabled":true}
[INFO - 2018-01-29T16:48:48.773Z] Session [47409620-0514-11e8-8810-7f18091449bd] - page.customHeaders: - {}
[INFO - 2018-01-29T16:48:48.773Z] Session [47409620-0514-11e8-8810-7f18091449bd] - Session.negotiatedCapabilities - {"browserName":"phantomjs","version":"2.1.1","driverName":"ghostdriver","driverVersion":"1.2.0","platform":"linux-unknown-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 - 2018-01-29T16:48:48.773Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 47409620-0514-11e8-8810-7f18091449bd
[Mon Jan 29 16:48:48 2018] ::1:40234 [200]: /
. 33 / 33 (100%)
Time: 3.9 seconds, Memory: 10.00MB
I don't get any errors. Yet, the tests fail. Again: it works locally, or inside Docker.
Is there anything I'm missing? What is so special about the Docker environment in Bitbucket Pipelines?
I finally figured it out. I needed to put a sleep call, which apparently fixed my issue.
I also switched to another image, which has several headless browsers pre-installed, shortening the build, which saves a few minutes (precious with Pipelines, as it's billed per minute). Unfortunately, it doesn't ship with the PHP ZIP extension, which is why I install it here.
Here's the config that works for me:
pipelines: default: # Run unit tests. - step: image: circleci/php:7.1-cli-browsers caches: - composer artifacts: - clover.xml - junit.log script: # Install dependencies. - sudo apt update && sudo apt install -y zlib1g-dev - sudo docker-php-ext-install zip - composer install # Run the development server and PhantomJS. - cd tests - php -S localhost:9000 -t www/ router.php & - cd .. - phantomjs --webdriver=localhost:8910 & - sleep 2 # Run the tests. - vendor/bin/phpunit --coverage-clover clover.xml --log-junit junit.log
Hey, did you figure that out?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.