我正在链接两个像这样的容器(docker-compose.yml):
test:
container_name: test
image: test
ports:
- "7761:80"
links:
- webdriver
webdriver:
container_name: webdriver
image: webdriver
'Test'包含一个正在运行的symfony网站。 'Webdriver'是一个自定义的ubuntu映像,Selenium服务器在4444端口运行ChromeDriver。
我在测试容器中的这个文件上运行PHPunit:
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...
}
}
作曲:
"phpunit/phpunit": "~4",
"phpunit/phpunit-selenium": "~1"
无论BrowserUrl的价值是什么,我都无法获得连接。我尝试了0.0.0.0,localhost(端口80和7761),我的容器的id等。
这是日志:
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
有什么想法吗?
编辑:使用3容器计划修复,请参阅下面的解决方案:
PHPUnit:
public function setUp()
{
$this->setHost('webdriver');
$this->setPort(4444);
$this->setBrowserUrl('http://website');
$this->setBrowser('chrome');
}
搬运工-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
webdriver-tests容器可以检查网站代码,包括测试或单独的测试仓库。
答案 0 :(得分:0)
您需要从webdriver
容器到test
的链接,但它会创建循环导入。您可以在此链接https://github.com/docker/compose/issues/666后找到一些解决方法。
我建议从主站点到另一个容器进行单独测试,因为他们有不同的职责。此外,此解决方案允许避免循环导入。