$I = new AcceptanceTester($scenario);
$I->amOnUrl('http://127.0.0.1');
$I->makeScreenshot();
$I->waitForElement(".modal");
但是测试没有正常运行,因为Chrome容器无法连接到Web容器。屏幕截图显示的页面显示:
This site can't be reached
127.0.0.1 refused to connect
这是运行codeception的附加shell中显示的错误:
[Facebook\WebDriver\Exception\NoSuchElementException] no such element: Unable to locate element: {"method":"css selector","selector":".modal"}
(Session info: chrome=68.0.3440.84)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.9.0-7-amd64 x86_64)
虽然我可以连接到
http://127.0.0.1:4444/wd/hub
这是我从运行“docker compose up”的shell得到的输出:
chrome_1 | INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0'
chrome_1 | INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
chrome_1 | INFO::main: Logging initialized @286ms to org.seleniumhq.jetty9.util.log.StdErrLog
chrome_1 | INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
chrome_1 | INFO [ActiveSessionFactory.apply] - Capabilities are: {"browserName": "chrome"}
chrome_1 | INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
chrome_1 | Starting ChromeDriver 2[.14513.5517089780809 .(328f61]e[dS5EfV9E3R4E3]c:1 3bfi7n3d1(4)4 5r3e8tfu1r5nce0d0 ba3n7 0eerdrao6r7,0 6e) onr rpnoor=t9 91:7 2C9a4n
chrome_1 | Onnloyt laoscsailg nc ornenqeucetsitoends aadrder easlsl o(w9e9d).
chrome_1 | INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
chrome_1 | INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session ed60fb03c497f98a7e23bdede05c4bb9 (org.openqa.selenium.chrome.ChromeDriverService)
chrome_1 | INFO [ActiveSessions$1.onStop] - Removing session ed60fb03c497f98a7e23bdede05c4bb9 (org.openqa.selenium.chrome.ChromeDriverService)
chrome_1 | INFO [ActiveSessionFactory.apply] - Capabilities are: {"browserName": "chrome"}
chrome_1 | INFO [ActiveSessionFactory.lambda$apply$11] - Matched factory org.openqa.selenium.remote.server.ServicedSession$Factory (provider: org.openqa.selenium.chrome.ChromeDriverService)
chrome_1 | Starting ChromeDriver 2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706) on port 17381
chrome_1 | Only local connections are allowed.
chrome_1 | [1535110012.491][SEVERE]: bind() returned an error, errno=99: Cannot assign requested address (99)
chrome_1 | INFO [ProtocolHandshake.createSession] - Detected dialect: OSS
chrome_1 | INFO [RemoteSession$Factory.lambda$performHandshake$0] - Started new session 3c49c360624e02460995193c50f43bd3 (org.openqa.selenium.chrome.ChromeDriverService)
chrome_1 | INFO [ActiveSessions$1.onStop] - Removing session 3c49c360624e02460995193c50f43bd3 (org.openqa.selenium.chrome.ChromeDriverService)
我认为,为Docker撰写容器建立网络应该可以解决这个问题。
我试着按照码头工人的文件(
Network configuration reference
)将网络设置为“主机”,但似乎已过时,因为版本3中不允许使用名称。
还尝试设置从chrome到web的链接,运行chrome而不使用compose(docker run--net=host selenium/standalone chrome),但没有改变。
你知道怎么做吗?
谢谢你的帮助!