Java Code Examples for org.openqa.selenium.remote.DesiredCapabilities.chrome()

The following are Jave code examples for showing how to use chrome() of the org.openqa.selenium.remote.DesiredCapabilities class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: akita-testing-template   File: AkitaChromeDriverProvider.java   Source Code and License Vote up 6 votes
@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    Map<String, Object> preferences = new Hashtable<>();
    preferences.put("profile.default_content_settings.popups", 0);
    preferences.put("download.prompt_for_download", "false");
    String downloadsPath = System.getProperty("user.home") + "/Downloads";
    preferences.put("download.default_directory", loadSystemPropertyOrDefault("fileDownloadPath", downloadsPath));
    preferences.put("plugins.plugins_disabled", new String[]{
            "Adobe Flash Player", "Chrome PDF Viewer"});
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", preferences);

    capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    capabilities.setCapability(ChromeOptions.CAPABILITY, options);
    return new ChromeDriver(capabilities);
}
 
Example 2
Project: Bytecoder   File: BytecoderUnitTestRunner.java   Source Code and License Vote up 6 votes
private WebDriver newDriverForTest() {
    ChromeOptions theOptions = new ChromeOptions();
    theOptions.addArguments("headless");
    theOptions.addArguments("disable-gpu");

    LoggingPreferences theLoggingPreferences = new LoggingPreferences();
    theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
    theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);

    DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
    theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);

    return new RemoteWebDriver(DRIVERSERVICE.getUrl(), theCapabilities);
}
 
Example 3
Project: akita   File: MobileChrome.java   Source Code and License Vote up 6 votes
/**
 * Создание instance google chrome эмулирующего работу на мобильном устройстве (по умолчанию nexus 5)
 * Мобильное устройство может быть задано через системные переменные
 *
 * @param capabilities настройки Chrome браузера
 * @return возвращает новый instance Chrome драйера
 */

@Override
public WebDriver createDriver(DesiredCapabilities capabilities) {
    log.info("---------------run CustomMobileDriver---------------------");
    String mobileDeviceName = loadSystemPropertyOrDefault("device", "Nexus 5");
    Map<String, String> mobileEmulation = new HashMap<>();
    mobileEmulation.put("deviceName", mobileDeviceName);

    Map<String, Object> chromeOptions = new HashMap<>();
    chromeOptions.put("mobileEmulation", mobileEmulation);

    DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();
    desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    desiredCapabilities.setBrowserName(desiredCapabilities.chrome().getBrowserName());
    return new ChromeDriver(desiredCapabilities);
}
 
Example 4
Project: delay-repay-bot   File: PhantomJSTest.java   Source Code and License Vote up 6 votes
@Test
public void testDriver() throws IOException {
    WebDriver driver = new RemoteWebDriver(toUrl("http://localhost:9515"), DesiredCapabilities.chrome());
    driver.get(URL2);

    String response = driver.getPageSource();
    Document doc = Jsoup.connect(URL2).ignoreContentType(true).get();
    Elements scriptTags = doc.select("body");

    // get All functions


    try {
        String result = (String) engine.eval(response);
    } catch (ScriptException e) {
        e.printStackTrace();
    }

    log.info("PageSource " + response);

    driver.quit();
}
 
Example 5
Project: functional-programming-selenium-examples   File: Chrome.java   Source Code and License Vote up 5 votes
@Override
public WebDriver getWebDriver()
{
	System.setProperty("webdriver.chrome.driver", "src/test/resources/chromedriver.2.27");
       DesiredCapabilities capabilities = DesiredCapabilities.chrome();
       return new ChromeDriver(capabilities);
}
 
Example 6
Project: NoraUi   File: DriverFactory.java   Source Code and License Vote up 5 votes
/**
 * Generates a chrome webdriver.
 *
 * @param headlessMode
 *            Enable headless mode ?
 * @return
 *         A chrome webdriver
 * @throws TechnicalException
 *             if an error occured when Webdriver setExecutable to true.
 */
