简体   繁体   English

Selenium Webdriver通过多个类继续

[英]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: 如果我想连续运行几个(使用TestNG xml文件),则第一个类将成功,但是下一个将打开新的firefox窗口,原因是:

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 在测试运行开始时创建单例WebDriver
  • 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(); 这可能是一种解决方法,您可以在代码中使用@AfterClass public closeBrowser(){driver.close(); } }

So that next class is opened freshly in new browser. 这样,下一个类将在新的浏览器中全新打开。 Write a 'driver.close()' in After class. 在After类中编写“ driver.close()”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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