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

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

Introduction

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

Prototype

public ChromeDriver() 

Source Link

Document

Creates a new ChromeDriver using the ChromeDriverService#createDefaultService default server configuration.

Usage

From source file:backend.BackendLoginTest.java

@BeforeSuite(alwaysRun = true)
public void setupBeforeSuite(ITestContext context) {
    driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    login.setDriver(driver);//  w w  w.  j  ava2  s  .  c om
}

From source file:Basic.NewTest.java

@BeforeTest
public void beforeTest() {
    System.setProperty("webdriver.gecko.driver", "/Users/abhinav.agrawal/Downloads/geckodriver");
    System.setProperty("webdriver.chrome.driver",
            "/Users/abhinav.agrawal/Downloads/OlaCorporateAutomation/OlaCorporate/config/chromedriver");
    driver = new ChromeDriver();
}

From source file:browsermator.com.RunASingleTest.java

public void RunSingleTest(Procedure bugtorun, ProcedureView thisbugview, String TargetBrowser, String OSType) {

    SiteTest.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

    switch (TargetBrowser) {
    // legacy file support
    case "Firefox-Marionette":
        // legacy file support
        if ("Windows".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe");
        }//from www .ja  v a2 s .co  m
        if ("Windows32".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe");
        }
        if ("Windows64".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win64\\geckodriver.exe");
        }
        if ("Mac".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-osx\\geckodriver");
        }
        if ("Linux-32".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux32\\geckodriver");
        }
        if ("Linux-64".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux64\\geckodriver");
        }

        if (firefox_path != null) {
            System.setProperty("webdriver.firefox.bin", firefox_path);
        }

        try {
            DesiredCapabilities cap = DesiredCapabilities.firefox();
            cap.setJavascriptEnabled(true);
            cap.setCapability("marionette", true);
            driver = new FirefoxDriver(cap);

            //  driver =  new MarionetteDriver();
        } catch (Exception ex) {
            System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: "
                    + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Marionette driver, will fallback to HTMLUnitDriver", false);

            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }

        break;

    case "Firefox":
        //legacy support
        if ("Windows".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe");
        }
        if ("Windows32".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win32\\geckodriver.exe");
        }
        if ("Windows64".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-win64\\geckodriver.exe");
        }
        if ("Mac".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-osx\\geckodriver");
        }
        if ("Linux-32".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux32\\geckodriver");
        }
        if ("Linux-64".equals(OSType)) {
            System.setProperty("webdriver.gecko.driver", "lib\\geckodriver-0.11.1-linux64\\geckodriver");
        }

        if (firefox_path != null) {
            System.setProperty("webdriver.firefox.bin", firefox_path);
        }

        try {
            DesiredCapabilities cap = DesiredCapabilities.firefox();
            cap.setJavascriptEnabled(true);
            cap.setCapability("marionette", true);
            driver = new FirefoxDriver(cap);

            //  driver =  new MarionetteDriver();
        } catch (Exception ex) {
            System.out.println("Exception launching Marionette driver... possibly XP or missing msvcr110.dll: "
                    + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Marionette driver, will fallback to HTMLUnitDriver", false);

            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }

        break;

    case "Silent Mode (HTMLUnit)":
        driver = new HtmlUnitDriver();
        break;

    case "Internet Explorer-32":
        System.setProperty("webdriver.ie.driver", "lib\\iedriverserver_win32\\IEDriverServer.exe");
        try {
            driver = new InternetExplorerDriver();
        } catch (Exception ex) {
            System.out.println("Exception launching Internet Explorer driver: " + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Internet Explorer driver, will fallback to HTMLUnitDriver", false);
            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }
        break;
    case "Internet Explorer-64":
        System.setProperty("webdriver.ie.driver", "lib\\iedriverserver_win64\\IEDriverServer.exe");
        try {
            driver = new InternetExplorerDriver();
        } catch (Exception ex) {
            System.out.println("Exception launching Internet Explorer-64 driver: " + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Internet Explorer 64 driver, will fallback to HTMLUnitDriver",
                    false);
            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }
        break;
    case "Chrome":
        if ("Windows32".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver.exe");
        }
        if ("Windows64".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver.exe");
        }
        if ("Mac".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_mac64\\chromedriver");
        }
        if ("Linux-32".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_linux32\\chromedriver-linux32");
        }
        if ("Linux-64".equals(OSType)) {
            System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_linux64\\chromedriver-linux64");
        }
        try {
            driver = new ChromeDriver();
        } catch (Exception ex) {
            System.out.println("Problem launching Chromedriver: " + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Chrome driver, will fallback to HTMLUnitDriver", false);
            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }
        break;
    case "Chrome (WinXP)":
        if (chrome_path != null) {
            System.setProperty("webdriver.chrome.bin", chrome_path);
        }
        System.setProperty("webdriver.chrome.driver", "lib\\chromedriver_win32\\chromedriver-winxp.exe");

        try {
            driver = new ChromeDriver();
        } catch (Exception ex) {
            System.out.println("Problem launching Chromedriver for XP: " + ex.toString());
            Prompter fallbackprompt = new Prompter(
                    "We could not launch the Chrome WinXP driver, will fallback to HTMLUnitDriver", false);
            SiteTest.setTargetBrowser("Silent Mode (HTMLUnit)");
        }
        break;

    default:
        driver = new ChromeDriver();
        break;
    }

    int WaitTime = SiteTest.GetWaitTime();
    // driver.manage().timeouts().implicitlyWait(WaitTime, TimeUnit.SECONDS);
    int totalpause = WaitTime * 1000;

    if (!"Dataloop".equals(thisbugview.Type)) {
        for (Action ThisAction : bugtorun.ActionsList) {

            if (!ThisAction.Locked) {
                try {
                    try {
                        Thread.sleep(totalpause);
                    } catch (Exception ex) {
                        System.out.println("Exception when sleeping: " + ex.toString());
                    }
                    String varfieldname = "";
                    if (ThisAction.Variable2.contains("[stored_varname-start]")) {
                        varfieldname = ThisAction.Variable2;
                        int indexof_end_tag = varfieldname.indexOf("[stored_varname-end]");
                        // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                        String fieldname = varfieldname.substring(22, indexof_end_tag);
                        ThisAction.Variable2 = SiteTest.GetStoredVariableValue(fieldname);
                        ThisAction.RunAction(driver);
                        ThisAction.Variable2 = "[stored_varname-start]" + fieldname + "[stored_varname-end]";
                    } else {
                        ThisAction.RunAction(driver);
                    }

                    if (!"".equals(ThisAction.tostore_varvalue)) {

                        SiteTest.VarHashMap.put(ThisAction.tostore_varname, ThisAction.tostore_varvalue);
                    }

                } catch (Exception ex) {
                    SiteTest.setCursor(Cursor.getDefaultCursor());
                    driver.close();
                    driver.quit();
                    break;

                }
            } else {
                ThisAction.Pass = true;
            }
        }

    } else {
        int number_of_rows = thisbugview.myTable.DataTable.getRowCount();

        for (int x = 0; x < number_of_rows; x++) {
            for (Action ThisAction : bugtorun.ActionsList) {
                String original_value1 = ThisAction.Variable1;
                String original_value2 = ThisAction.Variable2;
                if (!ThisAction.Locked) {

                    DataLoopVarParser var1Parser = new DataLoopVarParser(ThisAction.Variable1);
                    DataLoopVarParser var2Parser = new DataLoopVarParser(ThisAction.Variable2);
                    if (var1Parser.hasDataLoopVar == false && var2Parser.hasDataLoopVar == false) {
                        if ("Pause with Continue Button".equals(ThisAction.Type)) {
                            String pause_message = "Paused at record " + (x + 1) + " of " + number_of_rows;
                            ThisAction.RunAction(driver, pause_message, this.SiteTest);
                        }
                        try {
                            Thread.sleep(totalpause);
                        } catch (Exception ex) {
                            System.out.println("Exception when sleeping: " + ex.toString());
                        }
                        try {
                            String varfieldname = "";
                            if (ThisAction.Variable2.contains("[stored_varname-start]")) {
                                varfieldname = ThisAction.Variable2;
                                int indexof_end_tag = varfieldname.indexOf("[stored_varname-end]");
                                // assuming name of "[stored_varname-start]" and "[stored_varname-end]"
                                String fieldname = varfieldname.substring(22, indexof_end_tag);
                                ThisAction.Variable2 = SiteTest.GetStoredVariableValue(fieldname);
                                ThisAction.RunAction(driver);
                                ThisAction.Variable2 = "[stored_varname-start]" + fieldname
                                        + "[stored_varname-end]";
                            } else {
                                ThisAction.RunAction(driver);
                            }

                            if (!"".equals(ThisAction.tostore_varvalue)) {

                                SiteTest.VarHashMap.put(ThisAction.tostore_varname,
                                        ThisAction.tostore_varvalue);
                            }

                        } catch (Exception ex) {
                            driver.close();
                            driver.quit();
                            ThisAction.Variable1 = original_value1;
                            ThisAction.Variable2 = original_value2;
                            SiteTest.setCursor(Cursor.getDefaultCursor());
                            break;

                        }

                    } else {

                        String concat_variable;
                        String concat_variable2;
                        concat_variable = var1Parser.GetFullValue(x, thisbugview.myTable);
                        if (var1Parser.hasDataLoopVar) {
                            ThisAction.Variable1 = concat_variable;
                            if ("".equals(ThisAction.Variable1)) {
                                ThisAction.Variable1 = " ";
                            }
                        }

                        concat_variable2 = var2Parser.GetFullValue(x, thisbugview.myTable);
                        if (var2Parser.hasDataLoopVar) {
                            ThisAction.Variable2 = concat_variable2;
                            if ("".equals(ThisAction.Variable2)) {
                                ThisAction.Variable2 = " ";
                            }
                        }
                        try {
                            try {
                                Thread.sleep(totalpause);
                            } catch (Exception ex) {
                                System.out.println("Exception when sleeping: " + ex.toString());
                            }
                            ThisAction.RunAction(driver);
                            ThisAction.Variable1 = original_value1;
                            ThisAction.Variable2 = original_value2;

                        } catch (Exception ex) {

                            ThisAction.Variable1 = original_value1;
                            ThisAction.Variable2 = original_value2;
                            driver.close();
                            driver.quit();
                            SiteTest.setCursor(Cursor.getDefaultCursor());
                            break;

                        }

                    }

                } else {
                    ThisAction.Pass = true;
                }
            }
        }
    }
    driver.close();
    driver.quit();
    ArrayList<ActionView> ActionView = thisbugview.ActionsViewList;

    int ActionIndex = 0;

    for (ActionView TheseActionViews : ActionView) {

        LocalDateTime stringtime = bugtorun.ActionsList.get(ActionIndex).TimeOfTest;
        boolean TestState = bugtorun.ActionsList.get(ActionIndex).Pass;
        if (TestState == true) {
            thisbugview.ActionsViewList.get(ActionIndex).JLabelPassFail.setText("Passed at " + stringtime);

        } else {
            thisbugview.ActionsViewList.get(ActionIndex).JLabelPassFail.setText("Fail at " + stringtime);

        }

        ActionIndex++;

    }

}

From source file:ca.pe.cjsigouin.testinator.controller.scene.preferences.GeneralController.java

@FXML
private void handleBtnSelectDriver(ActionEvent event) {
    configureFileChooser(fileChooser);// www . ja v a2  s  .co m
    File file = fileChooser.showOpenDialog(SceneManager.getStage());
    if (file != null) {
        lblDriverPath.setText(file.getAbsolutePath());
        SeleniumManager.loadDriver(SeleniumConfig.DRIVER_CHROME, file.getAbsolutePath());
    }

    SeleniumManager.setDriver(new ChromeDriver());
}

From source file:ca.pe.cjsigouin.testinator.manager.SeleniumManager.java

@Override
public void run() {
    driver = new ChromeDriver();

    //Puts an Implicit wait, Will wait for 10 seconds before throwing exception
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //Launch website
    driver.navigate().to("http://www.google.ca");
    log.info("Thread should be terminated now");
}

From source file:ca.pe.cjsigouin.testinator.selenium.SeleniumDriverChrome.java

@Override
public void run() {
    SeleniumManager.setDriver(new ChromeDriver());
    handler.execute(test);
    SeleniumManager.getDriver().close();
}

From source file:ca.pe.cjsigouin.testinator.selenium.WebDriverMain.java

public static void main(String[] args) {

    System.setProperty("webdriver.gecko.driver", "/home/krystofurr/Programs/selenium/geckodriver");
    System.setProperty("webdriver.chrome.driver", "/home/krystofurr/Programs/selenium/chromedriver");

    //     WebDriver driver = new FirefoxDriver();
    WebDriver driver = new ChromeDriver();
    //     WebDriver driver = new InternetExplorerDriver();

    //Puts an Implicit wait, Will wait for 10 seconds before throwing exception
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //Launch website
    driver.navigate().to(CommonConstants.HOST + CommonConstants.URL_LOGIN);

    driver.findElement(By.id("emailAddress")).sendKeys("cjsigouin@gov.pe.ca");
    driver.findElement(By.id("password")).sendKeys("Test12345!");
    driver.findElement(By.id("loginButton")).click();

    WebDriverWait wait = new WebDriverWait(driver, 5);
    wait.until(/* www  . j  av a2s .  c  o  m*/
            ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='serviceWellSection']/div[2]/div/a/b")));

    driver.get(CommonConstants.HOST + CommonConstants.URL_RESERVE_NAME_INTRO);
    WebDriverWait wait2 = new WebDriverWait(driver, 5);

    wait2.until(ExpectedConditions.elementToBeClickable(By.xpath(ReserveNameElement.INTRO_BUTTON_CANCEL)));
    driver.findElement(By.xpath(ReserveNameElement.INTRO_RADIO_RESERVE_NAME)).click();
    //     driver.findElement(By.xpath(ReserveNameElement.INTRO_SELECT_COMPANY_TYPE)).sendKeys("Incorp");

    Select dropdown = new Select(driver.findElement(By.xpath(ReserveNameElement.INTRO_SELECT_COMPANY_TYPE)));
    dropdown.selectByVisibleText("Incorporated");
    driver.findElement(By.xpath(ReserveNameElement.INTRO_BUTTON_NEXT)).click();

    //     WebDriver driver = new FirefoxDriver();
    //     LoginTester login = new LoginTester(driver);
    //     IncorporatedTester tester = new IncorporatedTester(driver);
    //
    //     login.start();

    //     //Maximize the browser
    //     driver.manage().window().maximize();
    //     tester.start();
    //     tester.stop();

    //     // Click on Math Calculators
    //     driver.findElement(By.xpath(".//*[@id='hcalc']/table/tbody/tr/td[2]/div[3]/a")).click();
    //     
    //     // Click on Percent Calculators
    //     driver.findElement(By.xpath(".//*[@id='content']/ul[1]/li[3]/a")).click();
    //     
    //     // Enter value 10 in the first number of the percent Calculator
    //     driver.findElement(By.id("cpar1")).sendKeys(data.getNumberText(2));
    //     
    //     // Enter value 50 in the second number of the percent Calculator
    //     driver.findElement(By.id("cpar2")).sendKeys(data.getNumberText(2));
    //     
    //     // Click Calculate Button
    //     driver.findElement(By.xpath(".//*[@id='content']/table[1]/tbody/tr[2]/td/input[2]")).click();
    //   
    //     
    //     // Get the Result Text based on its xpath
    //     String result = driver.findElement(By.xpath(".//*[@id='content']/p[2]/font/b")).getText();
    //   
    //     
    //     // Print a Log In message to the screen
    //     System.out.println(" The Result is " + result);

    //Close the Browser.
    driver.close();
}

From source file:CartTest.CartTest.java

@Before
public void setup() {
    driver = new ChromeDriver();
    driver.get("http://store.demoqa.com/products-page/product-category/");

}

From source file:ch.admin.isb.hermes5.webtest.SeleniumTest.java

License:Apache License

private ChromeDriver getChromeDriver() {
    System.setProperty("webdriver.chrome.driver",
            "C:\\Daten\\Hermes5\\Tools\\seleniumdrivers\\chromedriver.exe");

    BrowserVersion bv = new BrowserVersion("", "", "", 0);
    bv.setBrowserLanguage("de");
    return new ChromeDriver();
}

From source file:co.flexmod.selenium.example.integration.framework.WebDriverFactory.java

License:Apache License

public static WebDriver create(String browser) {
    if (browser.equalsIgnoreCase("firefox")) {
        return new FirefoxDriver();
    } else if (browser.equalsIgnoreCase("chrome")) {
        return new ChromeDriver();
    } else if (browser.equalsIgnoreCase("ie")) {
        return new InternetExplorerDriver();
    } else if (browser.equalsIgnoreCase("html")) {
        HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_24);
        htmlUnitDriver.setJavascriptEnabled(true);
        return htmlUnitDriver;
    } else {//w ww  . j a  va2 s.  co m
        throw new IllegalArgumentException("The Browser Type is Undefined");
    }
}