private WebDriver generateGoogleChromeDriver(boolean headlessMode) throws TechnicalException {
    final String pathWebdriver = DriverFactory.getPath(Driver.CHROME);
    if (!new File(pathWebdriver).setExecutable(true)) {
        throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE));
    }
    logger.info("Generating Chrome driver ({}) ...", pathWebdriver);

    System.setProperty(Driver.CHROME.getDriverName(), pathWebdriver);

    final ChromeOptions chromeOptions = new ChromeOptions();
    final DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
    capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT);

    setLoggingLevel(capabilities);

    if (Context.isHeadless()) {
        chromeOptions.addArguments("--headless");
    }

    // Proxy configuration
    if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) {
        capabilities.setCapability(CapabilityType.PROXY, Context.getProxy());
    }

    setChromeOptions(capabilities, chromeOptions);

    String withWhitelistedIps = Context.getWebdriversProperties("withWhitelistedIps");
    if (withWhitelistedIps != null && !"".equals(withWhitelistedIps)) {
        ChromeDriverService service = new ChromeDriverService.Builder().withWhitelistedIps(withWhitelistedIps).withVerbose(false).build();
        return new ChromeDriver(service, capabilities);
    } else {
        return new ChromeDriver(capabilities);
    }
}
 
Example 7
Project: carnotzet   File: ExamplesTest.java   Source Code and License Vote up 5 votes
private static WebDriver createBrowserSession() throws MalformedURLException {
	DesiredCapabilities capabilities = DesiredCapabilities.chrome();
	capabilities.setJavascriptEnabled(true);
	LoggingPreferences logPreferences = new LoggingPreferences();
	logPreferences.enable(LogType.BROWSER, Level.ALL);
	capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPreferences);
	return new RemoteWebDriver(
			new URL("http://" + runtime.getContainer("selenium-chrome").getIp() + ":4444/wd/hub"),
			capabilities
	);
}
 
Example 8
Project: SWET   File: BrowserDriver.java   Source Code and License Vote up 5 votes
private static DesiredCapabilities capabilitiesAndroid() {
	DesiredCapabilities capabilities = DesiredCapabilities.chrome();

	Map<String, String> mobileEmulation = new HashMap<>();
	mobileEmulation.put("deviceName", "Google Nexus 5");

	Map<String, Object> chromeOptions = new HashMap<>();
	chromeOptions.put("mobileEmulation", mobileEmulation);
	capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

	return capabilities;
}
 
Example 9
Project: SWET   File: BrowserDriver.java   Source Code and License Vote up 5 votes
private static DesiredCapabilities capabilitiesiPhone() {
	DesiredCapabilities capabilities = DesiredCapabilities.chrome();

	Map<String, String> mobileEmulation = new HashMap<>();
	mobileEmulation.put("deviceName", "Apple iPhone 6");

	Map<String, Object> chromeOptions = new HashMap<>();
	chromeOptions.put("mobileEmulation", mobileEmulation);
	capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

	return capabilities;
}
 
Example 10
Project: SWET   File: BrowserDriver.java   Source Code and License Vote up 5 votes
private static DesiredCapabilities capabilitiesiPad() {
	DesiredCapabilities capabilities = DesiredCapabilities.chrome();

	Map<String, String> mobileEmulation = new HashMap<>();
	mobileEmulation.put("deviceName", "Apple iPad");

	Map<String, Object> chromeOptions = new HashMap<>();
	chromeOptions.put("mobileEmulation", mobileEmulation);
	capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

	return capabilities;
}
 
Example 11
Project: argument-reasoning-comprehension-task   File: DebateFetcher.java   Source Code and License Vote up 5 votes
public DebateFetcher(String chromeDriverFile)
        throws IOException
{
    service = new ChromeDriverService.Builder()
            .usingDriverExecutable(
                    new File(chromeDriverFile))
            .usingAnyFreePort()
            .withEnvironment(ImmutableMap.of("DISPLAY", ":20")).build();
    service.start();

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    driver = new RemoteWebDriver(service.getUrl(), capabilities);
}
 
