Java Code Examples for org.openqa.selenium.chrome.ChromeOptions.setExperimentalOption()

The following are Jave code examples for showing how to use setExperimentalOption() of the org.openqa.selenium.chrome.ChromeOptions 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: teasy   File: SeleniumTestExecutionListener.java   Source Code and License Vote up 8 votes
private DesiredCapabilities getChromeDesiredCapabilities(Settings settings) {
        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        //Added to avoid yellow warning in chrome 35
        ChromeOptions options = new ChromeOptions();
//        options.addArguments("test-type");
        //For view pdf in chrome
        options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type", "--ignore-certificate-errors"));

        if (settings.isHeadlessBrowser()) {
            options.addArguments("headless");
        }

        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        capabilities.setPlatform(Platform.WINDOWS);
        setAlertBehaviorCapabilities(capabilities);
        setLoggingPrefs(capabilities);
        setProxy(capabilities);
        return capabilities;
    }
 
Example 2
Project: NoraUi   File: DriverFactory.java   Source Code and License Vote up 7 votes
/**
 * Sets the target browser binary path in chromeOptions if it exists in configuration.
 *
 * @param capabilities
 *            The global DesiredCapabilities
 */
private void setChromeOptions(final DesiredCapabilities capabilities, ChromeOptions chromeOptions) {

    // Set custom downloaded file path. When you check content of downloaded file by robot.
    HashMap<String, Object> chromePrefs = new HashMap<>();
    chromePrefs.put("download.default_directory", System.getProperty("user.dir") + File.separator + "downloadFiles");
    chromeOptions.setExperimentalOption("prefs", chromePrefs);

    // Set custom chromium (if you not use default chromium on your target device)
    String targetBrowserBinaryPath = Context.getWebdriversProperties("targetBrowserBinaryPath");
    if (targetBrowserBinaryPath != null && !"".equals(targetBrowserBinaryPath)) {
        chromeOptions.setBinary(targetBrowserBinaryPath);
    }

    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
}
 
Example 3
Project: givemeadriver   File: ChromeCapabilitiesConverterTest.java   Source Code and License Vote up 6 votes
@Test
public void settingAllChromeProperties() throws IOException {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("device", IPHONE_DEVICE);
    properties.setProperty("userAgent", ANY_USER_AGENT);
    properties.setProperty("viewportSize", "378x664");
    properties.setProperty("pixelRatio", "3.0");
    properties.setProperty("headless", "true");

    // when
    Capabilities convertedCapabilities = chromeCapabilitiesConverter.convert(properties);

    // then
    // expected chrome options
    ChromeOptions expectedChromeOptions = new ChromeOptions();
    expectedChromeOptions.setCapability(CAPABILITY_BROWSER_NAME, "chrome");
    expectedChromeOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
    Map<String, Object> expectedMobileEmulation = new HashMap<>();
    Map<String, Object> expectedDeviceMetrics = new HashMap<>();
    expectedDeviceMetrics.put("width", 378);
    expectedDeviceMetrics.put("height", 664);
    expectedDeviceMetrics.put(CAPABILITY_PIXEL_RATIO, 3.0);
    expectedMobileEmulation.put("deviceMetrics", expectedDeviceMetrics);
    expectedMobileEmulation.put(CAPABILITY_DEVICE_NAME, IPHONE_DEVICE);
    expectedMobileEmulation.put(CAPABILITY_USER_AGENT, ANY_USER_AGENT);
    expectedChromeOptions.setExperimentalOption("mobileEmulation", expectedMobileEmulation);
    expectedChromeOptions.addArguments("--disable-device-discovery-notifications");
    expectedChromeOptions.addArguments("--disable-infobars");
    expectedChromeOptions.addArguments("--headless", "--disable-gpu");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedChromeOptions.asMap());
}
 
Example 4
Project: givemeadriver   File: ChromeCapabilitiesConverterTest.java   Source Code and License Vote up 6 votes
@Test
public void notSettingDeviceMetrics() throws IOException {
    // given
    WebDriverProperties properties = new WebDriverProperties();
    properties.setProperty("device", IPHONE_DEVICE);
    properties.setProperty("userAgent", ANY_USER_AGENT);

    // when
    Capabilities convertedCapabilities = chromeCapabilitiesConverter.convert(properties);

    // then
    // expected chrome options
    ChromeOptions expectedChromeOptions = new ChromeOptions();
    Map<String, Object> expectedMobileEmulation = new HashMap<>();
    expectedChromeOptions.setCapability(CAPABILITY_BROWSER_NAME, "chrome");
    expectedChromeOptions.setCapability(CAPABILITY_AUTOCLOSE, false);
    expectedMobileEmulation.put(CAPABILITY_DEVICE_NAME, IPHONE_DEVICE);
    expectedMobileEmulation.put(CAPABILITY_USER_AGENT, ANY_USER_AGENT);
    expectedChromeOptions.setExperimentalOption("mobileEmulation", expectedMobileEmulation);
    expectedChromeOptions.addArguments("--disable-device-discovery-notifications");
    expectedChromeOptions.addArguments("--disable-infobars");

    assertThat(convertedCapabilities.asMap()).isEqualTo(expectedChromeOptions.asMap());
}
 
