Search in sources :

Example 61 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver 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 62 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project xwiki-platform by xwiki.

the class WebDriverFactory method createWebDriver.

public XWikiWebDriver createWebDriver(String browserName) {
    WebDriver driver;
    if (browserName.startsWith("*firefox")) {
        // Native events are disabled by default for Firefox on Linux as it may cause tests which open many windows
        // in parallel to be unreliable. However, native events work quite well otherwise and are essential for some
        // of the new actions of the Advanced User Interaction. We need native events to be enable especially for
        // testing the WYSIWYG editor. See http://code.google.com/p/selenium/issues/detail?id=2331 .
        FirefoxProfile profile = new FirefoxProfile();
        profile.setEnableNativeEvents(true);
        // Make sure Firefox doesn't upgrade automatically on CI agents.
        profile.setPreference("app.update.auto", false);
        profile.setPreference("app.update.enabled", false);
        profile.setPreference("app.update.silent", false);
        driver = new FirefoxDriver(profile);
        // Hide the Add-on bar (from the bottom of the window, with "WebDriver" written on the right) because it can
        // prevent buttons or links from being clicked when they are beneath it and native events are used.
        // See https://groups.google.com/forum/#!msg/selenium-users/gBozOynEjs8/XDxxQNmUSCsJ
        // We need to load a page before sending the keys otherwise WebDriver throws ElementNotVisible exception.
        driver.get("data:text/plain;charset=utf-8,XWiki");
        driver.switchTo().activeElement().sendKeys(Keys.chord(Keys.CONTROL, "/"));
    } else if (browserName.startsWith("*iexplore")) {
        driver = new InternetExplorerDriver();
    } else if (browserName.startsWith("*chrome")) {
        driver = new ChromeDriver();
    } else if (browserName.startsWith("*phantomjs")) {
        DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
        capabilities.setCapability("handlesAlerts", true);
        try {
            driver = new PhantomJSDriver(ResolvingPhantomJSDriverService.createDefaultService(), capabilities);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        throw new RuntimeException("Unsupported browser name [" + browserName + "]");
    }
    // Maximize the browser window by default so that the page has a standard layout. Individual tests can resize
    // the browser window if they want to test how the page layout adapts to limited space. This reduces the
    // probability of a test failure caused by an unexpected layout (nested scroll bars, floating menu over links
    // and buttons and so on).
    driver.manage().window().maximize();
    return new XWikiWebDriver((RemoteWebDriver) driver);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) IOException(java.io.IOException) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Example 63 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project carina by qaprosoft.

the class DesktopFactory method create.

@Override
public WebDriver create(String name, Device device, DesiredCapabilities capabilities, String seleniumHost) {
    RemoteWebDriver driver = null;
    if (seleniumHost == null) {
        seleniumHost = Configuration.get(Configuration.Parameter.SELENIUM_HOST);
    }
    if (isCapabilitiesEmpty(capabilities)) {
        capabilities = getCapabilities(name);
    }
    if (staticCapabilities != null) {
        LOGGER.info("Static DesiredCapabilities will be merged to basic driver capabilities");
        capabilities.merge(staticCapabilities);
    }
    try {
        driver = new RemoteWebDriver(new URL(seleniumHost), capabilities);
    } catch (UnreachableBrowserException e) {
        // try to restart selenium hub
        restartAll(PREFIX_WIN, RESTART_ALL_BAT_PATH);
        restartAll(PREFIX_NIX, RESTART_ALL_SH_PATH);
        throw e;
    } catch (MalformedURLException e) {
        throw new RuntimeException("Unable to create desktop driver");
    }
    return driver;
}
Also used : MalformedURLException(java.net.MalformedURLException) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) URL(java.net.URL)

Example 64 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project activityinfo by bedatadriven.

the class WebDriverSession method getSessionId.

public SessionId getSessionId() {
    Preconditions.checkState(driver != null, "WebDriver is not started");
    RemoteWebDriver remoteWebDriver = (RemoteWebDriver) driver;
    return remoteWebDriver.getSessionId();
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver)

Example 65 with RemoteWebDriver

use of org.openqa.selenium.remote.RemoteWebDriver in project testcontainers-java by testcontainers.

the class LinkedContainerTest method testWebDriverToNginxContainerAccessViaContainerLink.

@Test
public void testWebDriverToNginxContainerAccessViaContainerLink() throws Exception {
    RemoteWebDriver driver = chrome.getWebDriver();
    driver.get("http://nginx/");
    assertEquals("Using selenium, an HTTP GET from the nginx server returns the index.html from the custom content directory", "This worked", driver.findElement(By.tagName("body")).getText());
}
Also used : RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) Test(org.junit.Test)

Aggregations

RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)101 URL (java.net.URL)39 Test (org.junit.Test)36 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)29 File (java.io.File)16 WebDriver (org.openqa.selenium.WebDriver)14 MalformedURLException (java.net.MalformedURLException)13 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)13 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)12 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)12 IOException (java.io.IOException)11 Dimension (org.openqa.selenium.Dimension)9 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)7 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 FirefoxProfile (org.openqa.selenium.firefox.FirefoxProfile)6 EventFiringWebDriver (org.openqa.selenium.support.events.EventFiringWebDriver)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5