2014-12-24 230 views
1

我使用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(); 
} 
+0

你的問題是什麼? – Shamik

+0

問題是如何讓它們並行運行! – user1944151

+0

你的測試班如何獲得驅動程序?看到我無法理解你的代碼。但讓我們清楚你是否想要並行運行測試(在相同或不同的瀏覽器中)它們應該得到不同的驅動程序。您的BeforeClass應該創建單獨的驅動程序並傳遞到測試類。然後只有你可以達到你想要的。你在做那個嗎? – Shamik

回答

0

那麼你可以做課前的,而不是創建驅動程序對象中,創建測試類中的驅動程序對象和實施超類中的before方法將爲您測試類創建驅動程序對象,並將其分配給測試類中的驅動程序對象,該驅動程序對象將特定於您的測試類。然後,如果你嘗試並行運行,它將起作用。

+0

我會檢查它。現在我創建我的驅動程序對象在超類從每個測試類。也許通過分配給每個測試類將解決我的問題,但我不明白,一個新的實例應該自動創建! – user1944151

+0

一個新的實例是什麼?測試?因爲你必須在你的testng.xml中使用並行屬性,請檢查這個 - http:// testng。 org/doc/documentation-main.html#parallel-tests 如果你的驅動程序是爲每個單獨的測試類實例化的,它應該可以工作 – Shamik

+0

shame :-(我有很多問題可以通過類和模塊來分享我的驅動程序實例來自我的測試班的電話,它只是「空」......可怕的頭痛 – user1944151

0

在XML中添加以下內容,運行測試並行:您的套件名稱

平行=「測試」,所以象下面這樣:

<suite name="Suite" parallel="tests" > 

它會在所有指定的運行測試並行瀏覽器。