@Subscribe public void configureBrowser(final BeforeWebDriverCreationEvent event) { switch (browser) { case "firefox": { // configure Firefox } case "chrome": { setPathToDriverIfExistsAndIsExecutable(relativePathToChromeDriver, ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY); // configure Chrome break; } case "ie": { setPathToDriverIfExistsAndIsExecutable(relativePathToIeDriver, InternetExplorerDriverService.IE_DRIVER_EXE_PROPERTY); // configure InternetExplorer break; } default: { throw new RuntimeException(String.format("Please configure one of the supported browsers in %s", JFunkConstants.SCRIPT_PROPERTIES)); } } }
/** * 本地初始化IE浏览器driver */ public InternetExplorer() { System.setProperty("webdriver.ie.driver", System.getProperty("user.dir") + Constants.IE_PATH); InternetExplorerDriverService service = (InternetExplorerDriverService) ((InternetExplorerDriverService.Builder) new InternetExplorerDriverService.Builder() .usingAnyFreePort()).build(); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);// 关闭保护模式,IE默认为开启模式 capabilities.setCapability("unexpectedAlertBehaviour", "accept"); this.driver = new InternetExplorerDriver(service, capabilities); }
private WebDriver getIeConfigurado(String proxy) { org.openqa.selenium.Proxy proxyy = new org.openqa.selenium.Proxy(); proxyy.setHttpProxy(proxy); proxyy.setFtpProxy(proxy); proxyy.setSslProxy(proxy); proxyy.setAutodetect(false); DesiredCapabilities capabilities = DesiredCapabilities .internetExplorer(); capabilities .setCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, false); capabilities.setCapability(CapabilityType.PROXY, proxyy); capabilities.setBrowserName("ie"); ieService = new InternetExplorerDriverService.Builder() .usingDriverExecutable(new File(InterNavegador.PATH_IEX)) .usingAnyFreePort().build(); try { ieService.start(); } catch (IOException e) { System.out.println(e); } return new RemoteWebDriver(ieService.getUrl(), capabilities); // return new InternetExplorerDriver(capabilities); }
@Override public DriverService createDriverService() { Builder builder = new InternetExplorerDriverService.Builder(); if (port != null) builder.usingPort(port); if (driverExecutable != null) builder.usingDriverExecutable(driverExecutable); if (environment != null) builder.withEnvironment(environment); if (logFile != null) builder.withLogFile(logFile); if (logLevel != null) builder.withLogLevel(InternetExplorerDriverLogLevel.valueOf(logLevel.toUpperCase())); if (engineImplementation != null) builder.withEngineImplementation(InternetExplorerDriverEngine.valueOf(engineImplementation.toUpperCase())); if (host != null) builder.withHost(host); if (extractPath != null) builder.withExtractPath(extractPath); if (silent != null) builder.withSilent(silent); return builder.build(); }
/** * {@inheritDoc} */ @Override public String getPathProperty() { return InternetExplorerDriverService.IE_DRIVER_EXE_PROPERTY; }
public InternetExplorerDriver(InternetExplorerDriverService service) { super(new org.openqa.selenium.ie.InternetExplorerDriver(service)); }
public InternetExplorerDriver(InternetExplorerDriverService service, Capabilities capabilities) { super(new org.openqa.selenium.ie.InternetExplorerDriver(service, capabilities)); }
public InternetExplorerDriver(InternetExplorerDriverService service, Capabilities capabilities, int port) { super(new org.openqa.selenium.ie.InternetExplorerDriver(service, capabilities, port)); }
/** * * @return the webdriver * @throws IOException if there is a problem loading the * properties file */ private WebDriver createWebDriver() throws IOException { Resource propertiesFile = new ClassPathResource( "META-INF/spring/application.properties"); Properties properties = new Properties(); properties.load(propertiesFile.getInputStream()); String webdriverMode = properties.getProperty("selenium.webdriver.mode", "local"); String driverName = properties.getProperty("selenium.webdriver.impl", "org.openqa.selenium.firefox.FirefoxDriver"); WebDriverBrowserType browser = WebDriverBrowserType.fromString(driverName); String display = properties.getProperty("selenium.display.port", ":0"); if (webdriverMode.equals("local")) { switch (browser) { case CHROME: String chromeLocation = properties .getProperty("selenium.webdriver.chromedriver.location"); Map<String,String> environment = new HashMap<String,String>(); environment.put("DISPLAY", display); ChromeDriverService chromeService = new ChromeDriverService.Builder() .usingDriverExecutable(new File(chromeLocation)) .usingAnyFreePort().withEnvironment(environment).build(); chromeService.start(); return new RemoteWebDriver(chromeService.getUrl(), DesiredCapabilities.chrome()); case SAFARI: return new SafariDriver(); case INTERNET_EXPLORER: String internetExplorerLocation = properties .getProperty("selenium.webdriver.ie.location"); InternetExplorerDriverService ieService = InternetExplorerDriverService.createDefaultService(); ieService.start(); return new RemoteWebDriver(ieService.getUrl(), DesiredCapabilities.internetExplorer()); case FIREFOX: default: FirefoxBinary firefoxBinary = new FirefoxBinary(); firefoxBinary.setEnvironmentProperty("DISPLAY", display); ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("default"); return new FirefoxDriver(firefoxBinary, profile); } } else { DesiredCapabilities capabilities = new DesiredCapabilities(); switch (browser) { case CHROME: capabilities = DesiredCapabilities.chrome(); break; case INTERNET_EXPLORER: capabilities = DesiredCapabilities.internetExplorer(); break; case SAFARI: capabilities = DesiredCapabilities.safari(); break; case FIREFOX: default: capabilities = DesiredCapabilities.firefox(); } String platformName = properties.getProperty("selenium.webdriver.platformName", "LINUX"); WebDriverPlatformType platform = WebDriverPlatformType.valueOf(platformName); switch (platform) { case MAC: capabilities.setPlatform(Platform.MAC); break; case WINDOWS: capabilities.setPlatform(Platform.WINDOWS); break; case LINUX: default: capabilities.setPlatform(Platform.LINUX); } return new RemoteWebDriver(new URL("http://build.e-monocot.org:4444/wd/hub"), capabilities); } }
public Browser createBrowser(int port) { InternetExplorerDriverService service = InternetExplorerDriverService.createDefaultService(); DesiredCapabilities capabilities = getDefaultCapabilities(); return createBrowser(new InternetExplorerDriver(service, capabilities, port)); }
public InternetExplorerBrowserFactory usingService(InternetExplorerDriverService ieds) { service = ieds; return this; }