Problem with Chromedriver in Headless mode

邮差的信 提交于 2019-12-13 00:39:10

问题


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

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.


回答1:


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.

If you are using python add this .

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

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.



来源:https://stackoverflow.com/questions/54984306/problem-with-chromedriver-in-headless-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!