0
I want to run Test cases on Multiple browser.
我寫下面的代碼來測試網頁的標題。這個測試通過firefox傳遞,但是當我嘗試在其他瀏覽器中運行時顯示跳過或失敗。測試用例總是失敗,除了火狐
public class clsTestCase {
WebDriver driver;
String baseurl,nodeurl;
@BeforeTest
public void beforeTest() throws MalformedURLException
{
baseurl="http://www.google.com/";
nodeurl="http://192.168.1.100:5566/wd/hub/";
DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setBrowserName("internet explorer");
cap.setPlatform(Platform.WINDOWS);
driver=new RemoteWebDriver(new URL (nodeurl), cap);
}
@Test
public void testAdd() {
driver.get(baseurl);
Assert.assertEquals("Google", driver.getTitle());
}
@AfterTest
public void aftrTest()
{
driver.quit();
}
}
當我改變陳述
DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setBrowserName("internet explorer");
到
DesiredCapabilities cap=DesiredCapabilities.firefox();
cap.setBrowserName("firefox");
然後測試用例通過。 爲什麼它沒有在IE或Chrome中傳入相同的代碼?
我在Python中測試。您可能需要先下載適用於硒的「Chrome」和「IE」瀏覽器驅動程序,然後才能對其進行測試。請參閱以下兩個鏈接:https://code.google.com/p/selenium/wiki/ChromeDriver; https://code.google.com/p/selenium/wiki/InternetExplorerDriver –
或者@ Vadivelan的答案,當您在網格上啓動客戶端和服務器時,您也可以從命令行設置IEDriver。 –