如何在Selenium中使用已经打开的firefox进行测试

如何在Selenium中使用已经打开的firefox进行测试

问题描述:

此声明

WebDriver driver = new FirefoxDriver();

始终打开Firefox的新实例窗口。它没有使用已经打开的firefox。

always opens a new instance window of Firefox. It doesn't use the already opened firefox.

任何人都可以让我知道如何使用已经打开的firefox进行测试而不是打开一个新的吗?

Can anyone let me know how to use a already opened firefox for testing instead of opening a new one?

请注意,因为如果驱动程序崩溃一次,那么之后必须执行的所有测试用例都会受到影响,因为他们使用相同的驱动程序,你也将共享cookie,也许你之前已经打开的会话等等。

Be careful with that, because in case the driver crashes once, then all the test cases that have to be executed after that will be affected because they are using the same driver, also you will be sharing cookies, and perhaps sessions already opened previously, etc.

更强大的解决方案是为每个创建一个新的WebDriver测试用例,因为这样做可以使所有测试用例减少对其他测试用例的依赖。

The more robust solution is to create a new WebDriver for each test cases because doing that you are making all your tests cases less dependent on the others.

如果激励你的原因是每个WebDriver创建的时间,也许你可以开始考虑并行运行测试用例,例如使用TestNG。

If the reason that is motivating you is the time each WebDriver takes to be created, perhaps you could start thinking on run test cases in parallel for example with TestNG.

谢谢