2015-05-29 100 views
0

我正在探索在多個瀏覽器上執行測試的硒網格。我已經在線教程配置了集線器和節點。我創建了一個測試腳本。在多個瀏覽器上使用硒網格和testNG運行測試

下面是測試腳本的代碼:

public class SeleniumGridTest { 
    WebDriver driver; 
    String baseUrl, nodeUrl; 
    static FirefoxProfile myprofile; 

    @BeforeTest 
    public void beforeTest() throws MalformedURLException { 
     ProfilesIni profile = new ProfilesIni();   
     myprofile = profile.getProfile("SeleniumAuto");   
     nodeUrl = "http://10.233.18.60:5566/wd/hub"; 
     DesiredCapabilities capability = DesiredCapabilities.firefox(); 
     capability.setBrowserName("firefox"); 
     capability.setCapability(FirefoxDriver.PROFILE, myprofile);  
     driver = new RemoteWebDriver(new URL(nodeUrl), capability); 
    } 

    @Test 
    public void google() { 
    driver.get("http://www.google.co.in"); 
    System.out.println(driver.getCurrentUrl()); 
    } 

    @Test 
    public void newtours() { 
    driver.get("http://newtours.demoaut.com"); 
    System.out.println(driver.getCurrentUrl()); 
    } 

    @AfterTest 
    public void afterTest() { 
    driver.quit(); 
    } 

} 

我的目標是運行在多個瀏覽器 我已經加入想要的功能,像Firefox這樣的測試,

1)should I add desired capabilities for other browsers in the 
@BeforeTest annotation? for eg capability.setBrowserName("chrome"); 
2)is that enough to run on multiple browsers. 
3)If I have to run a suite of tests, where should I add the selenium grid configuration 
details in all the tests or is it possible in testNG xml? 
4)what is the best practice used in real time? 

任何幫助讚賞

回答

0

您需要爲不同瀏覽器(Chrome或IE或Firefox中的每一個)分別使用ur @ beforeTest中的功能,並且您需要編寫代碼接受testng.xml參數,以便相應的瀏覽器可以在節點機上運行...

正常情況下,測試腳本是通過使用testng.xml, 來運行的,但是每個瀏覽器的配置細節,您需要將它們保存在您要運行的每個節點機器中

您需要運行命令/可以在每個節點機器上創建bat文件,並在運行ur testng.xml之前運行/保留它們。

欲瞭解更多信息,你可以參考這個link

有沒有最佳實踐,到目前爲止,根據你的需要,你可以自定義的東西,所以第一次嘗試的基本步驟在多臺計算機上運行。

相關問題