Example usage for org.openqa.selenium.chrome ChromeOptions ChromeOptions

List of usage examples for org.openqa.selenium.chrome ChromeOptions ChromeOptions

Introduction

In this page you can find the example usage for org.openqa.selenium.chrome ChromeOptions ChromeOptions.

Prototype

public ChromeOptions() 

Source Link

Usage

From source file:io.github.bonigarcia.wdm.test.StabilityTest.java

License:Apache License

@Test
public void test() throws InterruptedException {
    CountDownLatch latch = new CountDownLatch(NUM_THREADS);
    ExecutorService executorService = newFixedThreadPool(NUM_THREADS);

    for (int i = 0; i < NUM_THREADS; i++) {
        executorService.submit(() -> {
            try {
                WebDriverManager.chromedriver().setup();
                ChromeOptions options = new ChromeOptions();
                options.addArguments("--headless");
                WebDriver driver = new ChromeDriver(options);
                driver.get("https://bonigarcia.github.io/selenium-jupiter/");
                String title = driver.getTitle();
                System.out.println(title);
                driver.quit();//from  w ww . jav  a 2 s.co m
            } finally {
                latch.countDown();
            }
        });
    }

    latch.await();
    executorService.shutdown();
}

From source file:io.github.bonigarcia.wdm.test.WebRtcChromeTest.java

License:Apache License

@Before
public void setupTest() {
    ChromeOptions options = new ChromeOptions();

    // This flag avoids to grant the user media
    options.addArguments("--use-fake-ui-for-media-stream");

    // This flag fakes user media with synthetic video (green with spinner
    // and timer)
    options.addArguments("--use-fake-device-for-media-stream");

    driver = new ChromeDriver(options);
}

From source file:io.github.bonigarcia.wdm.test.WebRtcRemoteChromeTest.java

License:Apache License

@Before
public void setup() throws MalformedURLException {
    DesiredCapabilities capabilities = chrome();
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--use-fake-ui-for-media-stream");
    options.addArguments("--use-fake-device-for-media-stream");
    capabilities.setCapability(CAPABILITY, options);

    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
}

From source file:io.github.mike10004.vhs.testsupport.MakeFileUploadHar.java

License:Open Source License

private static WebDriver createWebDriver(int proxyPort) {
    ChromeOptions options = new ChromeOptions();
    options.addArguments("--proxy-server=localhost:" + proxyPort);
    ChromeDriverSetupRule.doSetup();//  w ww .  j a va 2 s .c o  m
    WebDriver driver = new ChromeDriver(options);
    return driver;
}

From source file:io.github.seleniumquery.browser.driver.builders.ChromeDriverBuilder.java

License:Apache License

private ChromeOptions getInitializedChromeOptions() {
    if (this.chromeOptions == null) {
        this.chromeOptions = new ChromeOptions();
    }// ww w . j av a  2 s.com
    return this.chromeOptions;
}

From source file:io.openvidu.test.browsers.ChromeAndroidUser.java

License:Apache License