Example 5
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 6
Project: hippo   File: WebDriverProvider.java   Source Code and License Vote up 6 votes
/**
 * Initialises the WebDriver (client).
 *
 * This method should be called once before each test to ensure that the session state doesn't bleed from one test
 * to another (such as user being logged in).
 */
public void initialise() {

    final ChromeOptions chromeOptions = new ChromeOptions();

    final Map<String, Object> chromePrefs = new HashMap<>();
    log.info("Setting WebDriver download directory to '{}'.", downloadDirectory);
    chromePrefs.put("download.default_directory", downloadDirectory.toAbsolutePath().toString());

    chromeOptions.setExperimentalOption("prefs", chromePrefs);
    log.info("Configuring WebDriver to run in {} mode.", isHeadlessMode ? "headless" : "full, graphical");
    if (isHeadlessMode) {
        chromeOptions.addArguments("--headless");
        chromeOptions.addArguments("window-size=1920,1080");
    }

    webDriver = new RemoteWebDriver(webDriverServiceProvider.getUrl(), chromeOptions);
}
 
Example 7
Project: f4f-tts   File: ScrapperTtsUpdater.java   Source Code and License Vote up 6 votes
private ChromeDriver setUp(Properties properties) {
    System.setProperty("webdriver.chrome.driver", properties.getProperty("webdriver.chrome.driver"));
    String binaryPath = properties.getProperty(CHROME_DRIVER_BINARY_PATH);

    if (binaryPath == null) {
        throw new RuntimeException("Missing property : " + CHROME_DRIVER_BINARY_PATH);
    }

    Map<String, Object> prefs = new HashMap<>();
    prefs.put("profile.default_content_setting_values.notifications", 2);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", prefs);
    options.setBinary(binaryPath);
    options.addArguments("--headless");
    options.addArguments("--user-agent=" + "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36");
    return new ChromeDriver(options);
}
 
Example 8
Project: AndroidRobot   File: ChromeDriverClient.java   Source Code and License Vote up 6 votes
public void createDriver(String pkg_name, String sn) {
    	if(this.driver == null) {
	        ChromeOptions chromeOptions = new ChromeOptions();
	        chromeOptions.setExperimentalOption("androidPackage", pkg_name);
	//        chromeOptions.setExperimentalOption("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin");
	//        chromeOptions.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
	        chromeOptions.setExperimentalOption("androidUseRunningApp", true);
	        chromeOptions.setExperimentalOption("androidDeviceSerial", sn);
	//        Map<String, Object> chromeOptions = new HashMap<String, Object>();
	//        chromeOptions.put("androidPackage", "com.eg.android.AlipayGphoneRC");
	//        chromeOptions.put("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin");
	        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
	        LoggingPreferences logPrefs = new LoggingPreferences();
	        logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
	        capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
	        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
//	        capabilities.setCapability(CapabilityType., value);
	        if(ChromeService.getService() != null)
	        	driver = new RobotRemoteWebDriver(ChromeService.getService().getUrl(), capabilities);
    	}
    }
 
Example 9
Project: frameworkium-core   File: ChromeImpl.java   Source Code and License Vote up 6 votes
@Override
public ChromeOptions getCapabilities() {
    ChromeOptions chromeOptions = new ChromeOptions();
    // useful defaults
    chromeOptions.setCapability(
            "chrome.switches",
            singletonList("--no-default-browser-check"));
    chromeOptions.setCapability(
            "chrome.prefs",
            ImmutableMap.of("profile.password_manager_enabled", "false"));

    // Use Chrome's built in device emulators
    if (Property.DEVICE.isSpecified()) {
        chromeOptions.setExperimentalOption(
                "mobileEmulation",
                ImmutableMap.of("deviceName", Property.DEVICE.getValue()));
    }

    // Allow user to provide their own user directory, for custom chrome profiles
    if (Property.CHROME_USER_DATA_DIR.isSpecified()) {
        chromeOptions.addArguments(
                "user-data-dir=" + Property.CHROME_USER_DATA_DIR.getValue());
    }
    chromeOptions.setHeadless(Property.HEADLESS.getBoolean());
    return chromeOptions;
}
 
