无头模式下的Chromedriver问题 [英] Problem with Chromedriver in Headless mode

查看:352
本文介绍了无头模式下的Chromedriver问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人在无头"模式下使用chromedriver有问题.就我而言,以这种方式运行硒测试时,将无限期停止执行硒测试,不会完成测试并开始执行下一个测试用例,也不会给出相关的异常.我想知道是否有人对发生的事情有任何了解.我猜这个问题是由于webdriver的静态初始化

I would like to know if anyone there has ever had a problem using the chromedriver in "headless" mode. In my case, when running selenium tests in this mode, the execution of the same is stopped indefinitely, not completing the test and starts execution of the next test case nor does it give the relevant exception. I would like to know if anyone can have any idea of what may be occurring. I am guessing this issue is due to static initialization of the webdriver

public static WebDriver createInstance(WebDriver driver, String browserName){..}

我的日志向我显示了这个顺序,测试用例没有完全执行,下一个测试用例称为

My logs show me this sequence the test cases are not completely executed and next test case is called

- INFO learning.helpers.DriverInitialisor - createInstance - 111 - Running Chrome browser in headless mode - INFO learning.helpers.DriverInitialisor - createInstance - 126 - Launching Chrome browser in local mode - INFO learning.tests.ExpandFAQ - expandAndCollapseFAQ - 30 - launching the ION Learning Hub Application - INFO learning.tests.ExpandFAQ - expandAndCollapseFAQ - 35 - Open a searched product - INFO learning.helpers.DriverInitialisor - createInstance - 111 - Running Chrome browser in headless mode - INFO learning.helpers.DriverInitialisor - createInstance - 126 - Launching Chrome browser in local mode - INFO learning.tests.CollapseFAQ - collapseFAQ - 30 - launching the ION Learning Hub Application - INFO learning.tests.CollapseFAQ - collapseFAQ - 35 - Open a searched product

- INFO learning.helpers.DriverInitialisor - createInstance - 111 - Running Chrome browser in headless mode - INFO learning.helpers.DriverInitialisor - createInstance - 126 - Launching Chrome browser in local mode - INFO learning.tests.ExpandFAQ - expandAndCollapseFAQ - 30 - launching the ION Learning Hub Application - INFO learning.tests.ExpandFAQ - expandAndCollapseFAQ - 35 - Open a searched product - INFO learning.helpers.DriverInitialisor - createInstance - 111 - Running Chrome browser in headless mode - INFO learning.helpers.DriverInitialisor - createInstance - 126 - Launching Chrome browser in local mode - INFO learning.tests.CollapseFAQ - collapseFAQ - 30 - launching the ION Learning Hub Application - INFO learning.tests.CollapseFAQ - collapseFAQ - 35 - Open a searched product

这在少数测试用例中继续,然后对于其他测试用例再次开始完全执行.我正在运行大约50个测试用例.没有实现多线程.

This continues for few test cases and then complete execution starts again for other test cases. I am running of around 50 test cases. There is no multithreading implemented.

推荐答案

在我的情况下,我注意到了这一点,并且运行良好.在无头模式下,您需要添加窗口大小作为参数.我不知道您使用的是哪种语言上.

I have noticed that in my case and worked perfectly.You need add window size as an arguments in headless Mode.I don't know which language you are working on.

如果您使用的是python,请添加this.

If you are using python add this .

  chrome_options = webdriver.ChromeOptions()
  chrome_options.add_argument('--headless')
  chrome_options.add_argument('window-size=1920x1080');

如果您使用的是Java,请将其添加.

if you are using java add this.

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("headless");
chromeOptions.addArguments("window-size=1920,1080");

请尝试一下,让我知道是否可行.

Please try this and let me know if this work.

这篇关于无头模式下的Chromedriver问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