Example 12
Project: AutomationFrameworkTPG   File: DriverProperties.java   Source Code and License Vote up 5 votes
private WebDriver initChromeDriver(String appURL) {
	System.out.println("Launching google chrome with new profile..");
	DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ()    ;   
			handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
	ChromeDriver driver = new ChromeDriver(handlSSLErr);
	driver.manage().window().maximize();
	driver.navigate().to(appURL);
	return new WebDriverProxy().protect(driver);
}
 
Example 13
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   Source Code and License Vote up 5 votes
public static WebDriver getChromeDriver()
{
       String path = "src/test/resources/chromedriver";
	System.setProperty("webdriver.chrome.driver", path);

	DesiredCapabilities capabilities = DesiredCapabilities.chrome();
       capabilities.setCapability("networkConnectionEnabled", true);
       capabilities.setCapability("browserConnectionEnabled", true);

       return new ChromeDriver(capabilities);
}
 
Example 14
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   Source Code and License Vote up 5 votes
public static WebDriver getChromeDriver()
{
       String path = "src/test/resources/chromedriver";
	System.setProperty("webdriver.chrome.driver", path);

	DesiredCapabilities capabilities = DesiredCapabilities.chrome();
       capabilities.setCapability("networkConnectionEnabled", true);
       capabilities.setCapability("browserConnectionEnabled", true);

       return new ChromeDriver(capabilities);
}
 
Example 15
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   Source Code and License Vote up 5 votes
public static WebDriver getChromeDriver(String pathToChromeExecutable)
{
	String path = System.getProperty("user.dir") + "\\Drivers\\chromedriver.exe";
	System.setProperty("webdriver.chrome.driver",path);

	Map<String, Object> chromeOptions = new HashMap<String, Object>();
	chromeOptions.put("binary", pathToChromeExecutable);
	DesiredCapabilities capabilities = DesiredCapabilities.chrome();
	capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

	return new ChromeDriver(capabilities);
}
 
Example 16
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   Source Code and License Vote up 5 votes
public static WebDriver getChromeDriver()
{
       String path = "src/test/resources/chromedriver";
	System.setProperty("webdriver.chrome.driver", path);

	DesiredCapabilities capabilities = DesiredCapabilities.chrome();
       capabilities.setCapability("networkConnectionEnabled", true);
       capabilities.setCapability("browserConnectionEnabled", true);

       return new ChromeDriver(capabilities);
}
 
Example 17
Project: Spring-Security-Third-Edition   File: SeleniumTestUtilities.java   Source Code and License Vote up 5 votes
public static WebDriver getChromeDriver(String pathToChromeExecutable)
{
	String path = System.getProperty("user.dir") + "\\Drivers\\chromedriver.exe";
	System.setProperty("webdriver.chrome.driver",path);

	Map<String, Object> chromeOptions = new HashMap<String, Object>();
	chromeOptions.put("binary", pathToChromeExecutable);
	DesiredCapabilities capabilities = DesiredCapabilities.chrome();
	capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

	return new ChromeDriver(capabilities);
}
 
Example 18
Project: daf-cacher   File: Browser.java   Source Code and License Vote up 5 votes
public Builder chrome() {
    this.browserCaps = DesiredCapabilities.chrome();

    ChromeOptions options = new ChromeOptions();
    options.addArguments("'--start-maximized", "--window-size=1360,1020");
    this.browserCaps.setCapability(ChromeOptions.CAPABILITY, options);
    this.browserCaps.setCapability("enableVNC", true);

    return this;
}
 
Example 19
Project: jcat   File: Base.java   Source Code and License Vote up 4 votes
@BeforeTest
public void setUp() throws MalformedURLException {
    driver = new RemoteWebDriver(new URL("http://localhost:9515"), DesiredCapabilities.chrome());
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
}
 
