拒绝连接:Docker中的PHPUnitselenium
我将这两个容器连接起来(docker-compose.yml):
test: container_name: test image: test ports: - "7761:80" links: - webdriver webdriver: container_name: webdriver image: webdriver
“testing”包含一个正在运行的symfony网站。 'Webdriver'是一个定制的Ubuntu镜像,Selenium服务器在端口4444上使用ChromeDriver运行。
我在testing容器内的这个文件上运行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... } }
composer php:
"phpunit/phpunit": "~4", "phpunit/phpunit-selenium": "~1"
无论BrowserUrl的价值是什么,我都无法获得连接。 我尝试0.0.0.0,本地主机(端口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容器计划固定,请参阅下面的解决scheme:
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
webdrivertesting容器可以检出网站代码,包括testing,或单独的testing回购。
你需要从你的webdriver
容器的链接来test
一个,但它会创build循环导入。 您可以在此链接https://github.com/docker/compose/issues/666find一些解决方法。
我build议将主站点的testing分成另一个容器,因为它们有不同的职责。 而且,这个解决scheme可以避免循环导入。