public ChromeAndroidUser(String userName, int timeOfWaitInSeconds) {
    super(userName, timeOfWaitInSeconds);

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

    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.setExperimentalOption("mobileEmulation", mobileEmulation);

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setAcceptInsecureCerts(true);
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    // This flag avoids to grant the user media
    chromeOptions.addArguments("--use-fake-ui-for-media-stream");
    // This flag fakes user media with synthetic video
    chromeOptions.addArguments("--use-fake-device-for-media-stream");

    String REMOTE_URL = System.getProperty("REMOTE_URL_CHROME");
    if (REMOTE_URL != null) {
        log.info("Using URL {} to connect to remote web driver", REMOTE_URL);
        try {/* w w  w  . j  a  va2 s . co  m*/
            this.driver = new RemoteWebDriver(new URL(REMOTE_URL), capabilities);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
    } else {
        log.info("Using local web driver");
        this.driver = new ChromeDriver(capabilities);
    }

    this.driver.manage().timeouts().setScriptTimeout(this.timeOfWaitInSeconds, TimeUnit.SECONDS);
    this.configureDriver();
}

From source file:io.openvidu.test.browsers.ChromeUser.java

License:Apache License

private static ChromeOptions generateDefaultScreenChromeOptions(boolean runningAsRoot) {
    ChromeOptions options = new ChromeOptions();
    // This flag avoids to grant the user media
    options.addArguments("--use-fake-ui-for-media-stream");
    // This flag fakes user media with synthetic video
    options.addArguments("--use-fake-device-for-media-stream");
    // This flag selects the entire screen as video source when screen sharing
    options.addArguments("--auto-select-desktop-capture-source=Entire screen");

    if (runningAsRoot) {
        options.addArguments("--no-sandbox");
    }/* w w w .java  2 s  . c o m*/

    return options;
}

From source file:io.openvidu.test.browsers.ChromeUser.java

License:Apache License

private static ChromeOptions generateCustomScreenChromeOptions(String screenToCapture, boolean runningAsRoot,
        Path audioFileLocation) {
    ChromeOptions options = new ChromeOptions();
    // This flag selects the entire screen as video source when screen sharing
    options.addArguments("--auto-select-desktop-capture-source=" + screenToCapture);
    options.addArguments("--use-fake-device-for-media-stream");
    options.addArguments("--use-file-for-fake-audio-capture=" + audioFileLocation.toString());

    if (runningAsRoot) {
        options.addArguments("--no-sandbox");
    }//from  w  w w  . j a v a 2s.co m

    return options;
}

From source file:io.openvidu.test.browsers.ChromeUser.java

License:Apache License

private static ChromeOptions generateFakeVideoChromeOptions(Path videoFileLocation) {
    ChromeOptions options = new ChromeOptions();
    // This flag avoids to grant the user media
    options.addArguments("--use-fake-ui-for-media-stream");
    // This flag fakes user media with synthetic video
    options.addArguments("--use-fake-device-for-media-stream");
    // This flag sets the video input as
    options.addArguments("--use-file-for-fake-video-capture=" + videoFileLocation.toString());
    return options;
}

From source file:javax.portlet.tck.driver.TCKSimpleTestDriver.java

License:Apache License

/**
 * @throws java.lang.Exception//from w  ww. j a  v  a  2s  . c  om
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {

    loginUrl = System.getProperty("test.server.login.url");
    host = System.getProperty("test.server.host");
    port = System.getProperty("test.server.port");
    username = System.getProperty("test.server.username");
    usernameId = System.getProperty("test.server.username.id");
    password = System.getProperty("test.server.password");
    passwordId = System.getProperty("test.server.password.id");
    browser = System.getProperty("test.browser");
    testContextBase = System.getProperty("test.context.base");
    String str = System.getProperty("test.url.strategy");
    useGeneratedUrl = str.equalsIgnoreCase("generateURLs");
    str = System.getProperty("test.debug");
    debug = str.equalsIgnoreCase("true");
    str = System.getProperty("test.timeout");
    dryrun = new Boolean(System.getProperty("test.dryrun"));
    timeout = ((str != null) && str.matches("\\d+")) ? Integer.parseInt(str) : 3;
    String wd = System.getProperty("test.browser.webDriver");
    String binary = System.getProperty("test.browser.binary");
    boolean browserDefaultHeadless = browser.equalsIgnoreCase("chrome") || browser.equalsIgnoreCase("firefox")
            || browser.equalsIgnoreCase("htmlunit") || browser.equalsIgnoreCase("phantomjs");
    String headlessProperty = System.getProperty("test.browser.headless");
    boolean headless = (((headlessProperty == null) || (headlessProperty.length() == 0))
            && browserDefaultHeadless);

    System.out.println("before class.");
    System.out.println("   Debug        =" + debug);
    System.out.println("   Dryrun       =" + dryrun);
    System.out.println("   Timeout      =" + timeout);
    System.out.println("   Login URL    =" + loginUrl);
    System.out.println("   Host         =" + host);
    System.out.println("   Port         =" + port);
    System.out.println("   Context      =" + testContextBase);
    System.out.println("   Generate URL =" + useGeneratedUrl);
    System.out.println("   Username     =" + username);
    System.out.println("   UsernameId   =" + usernameId);
    System.out.println("   Password     =" + password);
    System.out.println("   PasswordId   =" + passwordId);
    System.out.println("   Browser      =" + browser);
    System.out.println("   Driver       =" + wd);
    System.out.println("   binary       =" + binary);
    System.out.println("   headless     =" + headless);

    if (browser.equalsIgnoreCase("firefox")) {

        System.setProperty("webdriver.gecko.driver", wd);
        FirefoxOptions options = new FirefoxOptions();
        options.setLegacy(true);
        options.setAcceptInsecureCerts(true);

        if ((binary != null) && (binary.length() != 0)) {
            options.setBinary(binary);
        }

        if (headless) {
            options.setHeadless(true);
        }

        driver = new FirefoxDriver(options);

    } else if (browser.equalsIgnoreCase("internetExplorer")) {
        System.setProperty("webdriver.ie.driver", wd);
        driver = new InternetExplorerDriver();
    } else if (browser.equalsIgnoreCase("chrome")) {

        System.setProperty("webdriver.chrome.driver", wd);
        ChromeOptions options = new ChromeOptions();

        if ((binary != null) && (binary.length() > 0)) {
            options.setBinary(binary);
        }

        if (headless) {
            options.addArguments("--headless");
        }

        options.addArguments("--disable-infobars");
        options.setAcceptInsecureCerts(true);

        driver = new ChromeDriver(options);

    } else if (browser.equalsIgnoreCase("phantomjs")) {
        DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
        capabilities.setJavascriptEnabled(true);
        capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, binary);
        driver = new PhantomJSDriver(capabilities);
    } else if (browser.equalsIgnoreCase("htmlUnit")) {
        driver = new HtmlUnitDriver(true);
    } else if (browser.equalsIgnoreCase("safari")) {
        driver = new SafariDriver();
    } else {
        throw new Exception("Unsupported browser: " + browser);
    }

    if (!dryrun) {
        login();
    }

}