您的位置:软件测试 > 开源软件测试 > 开源功能测试工具 > Selenium
记selenium1.2升级到selenium2.0
作者:网络转载 发布时间:[ 2014/3/7 11:31:10 ] 推荐标签:selenium 自动化测试

相关code:

public static WebDriver createInstance() throws MalformedURLException {

     

     if (BROWSER == "Firefox"){

    driverInstance = new FirefoxDriver();

     driverInstance.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);

    driverInstance.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

     driverInstance.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);

      } else if (BROWSER == "Safari"){

    DesiredCapabilities capability = DesiredCapabilities.safari();

    driverInstance = new RemoteWebDriver(new URL("http://192.168.61.138:5555/wd/hub"),capability);

     capability.setBrowserName("safari");

     capability.setPlatform(Platform.MAC);

    capability.setVersion("6.0.2");

      } else if (BROWSER == "Chrome"){

       System.setProperty("webdriver.chrome.driver","D:\selenium\selenium-server-2.31.0\chromedriver.exe");

      driverInstance = new ChromeDriver();

      } else if (BROWSER == "iExplore"){

    System.setProperty("webdriver.ie.driver", "D:\selenium\selenium-server-2.31.0\IEDriverServer.exe");

      DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();

  capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

      driverInstance = new InternetExplorerDriver(capabilities);

      }  else if (BROWSER == "HtmlUnit" ) {

      driverInstance = new HtmlUnitDriver(true);

         }

return driverInstance;

  }

3. 完成以上两步,差不多把所需的东西准备好了,接下来需要一步步开工了。首先,把底层框架中启动和停止server的代码修改为新的

 1.0中需要启动server才能运行,而在2.0中如果不通过Remote来运行的话是不需要启动server的,这里提到的启动实际是实例化过程,这中间会启动浏览器,停止时会释放资源并关闭浏览器。

protected static void startdriver() {

if (driver == null ){

try {

driver = DriverInstance.createInstance();

} catch (MalformedURLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

private static void stopDriver() {

//stop driver;

if (driver != null) {

driver.quit();

if ( browser == "Firefox") {

closeFireFox();

} else if (browser == "Chrome") {

closeChromeDriver();

}

}

}

上一页1234下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd