Search in sources :

Example 6 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project ats-framework by Axway.

the class RealHtmlFileBrowse method setValueUsingNativeDialog.

/**
     * This method allows you to type in dialog windows. This option is available only for Windows OS
     *
     * @param path add the location of the file, you want to type in the dialog window
     * @throws Exception
     */
@PublicAtsApi
public void setValueUsingNativeDialog(String path) throws Exception {
    if (!OperatingSystemType.getCurrentOsType().isWindows()) {
        throw new RuntimeException("This method is only available for Windows machines!");
    }
    // check if the file exist
    if (!new File(path).exists()) {
        throw new FileNotFoundException("File path \"" + path + "\" is wrong or does not exist!");
    }
    // ats_file_upload.exe location
    String uploadFileDestination = System.getProperty("user.dir") + "\\ats_file_upload.exe";
    // native window name
    String windowName;
    log.info("Using native " + path + " to work with native browser dialogs");
    // check if the ats_file_upload.exe file is already created
    if (!new File(uploadFileDestination).exists()) {
        OutputStream os = null;
        InputStream is = null;
        try {
            // get the ats_file_upload.exe file, located in the ats-uiengine.jar
            is = getClass().getClassLoader().getResourceAsStream("binaries/ats_file_upload.exe");
            if (is == null) {
                throw new FileNotFoundException("The 'ats_file_upload.exe' file is not found in ats-uiengine.jar!");
            }
            File uploadFile = new File(uploadFileDestination);
            os = new FileOutputStream(uploadFile);
            IOUtils.copy(is, os);
        } finally {
            IoUtils.closeStream(is);
            IoUtils.closeStream(os);
        }
    }
    if (webDriver instanceof FirefoxDriver) {
        windowName = " \"File Upload\" ";
    } else if (webDriver instanceof ChromeDriver) {
        windowName = " \"Open\" ";
    } else {
        throw new RobotException("Not Implemented for your browser! Currently Firefox and " + "Chrome are supported.");
    }
    // add the browse button properties
    ((AbstractRealBrowserDriver) super.getUiDriver()).getHtmlEngine().getElement(properties).click();
    // run the ats_file_upload.exe file
    IProcessExecutor proc = new LocalProcessExecutor(HostUtils.LOCAL_HOST_IPv4, uploadFileDestination + windowName + path);
    proc.execute();
    // check if there is any error, while executing the ats_file_upload.exe file
    if (proc.getExitCode() != 0) {
        log.error("AutoIT process for native browser interaction failed with exit code: " + proc.getExitCode() + ";");
        log.error("Output stream data: " + proc.getStandardOutput() + ";");
        log.error("Error stream data: " + proc.getErrorOutput());
        throw new RobotException("AutoIT process for native browser interaction failed.");
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) RobotException(com.axway.ats.uiengine.exceptions.RobotException) AbstractRealBrowserDriver(com.axway.ats.uiengine.AbstractRealBrowserDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FileOutputStream(java.io.FileOutputStream) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) LocalProcessExecutor(com.axway.ats.core.process.LocalProcessExecutor) File(java.io.File) IProcessExecutor(com.axway.ats.core.process.model.IProcessExecutor) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 7 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project zeppelin by apache.

the class WebDriverManager method getWebDriver.

public static WebDriver getWebDriver() {
    WebDriver driver = null;
    if (driver == null) {
        try {
            FirefoxBinary ffox = new FirefoxBinary();
            if ("true".equals(System.getenv("TRAVIS"))) {
                // xvfb is supposed to
                ffox.setEnvironmentProperty("DISPLAY", ":99");
            // run with DISPLAY 99
            }
            int firefoxVersion = WebDriverManager.getFirefoxVersion();
            LOG.info("Firefox version " + firefoxVersion + " detected");
            downLoadsDir = FileUtils.getTempDirectory().toString();
            String tempPath = downLoadsDir + "/firebug/";
            downloadFireBug(firefoxVersion, tempPath);
            final String firebugPath = tempPath + "firebug.xpi";
            final String firepathPath = tempPath + "firepath.xpi";
            FirefoxProfile profile = new FirefoxProfile();
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.dir", downLoadsDir);
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.download.manager.showAlertOnComplete", false);
            profile.setPreference("browser.download.manager.closeWhenDone", true);
            profile.setPreference("app.update.auto", false);
            profile.setPreference("app.update.enabled", false);
            profile.setPreference("dom.max_script_run_time", 0);
            profile.setPreference("dom.max_chrome_script_run_time", 0);
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/x-ustar,application/octet-stream,application/zip,text/csv,text/plain");
            profile.setPreference("network.proxy.type", 0);
            profile.addExtension(new File(firebugPath));
            profile.addExtension(new File(firepathPath));
            driver = new FirefoxDriver(ffox, profile);
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while FireFox Driver ", e);
        }
    }
    if (driver == null) {
        try {
            driver = new ChromeDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while ChromeDriver ", e);
        }
    }
    if (driver == null) {
        try {
            driver = new SafariDriver();
        } catch (Exception e) {
            LOG.error("Exception in WebDriverManager while SafariDriver ", e);
        }
    }
    String url;
    if (System.getenv("url") != null) {
        url = System.getenv("url");
    } else {
        url = "http://localhost:8080";
    }
    long start = System.currentTimeMillis();
    boolean loaded = false;
    driver.manage().timeouts().implicitlyWait(AbstractZeppelinIT.MAX_IMPLICIT_WAIT, TimeUnit.SECONDS);
    driver.get(url);
    while (System.currentTimeMillis() - start < 60 * 1000) {
        // wait for page load
        try {
            (new WebDriverWait(driver, 30)).until(new ExpectedCondition<Boolean>() {

                @Override
                public Boolean apply(WebDriver d) {
                    return d.findElement(By.xpath("//i[@tooltip='WebSocket Connected']")).isDisplayed();
                }
            });
            loaded = true;
            break;
        } catch (TimeoutException e) {
            LOG.info("Exception in WebDriverManager while WebDriverWait ", e);
            driver.navigate().to(url);
        }
    }
    if (loaded == false) {
        fail();
    }
    return driver;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) IOException(java.io.IOException) TimeoutException(org.openqa.selenium.TimeoutException) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) TimeoutException(org.openqa.selenium.TimeoutException)

Example 8 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project webmagic by code4craft.

the class WebDriverPool method configure.

/**
	 * Configure the GhostDriver, and initialize a WebDriver instance. This part
	 * of code comes from GhostDriver.
	 * https://github.com/detro/ghostdriver/tree/master/test/java/src/test/java/ghostdriver
	 * 
	 * @author bob.li.0718@gmail.com
	 * @throws IOException
	 */
public void configure() throws IOException {
    // Read config file
    sConfig = new Properties();
    String configFile = DEFAULT_CONFIG_FILE;
    if (System.getProperty("selenuim_config") != null) {
        configFile = System.getProperty("selenuim_config");
    }
    sConfig.load(new FileReader(configFile));
    // Prepare capabilities
    sCaps = new DesiredCapabilities();
    sCaps.setJavascriptEnabled(true);
    sCaps.setCapability("takesScreenshot", false);
    String driver = sConfig.getProperty("driver", DRIVER_PHANTOMJS);
    // Fetch PhantomJS-specific configuration parameters
    if (driver.equals(DRIVER_PHANTOMJS)) {
        // "phantomjs_exec_path"
        if (sConfig.getProperty("phantomjs_exec_path") != null) {
            sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, sConfig.getProperty("phantomjs_exec_path"));
        } else {
            throw new IOException(String.format("Property '%s' not set!", PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY));
        }
        // "phantomjs_driver_path"
        if (sConfig.getProperty("phantomjs_driver_path") != null) {
            System.out.println("Test will use an external GhostDriver");
            sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_PATH_PROPERTY, sConfig.getProperty("phantomjs_driver_path"));
        } else {
            System.out.println("Test will use PhantomJS internal GhostDriver");
        }
    }
    // Disable "web-security", enable all possible "ssl-protocols" and
    // "ignore-ssl-errors" for PhantomJSDriver
    // sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new
    // String[] {
    // "--web-security=false",
    // "--ssl-protocol=any",
    // "--ignore-ssl-errors=true"
    // });
    ArrayList<String> cliArgsCap = new ArrayList<String>();
    cliArgsCap.add("--web-security=false");
    cliArgsCap.add("--ssl-protocol=any");
    cliArgsCap.add("--ignore-ssl-errors=true");
    sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
    // Control LogLevel for GhostDriver, via CLI arguments
    sCaps.setCapability(PhantomJSDriverService.PHANTOMJS_GHOSTDRIVER_CLI_ARGS, new String[] { "--logLevel=" + (sConfig.getProperty("phantomjs_driver_loglevel") != null ? sConfig.getProperty("phantomjs_driver_loglevel") : "INFO") });
    // Start appropriate Driver
    if (isUrl(driver)) {
        sCaps.setBrowserName("phantomjs");
        mDriver = new RemoteWebDriver(new URL(driver), sCaps);
    } else if (driver.equals(DRIVER_FIREFOX)) {
        mDriver = new FirefoxDriver(sCaps);
    } else if (driver.equals(DRIVER_CHROME)) {
        mDriver = new ChromeDriver(sCaps);
    } else if (driver.equals(DRIVER_PHANTOMJS)) {
        mDriver = new PhantomJSDriver(sCaps);
    }
}
Also used : PhantomJSDriver(org.openqa.selenium.phantomjs.PhantomJSDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) IOException(java.io.IOException) Properties(java.util.Properties) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) URL(java.net.URL)

Example 9 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project antlr4 by antlr.

the class SharedWebDriver method init.

public static WebDriver init() {
    if (driver == null) {
        String path = SharedWebDriver.class.getPackage().getName().replace(".", "/") + "/chromedriver.bin";
        URL url = Thread.currentThread().getContextClassLoader().getResource(path);
        // skip 'file:'
        File file = new File(url.toExternalForm().substring(5));
        assertTrue(file.exists());
        System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
        driver = new ChromeDriver();
    } else if (timer != null) {
        timer.cancel();
        timer = null;
    }
    return driver;
}
Also used : ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File) URL(java.net.URL)

Example 10 with ChromeDriver

use of org.openqa.selenium.chrome.ChromeDriver in project java.webdriver by sayems.

the class Click method main.

public static void main(String[] args) {
    WebDriver driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.navigate().to("http://www.google.com");
    JavascriptExecutor jse = (JavascriptExecutor) driver;
    driver.findElement(By.id("gbqfq")).sendKeys("Selenium");
    jse.executeScript("document.getElementById('gbqfba').click();");
}
Also used : WebDriver(org.openqa.selenium.WebDriver) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver)

Aggregations

ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)13 WebDriver (org.openqa.selenium.WebDriver)7 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)4 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)4 File (java.io.File)3 URL (java.net.URL)3 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)3 IOException (java.io.IOException)2 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)2 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)2 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 LocalProcessExecutor (com.axway.ats.core.process.LocalProcessExecutor)1 IProcessExecutor (com.axway.ats.core.process.model.IProcessExecutor)1 AbstractRealBrowserDriver (com.axway.ats.uiengine.AbstractRealBrowserDriver)1 RobotException (com.axway.ats.uiengine.exceptions.RobotException)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1