Example 10
Project: carina   File: ChromeCapabilities.java   Source Code and License Vote up 6 votes
public DesiredCapabilities getCapability(String testName)
{
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities = initBaseCapabilities(capabilities, BrowserType.CHROME, testName);
	capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized", "--ignore-ssl-errors"));
	capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
	capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, false);

	ChromeOptions options = new ChromeOptions();
	options.addArguments("test-type");

	if (Configuration.getBoolean(Configuration.Parameter.AUTO_DOWNLOAD))
	{
		HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
		chromePrefs.put("download.prompt_for_download", false);
		chromePrefs.put("download.default_directory", ReportContext.getArtifactsFolder().getAbsolutePath());
		chromePrefs.put("plugins.always_open_pdf_externally", true);
		options.setExperimentalOption("prefs", chromePrefs);
	}

	capabilities.setCapability(ChromeOptions.CAPABILITY, options);
	return capabilities;
}
 
Example 11
Project: jspider   File: ChromeDesiredCapabilities.java   Source Code and License Vote up 5 votes
public ChromeDesiredCapabilities() {
    super(BrowserType.ANDROID, "", Platform.ANDROID);

    prefs = new HashMap<String, Object>();
    options = new ChromeOptions();
    options.setExperimentalOption("prefs", prefs);
    setCapability(ChromeOptions.CAPABILITY, options);
}
 
Example 12
Project: Cognizant-Intelligent-Test-Scripter   File: WebDriverFactory.java   Source Code and License Vote up 5 votes
private static DesiredCapabilities getChromeEmulatorCaps(DesiredCapabilities caps, String deviceName) {
    Map<String, String> mobileEmulation = new HashMap<>();
    mobileEmulation.put("deviceName", deviceName);
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
    caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
    return caps;
}
 
Example 13
Project: mineraloil-selenium   File: ChromeSettings.java   Source Code and License Vote up 5 votes
public static DesiredCapabilities getDesiredCapabilities() {
    Map<String, Object> prefs = new HashMap<>();
    DesiredCapabilities profile = DesiredCapabilities.chrome();
    ChromeOptions options = new ChromeOptions();

    prefs.put("profile.default_content_settings.popups", 0);
    options.setExperimentalOption("prefs", prefs);
    profile.setCapability("name", "chrome");
    profile.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
    profile.setCapability(ChromeOptions.CAPABILITY, options);
    profile.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    return profile;
}
 
Example 14
Project: selenium-utils   File: ChromeBuildr.java   Source Code and License Vote up 5 votes
/**
 * Create chrome options from passes locales
 * @param locales comma-separated locales
 * @return chrome options
 */
public static ChromeOptions createChromeOptions(String locales) {
    ChromeOptions options = new ChromeOptions();
    options.addArguments("test-type");
    if (locales !=null) {
        HashMap<String, String> prefs = new HashMap<String, String>();
        prefs.put("intl.accept_languages", locales);
        options.setExperimentalOption("prefs", prefs);
    }
    return options;
}
 
Example 15
Project: kspl-selenium-helper   File: BaseActions.java   Source Code and License Vote up 5 votes
@BeforeMethod
@Parameters({ "remoteURL", "baseURL", "OS", "browser",
		"version", "internal" })
public void beforeTest(String remoteURL, String baseURL,
		String OS, String browser, String version, String internal)
		throws IOException {
	this.testCase = new TestCase();
	this.testCase.setExecutionEnvironment("{browser:"+browser+",browserVersion:"+version+",OperatingSystem:"+OS+"}");
	this.testCase.setParentURL(baseURL);
	this.testCase.setTestCaseId("KT"+testCaseCount++);
	this.testCase.setScreenshotDirectory(log.getReportDirectory()+ File.separator + "images");
	config = new WebDriverConfig();
	config.setRemoteURL(remoteURL);
	this.baseURL = baseURL;
	config.setOS(OS);
	config.setBrowserName(browser);
	config.setBrowserVersion(version);
	config.setIntenal(Boolean.parseBoolean(internal));
	ChromeOptions options = new ChromeOptions();
	options.addArguments("--start-maximized");
	options.addArguments("--enable-strict-powerful-feature-restrictions");
	JsonObject jsonObject = new JsonObject();
	jsonObject.addProperty("profile.default_content_settings.geolocation", 2);
	jsonObject.addProperty("profile.default_content_setting_values.notifications",2);
	options.setExperimentalOption("prefs", jsonObject);
	options.addArguments("--disable-notifications");
	config.setChromeOptions(options);
	driver = xRemoteWebDriver.getInstance(config, log);
	driver.manage().window().maximize();
	driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	driver.get(this.baseURL);
}
 
