All other tests run well but when it comes to the suite where that uses Selenium it refuses to connect:
Time: 7.55 seconds, Memory: 16.00MB
There was 1 failure:
---------
1) SampleTestCept: Test if wp is working in selenium
Test tests/php/acceptance/SampleTestCept.php
Step See "Just another WordPress site"
Fail Failed asserting that on page /
--> This site can’t be reached
localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
Reload
DETAILS
--> contains "this site can't be reached".
Scenario Steps:
2. $I->see("This site can't be reached") at tests/php/acceptance/SampleTestCept.php:6
1. $I->amOnPage("/") at tests/php/acceptance/SampleTestCept.php:4
Selenium server imho does not have to connect to localhost, because service is “another host”. You have to use HOSTNAME environment variable to find runner hostname. In NodeJS I use next
As @gintsgints mentioned, the standalone-chrome container you are using doesn’t know how to connect to your application, which is, according to your webdriver configuration http://localhost.
I stumbled into the same problem when I was trying to run web tests for my symfony application. I solved it by letting the test job figure out the IP address of its own container, start a local PHP server, and change the codeception configuration so that the chrome container connects to that IP address.
The relevant lines in .gitlab-ci.yaml are:
- LOCAL_IP=$(ip route get 8.8.8.8 | awk -F"src " 'NR==1{split($2,a," ");print a[1]}')
- echo Local IP $LOCAL_IP
# Run the php built in server. Don't try to run nginx as a service, that only causes troubles. ;-)
- php -S 0.0.0.0:8080 -t public/ 2> /dev/null &
- sed -i "s/localhost:8080/$LOCAL_IP:8080/" tests/acceptance.suite.yml
This is probably not the most beautiful solution around, but it works. If you happen to find a prettier solution, please let me know, because I would love to improve what I’ve got.