linux - Selenium 测试用例在 Firefox 中有效,但在 Chrome 中无效 - Headless Setup

标签 linux google-chrome selenium firefox xvfb

经过一段时间的拔毛,我已经没有选择了。

我正在设置一个基于 selenium 的构建服务器,并且在引入 Google-Chrome 之前取得了很大的成功。

我现在可以通过 selenium 成功运行测试用例,甚至在 Firefox headless 上捕获屏幕截图也没有问题,除了 Chrome 之外,其他都没有玩球。

从运行旧版本到重新安装,我已经按照我能找到的所有步骤进行操作,但没有成功。

当我调用 phpunit 并且测试设置为使用 Firefox 时,一切正常:

PHPUnit 5.7.20 by Sebastian Bergmann and contributors. Runtime: PHP 7.0.15-0ubuntu0.16.04.4 with Xdebug 2.4.0 Configuration: /private/var/www/functionaltests/vaimodev/tests/functional/phpunit.xml.dist . 1 / 1 (100%) Time: 10.61 seconds, Memory: 4.00MB OK (1 test, 1 assertion)

现在进行相同的测试,但设置为使用 chrome:

1) defaultTest::testTitle PHPUnit_Extensions_Selenium2TestCase_WebDriverException: unknown error: Runtime.executionContextCreated has invalid 'context': {"auxData":{"frameId":"10699.1","isDefault":true},"id":1,"name":"","origin":"://"} (Session info: chrome=58.0.3029.110) (Driver info: chromedriver=2.9.248304,platform=Linux 4.4.0-72-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 46 milliseconds Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'm2.vaimo.dev', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-72-generic', java.version: '1.8.0_131' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{applicationCacheEnabled=false, rotatable=false, chrome={userDataDir=/tmp/.com.google.Chrome.5OdRZX}, takesHeapSnapshot=true, databaseEnabled=false, handlesAlerts=true, version=58.0.3029.110, platform=LINUX, browserConnectionEnabled=false, nativeEvents=true, acceptSslCerts=true, locationContextEnabled=true, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 68262783c1d2f9aba29f813504ed9606

我按如下方式启动我的 selenium 实例:

DISPLAY=:8.8 java -Dwebdriver.gecko.driver=/home/vagrant/geckodriver -Dwebdriver.chrome.driver=/home/vagrant/chromedriver -Dchrome.binary=/opt/google/chrome/chrome -jar /home/vagrant/selenium-server-standalone-3.4.0.jar -port 4444 > /dev/null 2>&1 &

在此阶段,我们将不胜感激...

最佳答案

这看起来很奇怪,它太小了

Command duration or timeout: 46 milliseconds

作为选项,尝试增加超时( session 等)

另外查看代码可能会有帮助:)

关于linux - Selenium 测试用例在 Firefox 中有效,但在 Chrome 中无效 - Headless Setup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44201174/

相关文章:

javascript - 为什么我需要一个 Selenium Server 而不是直接调用 WebDriver 实现

python - var/www/html 中没有 index.lighttpd.html

jquery - 为什么 jQuery hide()/show() 会破坏 Chrome 中的 HTML 选择?

c - 为什么当我用记事本创建 Makefile 时,它​​保存的是 .txt

html - chrome 在滚动时获取固定元素复制

html - Firefox 绝对位置不同于 Chrome

python - 使用 BeautifulSoup 解析网页不会给出完整的页面内容

c# - Selenium WebDriver 在 RemoteWebElement.Click() 上抛出 WebDriverTimeoutException

linux - Perl 检查网络接口(interface)是否启动(linux)

linux - nohup 进程在 xterm 关闭时终止,但在退出时不终止