How to run chrome driver in background using selenium with Ruby for Mac OSx?

爷,独闯天下 提交于 2019-11-27 08:22:57

问题


Sometimes, the browser window comes to the foreground and I'm clicking it accidentally which makes the test fails on some occasions. So, I just want to know, is there any way that I can keep the chrome driver window in the background.

Details: < ChromeDriver version: 2.28.455517 > < Chrome version: 58.0.3029.96 >


回答1:


First and foremost rule is that we should not do any other work while your scripts are running. We may use actions class for hovering., etc, while you move your cursor it may lead to failing your test case. Hope It will be useful to you.




回答2:


A few words about the solution to your Question:

  1. As per best practices, you should try to execute your Test-scripts / Automation-framework in an isolated Test Environment with all the required Hardware and Software configurations and setup.
  2. While the execution is in process, there should be no manual user interaction in-between.
  3. In-case you want to do multitasking, use Ghost/Headless Browsers. You will find a detailed discussion in Which drivers support “no-browser”/“headless” testing?.
  4. Htmlunitdriver & PhantomJS are the two mostly widely used Ghost/Headless Browsers.
  5. If you are specific about using ChromeDriver you can use Chrome headless as per the documentation here.



回答3:


You can try using headless switch available for Chrome.

This will run the automation in the headless mode and you will not be disturbed.

options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless')

Afterward, initiate Chrome.



来源:https://stackoverflow.com/questions/43863837/how-to-run-chrome-driver-in-background-using-selenium-with-ruby-for-mac-osx

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