在 TestNG 中使用 IObjectFactory 时,是否需要预先创建所有测试类?
我正在通过 TestNG 运行一些 Selenium 2 测试,并且尝试使用 Guice 模块自动将配置好的浏览器(驱动程序)注入到我的测试中。我正在使用 TestNG 书中描述的 IObjectFactory 方法,并由 testnguice,但我遇到了一个问题。
似乎只要测试套件启动,我的所有测试类都会被创建,浏览器实例也会被初始化。如果我的类只有轻量级对象,这不会是一个问题,但就我而言,这意味着我有六个浏览器被启动并等待它们的测试运行。
是否可以告诉 TestNG 在测试运行之前创建测试类?
作为参考,这里是用于启动测试的 testng.xml。我正在 eclipse 中运行所有内容。
<suite name="Suite1" verbose="1" object-factory="com.corp.Testing.ObjectFactory.LocalFirefox">
LocalFirefox 同样不起眼
package com.corp.Testing.ObjectFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocalFirefox extends GuiceObjectFactory {
@Override
protected void configure() {
bind(WebDriver.class).to(FirefoxDriver.class);
}
}
I'm running some Selenium 2 tests through TestNG and I'm trying to use Guice modules to automatically inject a configured browser (driver) into my tests. I'm using the IObjectFactory method described in the TestNG book, and implemented by testnguice, but i've run into an issue.
It seems that all my test classes are being created, and the browser instance initialized, as soon as the tests suite starts. This wouldn't be such a problem if my classes only had lightweight objects, but in my case this means I've got a half dozen browsers being fired up and sitting around until their test is run.
Is it possible to tell TestNG to create the test class right before the test is run?
for reference here's the testng.xml used to start the tests. I'm running everything inside eclipse.
<suite name="Suite1" verbose="1" object-factory="com.corp.Testing.ObjectFactory.LocalFirefox">
LocalFirefox is equally unremarkable
package com.corp.Testing.ObjectFactory;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class LocalFirefox extends GuiceObjectFactory {
@Override
protected void configure() {
bind(WebDriver.class).to(FirefoxDriver.class);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论