【发布时间】:2019-06-12 15:09:02
【问题描述】:
当使用
将 chrome 的窗口大小设置为最大化或 1980x1080 时ChromeOptions.addArguments("--start-maximized");
或
driver.manage().window().setSize(new Dimension(1980,1080));
或
ChromeOptions.addArguments("window-size=1980,1080");
或
ChromeOptions.addArguments("--window-size=1980,1080");
Chrome 窗口设置为正确的大小,并且在从终端运行测试或从 intellij 运行单个测试用例(所有测试通过)时都能完美运行
但是,当我的 GOCD 管道接手工作时,一切都开始工作(测试开始正常执行)然后在日志中我看到测试中使用的窗口大小为 1044 x 788。
这会导致一个问题,因为我需要的按钮位于最右侧,并且由于屏幕尺寸(我假设)而超出视野(我假设)
收到的消息是
2018-11-28 13:38:52.542 WARN 4456 --- [ main] utils.PageUtils : element not interactable
(Session info: chrome=70.0.3538.110)
(Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:25:02.294Z'
System info: host: 'DEV', ip: '192.168.1.177', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.44.609538 (b655c5a60b0b54..., userDataDir: C:\windows\TEMP\scoped_dir1...}, cssSelectorsEnabled: true, databaseEnabled: false, goog:chromeOptions: {debuggerAddress: localhost:62401}, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: ignore, unhandledPromptBehavior: ignore, version: 70.0.3538.110, webStorageEnabled: true}
Session ID: e3f442486d9087e190e0954c5fcc19f5: Click(btnSearchDropMenu) failed! re trying...
2018-11-28 13:38:52.549 WARN 4456 --- [ main] utils.PageUtils : Screen dimentions: (1044, 788)
2018-11-28 13:38:52.550 INFO 4456 --- [ main] utils.PageUtils : Scrolling to move 'btnSearchDropMenu' to the middle of the screen
2018-11-28 13:38:53.619 ERROR 4456 --- [ main] BaseTestFolder.BaseTest : org.openqa.selenium.ElementNotVisibleException: element not interactable
(Session info: chrome=70.0.3538.110)
(Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
我尝试在不同区域传递 set size 命令,包括在将选项传递给我的 chrome 选项对象之前尝试单击缺少的按钮并重新排序之前,然后再将它们传递给 chrome 驱动程序。
我需要窗口至少为 1980x1080,但我不确定为什么在 GOCD 上运行测试时无法设置此设置
我不知道为什么会出现这个问题。任何帮助将不胜感激
**编辑 1 **
奇怪的是我可以减小窗口大小,而这个属性会保持...
2018-11-28 15:47:02.754 INFO 19088 --- [ main] configuration.GoogleChrome : Window size: (1000, 600)
编辑 2
添加了我尝试过的另一个参数,
这也是 jenkins 的问题 - 默认为相同的窗口大小:(1044, 788)
【问题讨论】:
-
尝试在
window-size前面加上--,即ChromeOptions options = new ChromeOptions(); options.addArguments("--window-size=1980,1080"); -
谢谢 Kiril,我也试过了,现在也用 Jenkins 试过了,同样的问题出现了
-
您可以尝试将您的测试运行包装在
xvfb--screen=1980x1080x24` 左右的命令中。如果 chrome 无法检测到 X 环境,它可能会选择一些奇怪的默认值,而 xvfb(或者可能是 Xdummy)应该会对此有所帮助。
标签: selenium selenium-chromedriver go-cd