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:com.mycompany.fullslidertest.FullsliderTest.java

public void createPresentation(String title) {
    driver = new ChromeDriver();
    js = (JavascriptExecutor) driver;/*from   w  w w  . jav  a2 s  .  c o  m*/
    actions = new Actions(driver);

    driver.get("http://localhost:8888");
    driver.manage().window().maximize();

    js.executeScript("$('.newpresopanel')[0].click()");
    js.executeScript("$('#titleinput').val('" + title + "')");
    js.executeScript("$('.createpresentation')[0].click()");
}

From source file:com.mycompany.newseleniumtest.TestScript.java

public void startDriver(String browser) {
    switch (browser) {
    case "firefox":

        FirefoxProfile fp = new FirefoxProfile();
        fp.setPreference("browser.startup.homepage", "about:blank");
        fp.setPreference("startup.homepage_welcome_url", "about:blank");
        fp.setPreference("startup.homepage_welcome_url.additional", "about:blank");

        this.driver = new FirefoxDriver(fp);
        this.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().window().maximize();

        break;// w  w  w  .ja  v  a2 s .c  o m
    case "chrome":
        System.setProperty("webdriver.chrome.driver", "/Users/rahmatzailani/Documents/chromedriver");
        this.driver = new ChromeDriver();
        this.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        break;
    default:

        break;
    }
}

From source file:com.mycompany.newseleniumtest.TestScript2.java

public void startDriver(String browser) {
    switch (browser) {
    case "firefox":

        FirefoxProfile fp = new FirefoxProfile();
        fp.setPreference("browser.startup.homepage", "about:blank");
        fp.setPreference("startup.homepage_welcome_url", "about:blank");
        fp.setPreference("startup.homepage_welcome_url.additional", "about:blank");

        this.driver = new FirefoxDriver(fp);
        this.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().window().maximize(); //pras

        break;/*  www.  java  2s.c  o  m*/
    case "chrome":
        System.setProperty("webdriver.chrome.driver", "/Users/kevinwibowo/Documents/Project/chromedriver");
        this.driver = new ChromeDriver();
        this.driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        break;
    default:

        break;
    }
}

From source file:com.mycompany.selenium.SeleniumExample.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver");

    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    WebDriver driver = new ChromeDriver();

    //        System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver");

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();//w  w w  .  j  a  v  a2 s.c  om

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith("cheese!");
        }
    });

    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    //Close the browser
    driver.quit();
}

From source file:com.mycompany.selenium.SeleniumTests.java

@BeforeClass
public static void setup() {
    /*########################### IMPORTANT ######################*/
    /*## Change this, according to your own OS and location of driver(s) ##*/
    /*############################################################*/
    System.setProperty("webdriver.chrome.driver", "/Applications/chromedriver");

    com.jayway.restassured.RestAssured.given().get("http://localhost:3000/reset");
    driver = new ChromeDriver();
    driver.get("http://localhost:3000");
}

From source file:com.mycompany.seleniumtest.Selenium2Example.java

public static void main(String[] args) {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    System.setProperty("webdriver.chrome.driver", "/Users/CosticaTeodor/Downloads/drivers/chromedriver");
    System.setProperty("webdriver.safari.driver", "/usr/bin/safaridriver");

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

    // And now use this to visit the cars program
    driver.get("http://localhost:3000/");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    //verify the page is loaded, wait 10 seconds if it doesn't
    try {//w  ww. j  a  va  2 s.  c o  m
        driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
        System.out.println("Page loaded!");
    } catch (Exception e) {
        System.err.println(e.getMessage());
        System.err.println(e.getStackTrace());
    }

    int rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size();
    if (rowCount == 5) {
        System.out.println(rowCount + " is the row count!");
    } else {
        System.out.println("rowcount should be different!");
    }

    // Find the filter input element by its name
    WebElement searchFilter = driver.findElement(By.id("filter"));

    // Enter 2002 to search for
    searchFilter.sendKeys("2002");

    //check if there are two rows left
    rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size();
    System.out.println("Row count after filter is: " + rowCount);

    searchFilter.clear();
    searchFilter.sendKeys("");

    rowCount = driver.findElements(By.xpath("//table[@class='table']/tbody/tr")).size();
    System.out.println("Row count after filter is: " + rowCount);
    //Close the browser
    driver.quit();
}

