I'm linking two containers like this (docker-compose.yml):
test:
container_name: test
image: test
ports:
- "7761:80"
links:
- webdriver
webdriver:
container_name: webdriver
image: webdriver
'Test' contains a running symfony website. 'Webdriver' is a custom ubuntu image with the Selenium server running with ChromeDriver on port 4444.
I'm running PHPunit on this file inside the test container:
class SeleniumTest extends PHPUnit_Extensions_Selenium2TestCase
{
public function setUp()
{
$this->setHost('webdriver');
$this->setPort(4444);
$this->setBrowserUrl('http://localhost:7761');
$this->setBrowser('chrome');
}
protected function login() {
$this->url('/');
$content = $this->byTag('body')->text();
print $content;
#...do tests...
}
}
Composer:
"phpunit/phpunit": "~4",
"phpunit/phpunit-selenium": "~1"
No matter what the value is of BrowserUrl, I can't get a connection. I tried 0.0.0.0, localhost (port 80 and 7761), the id of my container etc.
This is the log:
root@/var/www# bin/phpunit tests
PHPUnit 4.5.1 by Sebastian Bergmann and contributors.
EThis webpage is not available
ERR_CONNECTION_REFUSED
RELOAD
DETAILS
Time: 580 ms, Memory: 3.50Mb
There was 1 error:
1) SeleniumTest::testLogin
PHPUnit_Extensions_Selenium2TestCase_WebDriverException: no such element: Unable to locate element: {"method":"name","selector":"subscriptionForm"}
(Session info: chrome=48.0.2564.97)
(Driver info: chromedriver=2.21.371461 (633e689b520b25f3e264a2ede6b74ccc23cb636a),platform=Linux 3.19.0-39-generic x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 12 milliseconds
Any ideas?
EDIT: fixed using the 3 container plan, see solution below:
PHPUnit:
public function setUp()
{
$this->setHost('webdriver');
$this->setPort(4444);
$this->setBrowserUrl('http://website');
$this->setBrowser('chrome');
}
docker-compose.yml:
test:
container_name: test
image: test
webdriver:
container_name: webdriver
image: webdriver
links:
- test:website
webdriver-tests:
container_name: webdriver-tests
image: custom-image-with-tests
links:
- webdriver
The webdriver-tests container can checkout the website code including tests, or a separate test repo.