[Selenium] 如何使 InternetExplorerDriver 每次启动的端口不会随机变化

InternetExplorerDriver 在不指定任何参数的情况下,启动监听端口会随机变化。如果需要保证其端口固定不变,可通过InternetExplorerDriverService 达到目的。示例代码:

public class testInternetExplorerService{

  public static void main(String[] args){

    System.setProperty("webdriver.ie.driver", "D:\Driver\IEDriverServer_Win32_2.37.0_latest\IEDriverServer.exe");

    

    InternetExplorerDriverService.Builder builder = new InternetExplorerDriverService.Builder();

    InternetExplorerDriverService internetExplorerService = builder.usingPort(5678).withHost("127.0.0.1").build();

 

    DesiredCapabilities capab = DesiredCapabilities.internetExplorer();

    capab.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);

    capab.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);

 

    WebDriver driver = new InternetExplorerDriver(internetExplorerService, capab);

    driver.get("http://www.baidu.com");

  }

}

posted @ 2015-06-04 11:46  *飞飞*  阅读(1844)  评论(1编辑  收藏  举报