From source file:com.mycompany.webcrawler.GmailAutomation.java

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver", "chromedriver.exe");
    DesiredCapabilities dcaps = new DesiredCapabilities();

    dcaps.setCapability("takeScreenshot", true);
    //WebDriver driver = new PhantomJSDriver(dcaps);

    //Comment for PhantomJS
    ChromeDriver driver = new ChromeDriver();

    //Comment for PhantomJS
    //driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

    driver.get(//  w  w w  . ja v a2  s .  c o  m
            "https://accounts.google.com/ServiceLogin?sacu=1&scc=1&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&osid=1&service=mail&ss=1&ltmpl=default&rm=false#identifier");

    try {
        Thread.sleep(2000);

        driver.findElement(By.id("Email")).sendKeys("Your gmail goes here");

        Thread.sleep(2000);
        driver.findElement(By.id("next")).click();

        Thread.sleep(2000);
        driver.findElement(By.id("Passwd")).sendKeys("Your password goes here");

        Thread.sleep(2000);
        driver.findElement(By.id("signIn")).click();

        Thread.sleep(2000);
        driver.findElement(By.xpath("//div[@class='T-I J-J5-Ji T-I-KE L3']")).click();

        Thread.sleep(2000);
        driver.findElement(By.className("vO")).sendKeys("Who you want to send the email to");

        Thread.sleep(2000);
        driver.findElement(By.className("aoT")).sendKeys("The subject");

        Thread.sleep(2000);
        driver.switchTo().activeElement().sendKeys(Keys.TAB);
        driver.switchTo().activeElement().sendKeys("The body");

        //Comment for PhantomJS
        //driver.findElement(By.xpath("//div[@class='Am Al editable LW-avf']")).sendKeys("Test Email");

        Thread.sleep(2000);
        File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
        FileUtils.copyFile(file, new File("screenshot.jpg"));

        Thread.sleep(2000);
        driver.findElement(By.xpath("//div[@class='T-I J-J5-Ji aoO T-I-atl L3']")).click();

        //Comment for PhantomJS
        //Thread.sleep(2000);
        //driver.get("https://mail.google.com/mail/u/0/#sent");
    } catch (IOException | InterruptedException | WebDriverException e) {
        System.out.println(e.getMessage());
    }
}

From source file:com.nabla.project.fronter.selenium.tests.helper.SeleniumHelper.java

License:Open Source License

private synchronized static WebDriver getCurrentDriver() {
    if (SeleniumHelper.driver == null) {
        try {/*from  w  w  w . j  a v a  2s  . c  o  m*/
            // driver = new FirefoxDriver(new FirefoxProfile());
            SeleniumHelper.driver = new ChromeDriver();
        } finally {
            Runtime.getRuntime().addShutdownHook(new Thread(new BrowserCleanup()));
        }
    }
    return SeleniumHelper.driver;
}

From source file:com.nabla.project.visma.selenium.tests.helper.SeleniumHelper.java

License:Open Source License

private synchronized static WebDriver getCurrentDriver() {
    if (SeleniumHelper.REAL_DRIVER == null) {
        // try//from   ww w  .  jav a 2s  .c  om
        // {
        // driver = new FirefoxDriver(new FirefoxProfile());
        SeleniumHelper.REAL_DRIVER = new ChromeDriver();
        // } finally
        // {
        // Runtime.getRuntime().addShutdownHook(new Thread(new BrowserCleanup()));
        // }
    }
    return SeleniumHelper.REAL_DRIVER;
}

From source file:com.novartis.opensource.yada.test.YADAAdminTest.java

License:Apache License

/**
 * Configure test for provided browser// w w w .j  a v  a  2 s .c o  m
 * 
 * @param browser the currently tested client
 * @param properties the name of the properties file
 * @throws IOException  when properties can't be loaded
 */
@Parameters({ "browser", "properties" })
@BeforeClass
public void init(String browser, String properties) throws IOException {
    ConnectionFactoryTest.setProps(properties);
    Properties props = ConnectionFactoryTest.getProps();
    this.host = props.getProperty("YADA.host");
    this.dbDriver = props.getProperty("YADA.index.driverClassName");
    this.dbUrl = props.getProperty("YADA.index.url");
    this.dbUser = props.getProperty("YADA.index.username");
    this.dbPw = props.getProperty("YADA.index.password");
    this.dbValidationQuery = props.getProperty("YADA.index.validationQuery");
    if (browser.equalsIgnoreCase("firefox")) {
        setDriver(new FirefoxDriver());
    } else if (browser.equalsIgnoreCase("chrome")) {
        setDriver(new ChromeDriver());
    }
    getDriver().get(PROTOCOL + this.host + this.uri);
}