Example 16
Project: minium   File: WebDriverFactory.java   Source Code and License Vote up 5 votes
private Capabilities chromeCapabilities(ChromeOptionsProperties chromeProperties) {
    ChromeOptions options = new ChromeOptions();
    if (chromeProperties.getArgs() != null) options.addArguments(chromeProperties.getArgs());
    if (chromeProperties.getBinary() != null) options.setBinary(chromeProperties.getBinary());
    if (chromeProperties.getExtensions() != null) options.addExtensions(chromeProperties.getExtensions());
    if (chromeProperties.getPreferences() != null) options.setExperimentalOption("prefs", chromeProperties.getPreferences());
    return options;
}
 
Example 17
Project: dropwizard-experiment   File: WebDriverFactory.java   Source Code and License Vote up 5 votes
/**
 * Create a Chrome WebDriver instance.
 * @return The WebDriver
 */
public static EventFiringWebDriver createChrome() {
    String chromeDriverBinary = WebDriverBinaryFinder.findChromeDriver();
    System.setProperty("webdriver.chrome.driver", chromeDriverBinary);
    log.info("Using ChromeDriver binary from {}", chromeDriverBinary);

    // Prevent annoying yellow warning bar from being displayed.
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("excludeSwitches", ImmutableList.of("ignore-certificate-errors"));
    DesiredCapabilities caps = getCapabilities();
    caps.setCapability(ChromeOptions.CAPABILITY, options);

    return withReports(new ChromeDriver(caps));
}
 
Example 18
Project: givemeadriver   File: ChromeCapabilitiesConverter.java   Source Code and License Vote up 4 votes
@Override
public Capabilities convert(WebDriverProperties properties) {
    Map<String, Object> deviceMetrics = new HashMap<>();
    Map<String, Object> mobileEmulation = new HashMap<>();
    ChromeOptions chromeOptions = new ChromeOptions();

    // general options for logging purpose
    chromeOptions.setCapability(CAPABILITY_AUTOCLOSE, properties.isAutoClose());
    addToChromeOptionsIfNoEmptyValue(chromeOptions, CAPABILITY_DRIVER_VERSION, properties.getDriverVersion());
    addToChromeOptionsIfNoEmptyValue(chromeOptions, CAPABILITY_BROWSER_SIZE, properties.getBrowserSize());

    //https://cs.chromium.org/chromium/src/chrome/test/chromedriver/chrome/mobile_device_list.cc
    addToMapIfNoEmptyValue(mobileEmulation, CAPABILITY_DEVICE_NAME, properties.getDeviceName());
    addToMapIfNoEmptyValue(mobileEmulation, CAPABILITY_USER_AGENT, properties.getUserAgent());

    // calculate the deviceMetrics
    if (isNotEmpty(properties.getViewportSize())) {
        String[] dimension = properties.getViewportSize().split("x");
        int width = Integer.parseInt(dimension[0]);
        int height = Integer.parseInt(dimension[1]);
        deviceMetrics.put("width", width);
        deviceMetrics.put("height", height);
    }
    if (properties.getPixelRatio() != 0.0) {
        deviceMetrics.put(CAPABILITY_PIXEL_RATIO, properties.getPixelRatio());
    }

    // add deviceMetrics and mobileEmulation
    if(!deviceMetrics.isEmpty())
        mobileEmulation.put("deviceMetrics", deviceMetrics);

    if(!mobileEmulation.isEmpty()) {
        chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);
    }

    // setting additional arguments
    // https://sites.google.com/a/chromium.org/chromedriver/capabilities
    chromeOptions.addArguments("--disable-device-discovery-notifications");
    chromeOptions.addArguments("--disable-infobars");
    if(properties.isHeadless())
        chromeOptions.setHeadless(true);

    return chromeOptions;
}
 
Example 19
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);
}
 
