测试用例总是失败,而不是Firefox

时间:2015-01-11 09:41:07

标签: eclipse selenium-webdriver jasmine

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中传递相同的代码?

1 个答案:

答案 0 :(得分:0)

您应该在初始化驱动程序之前设置Chrome驱动程序和IE驱动程序。

System.setProperty(" webdriver.ie.driver"," IEServer.exe的路径"); WebDriver driver = new InternetExplorerDriver();

System.setProperty(" webdriver.ie.chrome"," chromeserver.exe的路径"); WebDriver driver = new ChromeDriver();