我使用testNg +硒網格作爲我的測試會話,我對整個東西感到非常滿意 關鍵是測試的數量正在增長,現在他們至少需要3個hrs被執行(+ -100測試在TH瀏覽器) 我打算有+ -150測試,所以,你可以想象,我必須找到一個解決方案,並行啓動他們 我試着玩這個,但沒有現在運氣好,我現在看到的是兩個瀏覽器啓動,但只有一個經過測試。另一個只是等待:-) 測試的結構如下,基本上是1測試= 1類。我在每次測試之前/之後都有@BeforeClass(啓動驅動程序)和@AfterClass(停止驅動程序)testNG和硒在並行測試環境
testNG.xml - >我將parallel =更改爲類,方法,測試但沒有運氣。數值!
<test name="Smoke Test in IE - IE REMOTE" preserve-order="true">
<parameter name="browser" value="IE" ></parameter>
<classes>
<class name="com.TestThis.Script1" />
<class name="com.TestThis.Script2" />
</classes>
</test>
TEST類如下所示 公共類SCRIPT1延伸SelTestCase {
try {
GlobalHelp.LogIn("usr","pwd");
customVerification.verifyTrue("Verify main page loaded(check download zone is visible!!)", ObjectHelp.isElementVisible(ObjectsPaths.Main_DownloadZone,120000)==true);
customVerification.SoftVerifyEquals("Verify main page is displayed " , driver.getTitle(), "Application Stuff");
} catch (Exception e) {
Reporter.log("from exception" + e.toString());
customVerification.verificationErrors.append(e);
}
}
}
與模塊之前&後看起來像這樣 公共類SelTestCase {
@BeforeSuite
@Parameters("appURL")
public void setEnv(
@Optional(ObjectsPaths.MAIN_URL) String appURL) {
this.appURL = appURL;
}
@BeforeClass
@Parameters({ "browser", "HUBip" })
public void launchBrowser(@Optional("IE") String browser, @Optional("localhost") String HUBip) throws MalformedURLException {
String brw=browser;
String ip=HUBip;
try {
if (sBrw.equalsIgnoreCase("Chrome")) {
URL url = new URL("http","localhost",4444, "/wd/hub");
DesiredCapabilities caps=DesiredCapabilities.chrome();
driver = new ScreenShotRemoteWebDriver(url, caps);
} else if (sBrw.equalsIgnoreCase("FF")) {
URL url = new URL("http", "localhost",4444, "/wd/hub")
DesiredCapabilities caps=DesiredCapabilities.firefox();
} else {
URL url = new URL("http", "localhost",4444, "/wd/hub");
DesiredCapabilities caps=DesiredCapabilities.internetExplorer();
driver = new ScreenShotRemoteWebDriver(url, caps);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
};
}
try {
Reporter.log("Test started at: " + ObjectHelp.getDate() + "<p>");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.manage().timeouts().implicitlyWait(ObjectHelp.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(ObjectHelp.PAGE_LOAD_TIMEOUT,TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.navigate().to("http://www.google.com");
}
//TBD
@AfterClass
public void closeBrowser() throws Exception {
//driver.close();
QuitDriver();
}
你的問題是什麼? – Shamik
問題是如何讓它們並行運行! – user1944151
你的測試班如何獲得驅動程序?看到我無法理解你的代碼。但讓我們清楚你是否想要並行運行測試(在相同或不同的瀏覽器中)它們應該得到不同的驅動程序。您的BeforeClass應該創建單獨的驅動程序並傳遞到測試類。然後只有你可以達到你想要的。你在做那個嗎? – Shamik