List of usage examples for org.openqa.selenium.chrome ChromeOptions ChromeOptions
public ChromeOptions()
From source file:PokemonGoMapValidator.Config.java
public void configInstance(String driverFile, String profileFile, String mapFile) { WebDriver webDriver = null;/* www . j a v a2s.c om*/ try { System.setProperty("webdriver.chrome.driver", driverFile); String currentDirectory = Paths.get(".").toAbsolutePath().normalize().toString(); ZipFile zipFile = new ZipFile(profileFile); zipFile.extractAll(currentDirectory + "/" + "profile" + "/"); File f = new File(currentDirectory + "/prints/"); if (!f.isDirectory()) { new File(currentDirectory + "/prints/").mkdir(); } HashMap<String, Object> chromePrefs = new HashMap<>(); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory", currentDirectory); ChromeOptions options = new ChromeOptions(); //se na user-data-dir nao existir profile do chrome, gerado um na hora options.addArguments("user-data-dir=" + currentDirectory + "/" + "profile"); options.addArguments("--start-maximized"); //adicionei esta linha, j que dns e portos andam sempre em mudanas options.addArguments("--dns-prefetch-disable"); //options.addExtensions(new File(extensionFile)); options.setExperimentalOption("prefs", chromePrefs); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); capabilities.setCapability(ChromeOptions.CAPABILITY, options); webDriver = new ChromeDriver(capabilities); //pokemongos grow in sextagon shape, so I will force a square resolution webDriver.manage().window().setPosition(new Point(XCOORD, YCOORD)); if (MAPDIMENSION > 0) { webDriver.manage().window().setSize(new Dimension(MAPDIMENSION, MAPDIMENSION)); } else { webDriver.manage().window().maximize(); } //in the code below, I tried to create a square, but the width's and height's //seem to change, and I didn't figured out why and how //TODO in the future /* webDriver.get("http://www.google.com"); Thread.sleep(1000); Dimension win_size = webDriver.manage().window().getSize(); WebElement html = webDriver.findElement(By.tagName("html")); int inner_width = Integer.parseInt(html.getAttribute("clientWidth")); int outer_width = win_size.width - inner_width; int inner_height = Integer.parseInt(html.getAttribute("clientHeight")); int outer_height = win_size.height - inner_height; //pokemongos grow in sextagon shape, so I will force a square resolution webDriver.manage().window().setPosition(new Point(0, -1080)); webDriver.manage().window().setSize(new Dimension(800 + outer_width, 600 + outer_height)); if (VALIDATEBROWSER) { new Graphics().browserDimension(webDriver); } */ RunComparison comparison = new RunComparison(); comparison.comparison(currentDirectory, webDriver, mapFile); } catch (ZipException | IOException | InterruptedException ex) { System.err.println("Config error: " + ex.getMessage()); } finally { try { if (webDriver != null) { Exit sair = new Exit(); sair.exit(webDriver); System.out.println("ChromeDriver and Chrome unloaded"); } } catch (InterruptedException ex) { System.err.println("Exit error: " + ex.getMessage()); } } }
From source file:Search.DriverSetup.java
public static void GetDriver(int browserId) { {//from ww w . j ava 2 s .co m switch (browserId) { case 1: // For Firefox Driver driver = new FirefoxDriver(); break; case 2: // For Chrome Driver File file = new File("src/main/resources/chromedriver.exe"); String absolutePath = file.getAbsolutePath(); ChromeOptions options = new ChromeOptions(); options.addArguments("chrome.switches", "--disable-extensions"); System.setProperty("webdriver.chrome.driver", absolutePath); // System.setProperty("webdriver.chrome.driver", // "D:\\NetBeansProjects\\Max-IDS4.0\\src\\main\\resources\\chromedriver.exe"); driver = new ChromeDriver(options); break; case 3: // For IE Driver File file1 = new File("src/main/resources/IEDriverServer.exe"); String absolutePath1 = file1.getAbsolutePath(); System.setProperty("webdriver.ie.driver", absolutePath1); driver = new InternetExplorerDriver(); } } }
From source file:sfp.gov.py.core.CHDriver.java
License:Open Source License
private static void loadCapabilities() { System.setProperty("webdriver.chrome.driver", properties.getProperty("app.chromeDriver")); capability = DesiredCapabilities.chrome(); HashMap<String, Object> chromePrefs = new HashMap<String, Object>(); chromePrefs.put("profile.default_content_settings.popups", 0); chromePrefs.put("download.default_directory", properties.getProperty("app.download-path")); chromePrefs.put("download.prompt_for_download", "false"); chromePrefs.put("plugins.plugins_disabled", new String[] { "Adobe Flash Player", "Chrome PDF Viewer" }); ChromeOptions options = new ChromeOptions(); HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>(); options.setExperimentalOption("prefs", chromePrefs); options.addArguments("--test-type"); capability.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap); capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); capability.setCapability(ChromeOptions.CAPABILITY, options); }
From source file:streaming.crawler.WebDriverResource.java
License:Apache License
private WebDriver doCreateWebDriver(boolean headless, String browserType, Class<? extends WebDriver> defaultWebDriverClass, Long pageLoadTimeout, Long scriptTimeout, Long implicitlyWait//from w w w . jav a 2 s.c om ) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { DesiredCapabilities capabilities = new DesiredCapabilities(DEFAULT_CAPABILITIES); ChromeOptions chromeOptions = new ChromeOptions(); chromeOptions.merge(DEFAULT_CHROME_CAPABILITIES); // Use headless mode by default, GUI mode can be used for debugging chromeOptions.setHeadless(headless); if (headless) { // Do not downloading images in headless mode chromeOptions.addArguments("--blink-settings=imagesEnabled=false"); } // Reset proxy capabilities.setCapability(CapabilityType.PROXY, (Object) null); chromeOptions.setCapability(CapabilityType.PROXY, (Object) null); // Choose the WebDriver WebDriver driver; if (browserType == BrowserType.CHROME) { driver = new ChromeDriver(chromeOptions); } else { if (RemoteWebDriver.class.isAssignableFrom(defaultWebDriverClass)) { driver = defaultWebDriverClass.getConstructor(Capabilities.class).newInstance(capabilities); } else { driver = defaultWebDriverClass.getConstructor().newInstance(); } } // Set timeouts WebDriver.Timeouts timeouts = driver.manage().timeouts(); timeouts.pageLoadTimeout(pageLoadTimeout, TimeUnit.SECONDS); timeouts.setScriptTimeout(scriptTimeout, TimeUnit.SECONDS); timeouts.implicitlyWait(implicitlyWait, TimeUnit.SECONDS); // Set log level if (driver instanceof RemoteWebDriver) { RemoteWebDriver remoteWebDriver = (RemoteWebDriver) driver; final Logger webDriverLog = LoggerFactory.getLogger(WebDriver.class); Level level = Level.FINE; if (webDriverLog.isDebugEnabled()) { level = Level.FINER; } else if (webDriverLog.isTraceEnabled()) { level = Level.ALL; } remoteWebDriver.setLogLevel(level); } return driver; }
From source file:Utility.General.java
License:Open Source License
public static WebDriver GetBrowser(String driverName) { WebDriver driver = null;/*from www .jav a 2 s.com*/ switch (driverName) { case "IE": System.setProperty("webdriver.ie.driver", new General().LoadProperties().getProperty("ieDriver")); driver = new InternetExplorerDriver(); break; case "Firefox": driver = new FirefoxDriver(); break; case "Chrome": System.setProperty("webdriver.chrome.driver", new General().LoadProperties().getProperty("chromeDriver")); ChromeOptions options = new ChromeOptions(); options.addArguments("test-type"); driver = new ChromeDriver(options); break; case "Safari": driver = new SafariDriver(); break; } Log.info("Connnection opened using " + driverName + " browser."); return driver; }