Example 20
Project: BHBot   File: MainThread.java   Source Code and License Vote up 4 votes
public static void connectDriver() throws MalformedURLException {
	ChromeOptions options = new ChromeOptions();
	// https://sites.google.com/a/chromium.org/chromedriver/capabilities
	//options.addArguments("user-data-dir=./chrome_profile_test"); // will create this profile folder where chromedriver.exe is located!
	options.addArguments("user-data-dir=./chrome_profile"); // will create this profile folder where chromedriver.exe is located!
	//***options.addArguments("--no-startup-window");
	//***options.addArguments("--silent-launch");

	if (BHBot.settings.useHeadlessMode) {
		options.setBinary("C:/Users/Betalord/AppData/Local/Google/Chrome SxS/Application/chrome.exe");
		
		// https://sites.google.com/a/chromium.org/chromedriver/capabilities
		
		options.addArguments("--headless");
		//options.addArguments("--disable-gpu"); // in future versions of Chrome this flag will not be needed
		
		/*
		options.addArguments("--disable-plugins");
		options.addArguments("--disable-internal-flash");
		options.addArguments("--disable-plugins-discovery");
		*/
		//options.addArguments("--disable-bundled-ppapi-flash");
		
		
		
		options.addArguments("--always-authorize-plugins");
		options.addArguments("--allow-outdated-plugins");
		options.addArguments("--allow-file-access-from-files");
		options.addArguments("--allow-running-insecure-content");
		options.addArguments("--disable-translate");
		options.addArguments("-�allow-webui-compositing"); // https://adestefawp.wordpress.com/software/chromium-command-line-switches/
		options.addArguments("-�ppapi-flash-in-process"); 

		options.addArguments("--use-fake-device-for-media-stream");
		options.addArguments("--disable-web-security");
		
		
		options.setExperimentalOption("excludeSwitches", Arrays.asList("disable-component-update", "disable-default-apps"));
		
		//options.setExperimentalOption("#run-all-flash-in-allow-mode", Arrays.asList("Enabled"));
		//options.setExperimentalOption("#run-all-flash-in-allow-mode", "Enabled");
		
		Map<String, Object> prefs = new HashMap<>();
		prefs.put("run-all-flash-in-allow-mode", Boolean.valueOf(true));
		prefs.put("profile.run_all_flash_in_allow_mode", Boolean.valueOf(true));
		options.setExperimentalOption("prefs", prefs);
		
		//options.addExtensions(new File("C:/Users/Betalord/AppData/Local/Google/Chrome SxS/Application/chrome_profile_test/PepperFlash/26.0.0.137/pepflashplayer.dll"));
		//options.addExtensions(new File("C:/Users/Betalord/AppData/Local/Google/Chrome SxS/User Data/PepperFlash/26.0.0.137/pepflashplayer.dll"));
		
		//options.addArguments("--remote-debugging-port=9222"); // this doesn't work because ChromeDriver uses dubuging port internally. Read about it here: https://bugs.chromium.org/p/chromedriver/issues/detail?id=878#c16
	}
	
	//options.addArguments("--no-startup-window"); // does not work with WebDriver. Read about it here: https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/5351
	
	
	//options.addArguments("--headless");
	//options.addArguments("--disable-gpu");
	options.addArguments("--mute-audio"); // found this solution here: https://stackoverflow.com/questions/39392479/how-to-mute-all-sounds-in-chrome-webdriver-with-selenium/39392601#39392601
	
	//***ChromeDriverService chromeDriverService = ChromeDriverService.createDefaultService();
	//***chromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY

	DesiredCapabilities capabilities = DesiredCapabilities.chrome();
	capabilities.setCapability(ChromeOptions.CAPABILITY, options);
	driver = new RemoteWebDriver(new URL("http://" + BHBot.chromeDriverAddress), capabilities);
	//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}