Search in sources :

Example 31 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project syndesis-qe by syndesisio.

the class CustomWebDriverProvider method prepareChromeWebDriver.

/**
 * Method will prepare chrome driver with custom profile
 * @return
 */
private ChromeDriver prepareChromeWebDriver() {
    log.info("setting chrome profile");
    System.setProperty("webdriver.chrome.driver", findDriverPath());
    Map<String, Object> preferences = new Hashtable<String, Object>();
    preferences.put("profile.default_content_settings.popups", 0);
    preferences.put("download.prompt_for_download", "false");
    preferences.put("download.default_directory", DOWNLOAD_DIR);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", preferences);
    options.addArguments("start-maximized", "--no-sandbox");
    return new ChromeDriver(options);
}
Also used : Hashtable(java.util.Hashtable) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 32 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project hippo by NHS-digital-website.

the class WebDriverProvider method initialise.

/**
 * 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);
}
Also used : HashMap(java.util.HashMap) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions)

Example 33 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project jmeter-plugins by undera.

the class RemoteDesiredCapabilitiesFactory method build.

public static DesiredCapabilities build(RemoteCapability capability) {
    DesiredCapabilities desiredCapabilities;
    if (RemoteCapability.CHROME.equals(capability)) {
        ChromeOptions options = new ChromeOptions();
        desiredCapabilities = DesiredCapabilities.chrome();
        desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
        return desiredCapabilities;
    } else if (RemoteCapability.FIREFOX.equals(capability)) {
        FirefoxProfile profile = new FirefoxProfile();
        desiredCapabilities = DesiredCapabilities.firefox();
        desiredCapabilities.setCapability(FirefoxDriver.PROFILE, profile);
        return desiredCapabilities;
    } else if (RemoteCapability.INTERNET_EXPLORER.equals(capability)) {
        desiredCapabilities = DesiredCapabilities.internetExplorer();
        return desiredCapabilities;
    } else if (RemoteCapability.PHANTOMJS.equals(capability)) {
        desiredCapabilities = DesiredCapabilities.phantomjs();
        return desiredCapabilities;
    }
    throw new IllegalArgumentException("No such capability");
}
Also used : DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile)

Example 34 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project Bytecoder by mirkosertic.

the class BytecoderMavenMojo method wat2wasm.

private int[] wat2wasm(WASMCompileResult aResult) throws IOException {
    String theChromeDriverBinary = System.getenv("CHROMEDRIVER_BINARY");
    if (theChromeDriverBinary == null || theChromeDriverBinary.isEmpty()) {
        throw new RuntimeException("No chromedriver binary found! Please set CHROMEDRIVER_BINARY environment variable!");
    }
    ChromeDriverService.Builder theDriverServiceBuilder = new ChromeDriverService.Builder();
    theDriverServiceBuilder = theDriverServiceBuilder.withVerbose(false);
    theDriverServiceBuilder = theDriverServiceBuilder.usingDriverExecutable(new File(theChromeDriverBinary));
    ChromeDriverService theDriverService = theDriverServiceBuilder.build();
    theDriverService.start();
    File theTempDirectory = Files.createTempDir();
    File theGeneratedFile = new File(theTempDirectory, "compile.html");
    // Copy WABT Tools
    File theWABTFile = new File(theTempDirectory, "libwabt.js");
    try (FileOutputStream theOS = new FileOutputStream(theWABTFile)) {
        IOUtils.copy(getClass().getResourceAsStream("/libwabt.js"), theOS);
    }
    PrintWriter theWriter = new PrintWriter(theGeneratedFile);
    theWriter.println("<html>");
    theWriter.println("    <body>");
    theWriter.println("        <h1>Module code</h1>");
    theWriter.println("        <pre id=\"modulecode\">");
    theWriter.println(aResult.getData());
    theWriter.println("        </pre>");
    theWriter.println("        <h1>Compilation result</h1>");
    theWriter.println("        <pre id=\"compileresult\">");
    theWriter.println("        </pre>");
    theWriter.println("        <script src=\"libwabt.js\">");
    theWriter.println("        </script>");
    theWriter.println("        <script>");
    theWriter.println("            function compile() {");
    theWriter.println("                console.log('Compilation started');");
    theWriter.println("                try {");
    theWriter.println("                    var module = wabt.parseWat('test.wast', document.getElementById(\"modulecode\").innerText);");
    theWriter.println("                    module.resolveNames();");
    theWriter.println("                    module.validate();");
    theWriter.println("                    var binaryOutput = module.toBinary({log: true, write_debug_names:true});");
    theWriter.println("                    document.getElementById(\"compileresult\").innerText = binaryOutput.log;");
    theWriter.println("                    return binaryOutput.buffer;");
    theWriter.println("                } catch (e) {");
    theWriter.println("                    document.getElementById(\"compileresult\").innerText = e.toString();");
    theWriter.println("                    console.log(e.toString());");
    theWriter.println("                    console.log(e.stack);");
    theWriter.println("                }");
    theWriter.println("            }");
    theWriter.println("        </script>");
    theWriter.println("    </body>");
    theWriter.println("</html>");
    theWriter.flush();
    theWriter.close();
    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);
    RemoteWebDriver theDriver = new RemoteWebDriver(theDriverService.getUrl(), theCapabilities);
    theDriver.get(theGeneratedFile.toURI().toURL().toString());
    ArrayList<Long> theResult = (ArrayList<Long>) theDriver.executeScript("return compile();");
    int[] theBinaryDara = new int[theResult.size()];
    for (int i = 0; i < theResult.size(); i++) {
        long theLongValue = theResult.get(i);
        theBinaryDara[i] = (int) (theLongValue);
    }
    List<LogEntry> theAll = theDriver.manage().logs().get(LogType.BROWSER).getAll();
    for (LogEntry theEntry : theAll) {
        System.out.println(theEntry.getMessage());
    }
    theDriver.close();
    theDriverService.stop();
    return theBinaryDara;
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) LoggingPreferences(org.openqa.selenium.logging.LoggingPreferences) ChromeDriverService(org.openqa.selenium.chrome.ChromeDriverService) FileOutputStream(java.io.FileOutputStream) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) SourceFile(com.google.javascript.jscomp.SourceFile) File(java.io.File) LogEntry(org.openqa.selenium.logging.LogEntry) PrintWriter(java.io.PrintWriter)

Example 35 with ChromeOptions

use of org.openqa.selenium.chrome.ChromeOptions in project carina by qaprosoft.

the class ChromeCapabilities method getCapability.

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;
}
Also used : HashMap(java.util.HashMap) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions)

Aggregations

ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)50 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)39 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)28 File (java.io.File)20 HashMap (java.util.HashMap)19 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)16 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)10 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)8 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)8 WebDriver (org.openqa.selenium.WebDriver)7 Actions (org.openqa.selenium.interactions.Actions)7 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)6 URL (java.net.URL)5 WebDriverException (org.openqa.selenium.WebDriverException)5 LoggingPreferences (org.openqa.selenium.logging.LoggingPreferences)5 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)5 ArrayList (java.util.ArrayList)4 BeforeClass (org.junit.BeforeClass)4 TakesScreenshot (org.openqa.selenium.TakesScreenshot)4 ChromeDriverService (org.openqa.selenium.chrome.ChromeDriverService)4