简体   繁体   中英

Selenium Webdriver continue through multiple classes

I made a test script that is way to long. So, i'm making short classes. if i want to run a few in a row (with TestNG xml file) the first class will succeed, but the next one opens a new firefox window because of:

WebDriver driver = new FirefoxDriver();    

How do I make it so that it won't open a new window but goes on in the same window as the previous class?

This has been answered many times before, but here is one I posted the other day. In a nutshell:

  • Create singleton WebDriver at the start of your test run
  • Reuse it in all your tests
  • Don't close or quit it until you're finished.

This might be workaround, you can used in you code, @AfterClass public closedBrowser() { driver.close(); }

So that next class is opened freshly in new browser. Write a 'driver.close()' in After class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM