两种Selenium WebDriver实例化方式

来源:互联网 发布:golang面试题 编辑:程序博客网 时间:2024/04/30 10:11

1. Server <----> Client (one-to-one)

   代码:

   System.setProperty("webdriver.ie.driver", "D:\\ws\\selenium_app_version\\tool\\IEDriverServer.exe");
  
   DesiredCapabilities ieCapabilities = DesiredCapabilities
   .internetExplorer();
   ieCapabilities
   .setCapability(
   InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
   true);
   WebDriver oWebDriver = new InternetExplorerDriver();

 

2. Standalone,Server <---->Client (one-to-many)

  使用方法:

     1. 任意指定一个目录,如 D:\Software\Java_Dev\selenium\

         目录中需要包含如下文件:

                 selenium-server-standalone-2.35.0.jar

                 IEDriverServer.exe

      2. cd进此目录,执行如下命令。

                 java -jar selenium-server-standalone-2.35.0.jar -Dwebdriver.ie.driver=D:\Software\Java_Dev\selenium\IEDriverServer.exe

 

  代码:

  WebDriver driver = null;
  try {
   driver = new RemoteWebDriver(
     new URL("http://localhost:4444/wd/hub"),
     DesiredCapabilities.internetExplorer());
  } catch (MalformedURLException e) {
   e.printStackTrace();
  }

原创粉丝点击