Example 20
Project: hello-openfin-selenium-java-example   File: SimpleTest.java   Source Code and License Vote up 4 votes
/**
 * main method
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    String execPath = System.getProperty("ExecPath");   // path to OpenFinRVM.exe
    String execArgs = System.getProperty("ExecArgs");   // command arguments for OpenFinRVM.exe, such as --config="app.json"
    String debuggerAddress = System.getProperty("DebuggerAddress");  // debugger URL for OpenFin Runtime.exe
    String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
    WebDriver driver;
    int etagSeq = 1;

    ChromeOptions options = new ChromeOptions();
    if (execPath != null) {
        System.out.println("Binary path " + execPath);
        options.setBinary(new File(execPath));
        options.addArguments(execArgs);
    }
    options.setExperimentalOption("debuggerAddress", debuggerAddress != null ? debuggerAddress : "localhost:9090");
    options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

    System.out.println("Creating remote driver " + remoteDriverURL);

    while (etagSeq < 20) {
        driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);
        System.out.println("Got the driver " + driver.getCurrentUrl());
        driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);
        try {
            if (switchWindow(driver, "ETAG check")) {  // select main window
                sleep(1);
            }
            WebElement body = driver.findElement(By.id("etagseq"));
            String tag = body.getText();
            if (Integer.parseInt(tag) != etagSeq) {
                System.out.println(String.format("Mismatch %d %s", etagSeq, tag));
                break;
            }
            System.out.printf(String.format("Run %d", etagSeq));
            executeJavascript(driver, "fin.desktop.System.exit();");  // ask OpenFin Runtime to exit
            sleep(5);
            etagSeq++;
        } catch (Exception e) {
            e.printStackTrace();
            break;
        } finally {
            driver.quit();
        }
    }
}
 
Example 21
Project: hello-openfin-selenium-java-example   File: AngularUISelectTest.java   Source Code and License Vote up 4 votes
/**
 * main method
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    String execPath = System.getProperty("ExecPath");   // path to OpenFinRVM.exe
    String execArgs = System.getProperty("ExecArgs");   // command arguments for OpenFinRVM.exe, such as --config="app.json"
    String debuggerAddress = System.getProperty("DebuggerAddress");  // debugger URL for OpenFin Runtime.exe
    String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
    WebDriver driver;

    ChromeOptions options = new ChromeOptions();
    if (execPath != null) {
        System.out.println("Binary path " + execPath);
        options.setBinary(new File(execPath));
        options.addArguments(execArgs);
    }
    options.setExperimentalOption("debuggerAddress", debuggerAddress != null ? debuggerAddress : "localhost:9090");
    options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

    System.out.println("Creating remote driver " + remoteDriverURL);
    driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);

    System.out.println("Got the driver " + driver.getCurrentUrl());
    driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);

    try {
        if (switchWindow(driver, "AngularJS ui-select")) {  // select main window
            sleep(1);
        }

        WebElement body = driver.findElement(By.tagName("body"));
        List<WebElement> list = body.findElements(By.cssSelector("div.ui-select-container"));
        for (WebElement container: list) {
            WebElement focusser = container.findElement(By.cssSelector(".ui-select-match"));
            focusser.click();
            WebElement input = container.findElement(By.cssSelector("input.ui-select-search"));
            input.clear();
            input.sendKeys("Adam");
            input.sendKeys(Keys.ENTER);
        }
        Thread.sleep(10000);  // sleep here so we can see it works
        executeJavascript(driver, "fin.desktop.System.exit();");  // ask OpenFin Runtime to exit
        sleep(2);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        driver.quit();
    }
}
 
Example 22
Project: hello-openfin-selenium-java-example   File: ChromeTest.java   Source Code and License Vote up 4 votes
public static void main(String[] args) throws Exception {
        String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
        WebDriver driver;

        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

        System.out.println("Creating remote driver " + remoteDriverURL);
        driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);

        System.out.println("Got the driver " + driver.getCurrentUrl());
        driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);

        try {
            driver.get("http://localhost:8080/examples/demo.html");
            Thread.sleep(2000);
            WebElement body = driver.findElement(By.tagName("body"));
            List<WebElement> list = body.findElements(By.cssSelector("div.ui-select-container"));
            System.out.println(String.format("populating input of %d elements", list.size()));
            for (WebElement container: list) {

                WebElement focusser = container.findElement(By.cssSelector("input.ui-select-focusser"));

                focusser.sendKeys("aa\n");

//                WebElement focusser = container.findElement(By.cssSelector(".ui-select-match"));

//                focusser.click();
                WebElement input = container.findElement(By.cssSelector("input.ui-select-search"));
                input.clear();
                input.sendKeys("aa");
                input.sendKeys(Keys.ENTER);
                Actions action = new Actions(driver);
                action.sendKeys(Keys.ARROW_DOWN);

            }
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.quit();
        }
    }
 
Example 23
Project: hello-openfin-selenium-java-example   File: TpForward.java   Source Code and License Vote up 4 votes
/**
     * main method
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        String execPath = System.getProperty("ExecPath");   // path to OpenFinRVM.exe
        String execArgs = System.getProperty("ExecArgs");   // command arguments for OpenFinRVM.exe, such as --config="app.json"
        String debuggerAddress = System.getProperty("DebuggerAddress");  // debugger URL for OpenFin Runtime.exe
        String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
        WebDriver driver;

        ChromeOptions options = new ChromeOptions();
        if (execPath != null) {
            System.out.println("Binary path " + execPath);
            options.setBinary(new File(execPath));
            options.addArguments(execArgs);
        }
        options.setExperimentalOption("debuggerAddress", debuggerAddress != null ? debuggerAddress : "localhost:9090");
        options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

        System.out.println("Creating remote driver " + remoteDriverURL);
        driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);

        System.out.println("Got the driver " + driver.getCurrentUrl());
        driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);

        try {
            if (switchWindow(driver, "Tullett Prebon - Electronic Broking")) {
                LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class);
                loginPage.login();
                sleep(3);

                DashboardPage dashBoardPage = PageFactory.initElements(driver, DashboardPage.class);
                dashBoardPage.goToFpForward();
            }
            if (switchWindow(driver, "tpForwardDeal-tile")) {
                TilePage tilePage = PageFactory.initElements(driver, TilePage.class);
                tilePage.startEdit();
                tilePage.updateTenor();
            }

//            executeJavascript(driver, "fin.desktop.System.exit();");  // ask OpenFin Runtime to exit
            sleep(2);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.quit();
        }

    }
 
Example 24
Project: hello-openfin-selenium-java-example   File: VoiceBoxTest.java   Source Code and License Vote up 4 votes
/**
 * main method
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    String execPath = System.getProperty("ExecPath");   // path to OpenFinRVM.exe
    String execArgs = System.getProperty("ExecArgs");   // command arguments for OpenFinRVM.exe, such as --config="app.json"
    String debuggerAddress = System.getProperty("DebuggerAddress");  // debugger URL for OpenFin Runtime.exe
    String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
    WebDriver driver = null;

    ChromeOptions options = new ChromeOptions();
    if (execPath != null) {
        System.out.println("Binary path " + execPath);
        options.setBinary(new File(execPath));
        options.addArguments(execArgs);
    }
    options.setExperimentalOption("debuggerAddress", debuggerAddress != null ? debuggerAddress : "localhost:9090");
    options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

    boolean keepRunning = true;
    int count = 0;

    while (keepRunning) {
        try {
            System.out.println("Creating remote driver " + remoteDriverURL);
            driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);
            System.out.println("Got the driver " + driver.getCurrentUrl());
            driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);

            List<String> list = new ArrayList<String>();
            list.add("https://test.web.tradervoicebox.com/login");
            list.add("https://test.web.tradervoicebox.com/dashboard");
            if (switchWindowByUrl(driver, list)) {
                sleep(1);
            }
            if (driver.getCurrentUrl().equals(list.get(0))) {
                LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class);
                loginPage.login();

                List<String> list2 = new ArrayList<String>();
                list2.add("https://test.web.tradervoicebox.com/dashboard");
                if (switchWindowByUrl(driver, list2)) {
                    sleep(1);
                }
            }

            DashBoardPage dashBoardPage = PageFactory.initElements(driver, DashBoardPage.class);
            dashBoardPage.toggleInviteScreen();
            dashBoardPage.logOff();

            executeJavascript(driver, "fin.desktop.System.exit();");  // ask OpenFin Runtime to exit
            sleep(2);

        } catch (Exception e) {
            keepRunning = false;
            e.printStackTrace();
        } finally {
            if (driver != null) {
                driver.quit();
                driver = null;
            }
        }
        count++;
        System.out.println(String.format("Finished loop %d", count));
        sleep(2);
    }
}
 
Example 25
Project: hello-openfin-selenium-java-example   File: SimpleTest.java   Source Code and License Vote up 4 votes
/**
 * main method
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    String execPath = System.getProperty("ExecPath");   // path to OpenFinRVM.exe
    String execArgs = System.getProperty("ExecArgs");   // command arguments for OpenFinRVM.exe, such as --config="app.json"
    String debuggerAddress = System.getProperty("DebuggerAddress");  // debugger URL for OpenFin Runtime.exe
    String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
    WebDriver driver;
    int etagSeq = 1;

    ChromeOptions options = new ChromeOptions();
    if (execPath != null) {
        System.out.println("Binary path " + execPath);
        options.setBinary(new File(execPath));
        options.addArguments(execArgs);
    }
    options.setExperimentalOption("debuggerAddress", debuggerAddress != null ? debuggerAddress : "localhost:9090");
    options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

    System.out.println("Creating remote driver " + remoteDriverURL);

    while (etagSeq < 20) {
        driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);
        System.out.println("Got the driver " + driver.getCurrentUrl());
        driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);
        try {
            if (switchWindow(driver, "ETAG check")) {  // select main window
                sleep(1);
            }
            WebElement body = driver.findElement(By.id("etagseq"));
            String tag = body.getText();
            if (Integer.parseInt(tag) != etagSeq) {
                System.out.println(String.format("Mismatch %d %s", etagSeq, tag));
                break;
            }
            System.out.printf(String.format("Run %d", etagSeq));
            executeJavascript(driver, "fin.desktop.System.exit();");  // ask OpenFin Runtime to exit
            sleep(5);
            etagSeq++;
        } catch (Exception e) {
            e.printStackTrace();
            break;
        } finally {
            driver.quit();
        }
    }
}
 
Example 26
Project: hello-openfin-selenium-java-example   File: AngularUISelectTest.java   Source Code and License Vote up 4 votes
/**
 * main method
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    String execPath = System.getProperty("ExecPath");   // path to OpenFinRVM.exe
    String execArgs = System.getProperty("ExecArgs");   // command arguments for OpenFinRVM.exe, such as --config="app.json"
    String debuggerAddress = System.getProperty("DebuggerAddress");  // debugger URL for OpenFin Runtime.exe
    String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
    WebDriver driver;

    ChromeOptions options = new ChromeOptions();
    if (execPath != null) {
        System.out.println("Binary path " + execPath);
        options.setBinary(new File(execPath));
        options.addArguments(execArgs);
    }
    options.setExperimentalOption("debuggerAddress", debuggerAddress != null ? debuggerAddress : "localhost:9090");
    options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

    System.out.println("Creating remote driver " + remoteDriverURL);
    driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);

    System.out.println("Got the driver " + driver.getCurrentUrl());
    driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);

    try {
        if (switchWindow(driver, "AngularJS ui-select")) {  // select main window
            sleep(1);
        }

        WebElement body = driver.findElement(By.tagName("body"));
        List<WebElement> list = body.findElements(By.cssSelector("div.ui-select-container"));
        for (WebElement container: list) {
            WebElement focusser = container.findElement(By.cssSelector(".ui-select-match"));
            focusser.click();
            WebElement input = container.findElement(By.cssSelector("input.ui-select-search"));
            input.clear();
            input.sendKeys("Adam");
            input.sendKeys(Keys.ENTER);
        }
        Thread.sleep(10000);  // sleep here so we can see it works
        executeJavascript(driver, "fin.desktop.System.exit();");  // ask OpenFin Runtime to exit
        sleep(2);

    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        driver.quit();
    }
}
 
Example 27
Project: hello-openfin-selenium-java-example   File: ChromeTest.java   Source Code and License Vote up 4 votes
public static void main(String[] args) throws Exception {
        String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
        WebDriver driver;

        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

        System.out.println("Creating remote driver " + remoteDriverURL);
        driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);

        System.out.println("Got the driver " + driver.getCurrentUrl());
        driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);

        try {
            driver.get("http://localhost:8080/examples/demo.html");
            Thread.sleep(2000);
            WebElement body = driver.findElement(By.tagName("body"));
            List<WebElement> list = body.findElements(By.cssSelector("div.ui-select-container"));
            System.out.println(String.format("populating input of %d elements", list.size()));
            for (WebElement container: list) {

                WebElement focusser = container.findElement(By.cssSelector("input.ui-select-focusser"));

                focusser.sendKeys("aa\n");

//                WebElement focusser = container.findElement(By.cssSelector(".ui-select-match"));

//                focusser.click();
                WebElement input = container.findElement(By.cssSelector("input.ui-select-search"));
                input.clear();
                input.sendKeys("aa");
                input.sendKeys(Keys.ENTER);
                Actions action = new Actions(driver);
                action.sendKeys(Keys.ARROW_DOWN);

            }
            Thread.sleep(5000);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.quit();
        }
    }
 
Example 28
Project: hello-openfin-selenium-java-example   File: TpForward.java   Source Code and License Vote up 4 votes
/**
     * main method
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        String execPath = System.getProperty("ExecPath");   // path to OpenFinRVM.exe
        String execArgs = System.getProperty("ExecArgs");   // command arguments for OpenFinRVM.exe, such as --config="app.json"
        String debuggerAddress = System.getProperty("DebuggerAddress");  // debugger URL for OpenFin Runtime.exe
        String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
        WebDriver driver;

        ChromeOptions options = new ChromeOptions();
        if (execPath != null) {
            System.out.println("Binary path " + execPath);
            options.setBinary(new File(execPath));
            options.addArguments(execArgs);
        }
        options.setExperimentalOption("debuggerAddress", debuggerAddress != null ? debuggerAddress : "localhost:9090");
        options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

        System.out.println("Creating remote driver " + remoteDriverURL);
        driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);

        System.out.println("Got the driver " + driver.getCurrentUrl());
        driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);

        try {
            if (switchWindow(driver, "Tullett Prebon - Electronic Broking")) {
                LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class);
                loginPage.login();
                sleep(3);

                DashboardPage dashBoardPage = PageFactory.initElements(driver, DashboardPage.class);
                dashBoardPage.goToFpForward();
            }
            if (switchWindow(driver, "tpForwardDeal-tile")) {
                TilePage tilePage = PageFactory.initElements(driver, TilePage.class);
                tilePage.startEdit();
                tilePage.updateTenor();
            }

//            executeJavascript(driver, "fin.desktop.System.exit();");  // ask OpenFin Runtime to exit
            sleep(2);

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            driver.quit();
        }

    }
 
Example 29
Project: hello-openfin-selenium-java-example   File: VoiceBoxTest.java   Source Code and License Vote up 4 votes
/**
 * main method
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    String execPath = System.getProperty("ExecPath");   // path to OpenFinRVM.exe
    String execArgs = System.getProperty("ExecArgs");   // command arguments for OpenFinRVM.exe, such as --config="app.json"
    String debuggerAddress = System.getProperty("DebuggerAddress");  // debugger URL for OpenFin Runtime.exe
    String remoteDriverURL = System.getProperty("RemoteDriverURL");  // URL to Selenium server or chromedriver
    WebDriver driver = null;

    ChromeOptions options = new ChromeOptions();
    if (execPath != null) {
        System.out.println("Binary path " + execPath);
        options.setBinary(new File(execPath));
        options.addArguments(execArgs);
    }
    options.setExperimentalOption("debuggerAddress", debuggerAddress != null ? debuggerAddress : "localhost:9090");
    options.setExperimentalOption("forceDevToolsScreenshot", Boolean.TRUE); // required for saving screenshot

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability(ChromeOptions.CAPABILITY,  options);

    boolean keepRunning = true;
    int count = 0;

    while (keepRunning) {
        try {
            System.out.println("Creating remote driver " + remoteDriverURL);
            driver = new RemoteWebDriver(new URL(remoteDriverURL), capabilities);
            System.out.println("Got the driver " + driver.getCurrentUrl());
            driver.manage().timeouts().setScriptTimeout(3, TimeUnit.SECONDS);

            List<String> list = new ArrayList<String>();
            list.add("https://test.web.tradervoicebox.com/login");
            list.add("https://test.web.tradervoicebox.com/dashboard");
            if (switchWindowByUrl(driver, list)) {
                sleep(1);
            }
            if (driver.getCurrentUrl().equals(list.get(0))) {
                LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class);
                loginPage.login();

                List<String> list2 = new ArrayList<String>();
                list2.add("https://test.web.tradervoicebox.com/dashboard");
                if (switchWindowByUrl(driver, list2)) {
                    sleep(1);
                }
            }

            DashBoardPage dashBoardPage = PageFactory.initElements(driver, DashBoardPage.class);
            dashBoardPage.toggleInviteScreen();
            dashBoardPage.logOff();

            executeJavascript(driver, "fin.desktop.System.exit();");  // ask OpenFin Runtime to exit
            sleep(2);

        } catch (Exception e) {
            keepRunning = false;
            e.printStackTrace();
        } finally {
            if (driver != null) {
                driver.quit();
                driver = null;
            }
        }
        count++;
        System.out.println(String.format("Finished loop %d", count));
        sleep(2);
    }
}