我正在运行Dusk来测试我的Laravel应用程序。我最近切换到了Laradock,由于我对Docker的经验很少,所以花了一些时间对其进行了设置,但是现在一切似乎都可以使用了。除了Selenium似乎不能正常工作。
我这样启动并打开我的工作区:
sudo docker-compose up -d nginx postgres beanstalkd selenium
sudo docker-compose exec --user=laradock workspace bash
然后
php artisan dusk
1) Tests\Browser\SuccessLoginTest::test_user_can_login
Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body textarea[name='email']"}
(Session info: headless chrome=75.0.3770.90)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'f8c1169cd1a3', ip: '172.18.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.7-100.fc30.x86_64', java.version: '1.8.0_212'
Driver info: driver.version: unknown
我得到了测试失败的屏幕快照,显示了该网站及其上似乎找不到的and元素。在我改用Laradock之前,一切都工作正常,因此问题似乎出在Selenium上。我的设置如下所示,我使用Laravel 5.7.28
protected function driver()
{
$options = new ChromeOptions();
$options->addArguments([
'--headless',
'--no-sandbox',
'--disable-gpu',
'--window-size=1920,1080',
'--ignore-certificate-errors'
]);
$capabilities = DesiredCapabilities::chrome();
$capabilities->setCapability(ChromeOptions::CAPABILITY, $options);
if (env('USE_SELENIUM', 'false') == 'true') {
return RemoteWebDriver::create(
'http://selenium:4444/wd/hub', $capabilities
);
} else {
return RemoteWebDriver::create(
'http://localhost:9515', $capabilities
);
}
答案 0 :(得分:1)
此错误消息...
Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"body textarea[name='email']"}
(Session info: headless chrome=75.0.3770.90)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'f8c1169cd1a3', ip: '172.18.0.3', os.name: 'Linux', os.arch: 'amd64', os.version: '5.4.7-100.fc30.x86_64', java.version: '1.8.0_212'
Driver info: driver.version: unknown
...表示在程序执行期间引发了 NoSuchElementException 。
有关 chromedriver 版本的测试配置的一些详细信息,将有助于我们以更好的方式调试问题。但是,您需要注意以下几点:
参数--disable-gpu
的目的是在google-chrome-headless平台上启用windows。早于SwiftShader fails an assert on Windows in headless mode就需要它。此问题已通过Headless: make --disable-gpu flag unnecessary 已解决。在laravel上的laravel-dusk / laradock / linux上,您需要删除以下代码行:
'--disable-gpu' // applicable to windows os only
根据您的问题,就像您使用的是 chrome = 75.0 一样。您需要确保:
@Test
。driver.quit()
方法内调用tearDown(){}
,以优雅地关闭和销毁 WebDriver 和 Web Client 实例。您可以在以下位置找到相关的详细讨论: