![](/img/trans.png)
[英]Running Parallel Tests using Selenium WebDriver, Selenium Grid and testNG
[英]Multiple browsers while running tests in parallel with Google Guice + TestNG + Selenium GRID + Maven
我搜索并阅读了几乎所有有关Selenium Grid以及与testNG并行运行测试的文章。 但是,我仍然不知道自己在做什么错。
使用页面对象模式,我正在测试http://www.gmail.com 。 我使用Google Guice依赖项注入来为每个页面提供WebDriver,因为我在AbstractModule类中使用了@Provides批注:
public class GmailModule extends AbstractModule {
@Override
protected void configure() { ... }
String NODE_URL = "http://localhost:5555/wd/hub";
@Provides
WebDriver getRemoteDriver() throws MalformedURLException {
ThreadLocal<RemoteWebDriver> threadDriver = new ThreadLocal<RemoteWebDriver>();
DesiredCapabilities capability = new DesiredCapabilities();
capability.setBrowserName(DesiredCapabilities.firefox().getBrowserName());
capability.setCapability(FirefoxDriver.PROFILE, new File(ResourceExaminer.getValueFromExpDataMap("firefoxprofile")));
capability.setPlatform(Platform.XP);
RemoteWebDriver webDriver = new RemoteWebDriver(new URL(NODE_URL), capability);
threadDriver.set(webDriver);
return threadDriver.get();
}
}
所有页面都扩展了摘要页面,在这里我传递了驱动程序,然后就可以使用它了。
public abstract class AbstractPage extends HTMLElements{
public WebDriver webDriver;
@Inject
public AbstractPage(WebDriver driver){
this.webDriver = driver;
PageFactory.initElements(new HtmlElementDecorator(webDriver), this);
}
}
然后,所有测试都对AbstractTestingClass进行了扩展,该类随Google @Guice批注一起提供,以便注入第一页。 我使用以下cmd行通过Selenium Grid运行集线器和节点:
java -jar selenium-server-standalone-2.39.0.jar -role hub -hubConfig DefaultHub.json java -jar selenium-server-standalone-2.39.0.jar -role节点-nodeConfig DefaultNode.json
在DefaultNode.json中,我减少了maxSessions = 2和browserName = firefox的数量
我的测试套件包含以下内容
<suite name="PositiveTestSuite" parallel="classes" thread-count="2" verbose="2">
<test name="Attaching file">
<classes>
<class name="com.epam.seleniumtask.gmail.test.AttachingFilesTest"/>
</classes>
</test>
<test name="2nd">
<classes>
<class name="com.epam.seleniumtask.gmail.test.ChangeSignatureTest"/>
</classes>
</test>
<test name="3rd">
<classes>
<class name="com.epam.seleniumtask.gmail.test.CreateNewLabelTest"/>
</classes>
</test>
<test name="4th">
<classes>
<class name="com.epam.seleniumtask.gmail.test.DeletingMessagesTest"/>
</classes>
</test>
但是,测试运行起来很奇怪->
我的问题是-1)为什么即使我在Selenium Grid中限制了3个浏览器,我仍然还有3个浏览器? 2)如何强制我的测试只能在2个浏览器中运行? 一个进行2个测试,另一个进行2个测试?
请帮我。 我将不胜感激。
感谢您的回答。 我终于明白了为什么会有这些问题。 万一有人需要答案->我一直在每个测试课程中为Google Guice注入模块。 因此,每次测试开始时都会初始化注入,因此也打开了新的浏览器。
作为解决方案,我在Guice中使用@Provides注入来使用惰性初始化。 在每个@BeforeClass批注中,我正在获取提供程序。 像这样:
@Guice(modules = GmailModule.class)
public class ForwardTest extends AbstractTestingClass {
@Inject
Provider<SignInPage> providingSignInPage;
@BeforeClass
public void startUp(){
signInPage = providingSignInPage.get();
}
在singInPage内部,有一个RemoteWebDriver。 现在对我来说很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.