Example usage for org.openqa.selenium By name

List of usage examples for org.openqa.selenium By name

Introduction

In this page you can find the example usage for org.openqa.selenium By name.

Prototype

public static By name(String name) 

Source Link

Usage

From source file:AndroidRemoteDriverTest.java

/**
 * @param args the command line arguments
 *//*from   w ww . jav  a  2 s .  c o  m*/
public static void main(String[] args) {

    AndroidRemoteWebDriver driver = new AndroidRemoteWebDriver("ws://localhost:9222/devtools/page/4");
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    driver.get("http://www.google.com");
    Utils.sleep(2000);
    WebElement elm = driver.findElement(By.name("q"));
    Utils.sleep(2000);
    elm.sendKeys(" // \\ ' * [@id=\"rg_s\"]/div[1]/a ");
    elm.submit();
    //Utils.sleep(2000);
    elm = driver.findElement(By.partialLinkText("Images"));
    elm.click();
    Utils.sleep(2000);
    elm = driver.findElement(By.xpath("//*[@id=\"rg_s\"]/div[1]/a"));
    elm.click();
    Utils.sleep(2000);
    System.out.println("Page source :/n" + driver.getPageSource());

}

From source file:SmokeTester_UnitTest.java

public void executeSmokeTest() throws Exception {
    // 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", "C:\\Nino\\ChromeWebDriver\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    TestCaseReader tcreader = new TestCaseReader();
    List<TestScriptTemplate> tcl = tcreader.readExcel();

    List<TestScriptTemplate> validatedTestScript = new ArrayList();

    String log_execution = "";
    Iterator<TestScriptTemplate> i = tcl.iterator();
    while (i.hasNext()) {
        TestScriptTemplate testscript = i.next();
        //collect the results
        TestScriptTemplate testexecution = new TestScriptTemplate();

        testexecution.setAppCode(testscript.getAppCode());
        log_execution = log_execution + "\nStart smoke testing for application code: "
                + testexecution.getAppCode();

        //access the URL
        driver.get(testscript.getAppURL());

        //login if not yet
        if (driver.getCurrentUrl().contains("identity.safeway.com")) {
            //key in userid and password
            WebElement weusername = driver.findElement(By.id("username"));
            //System.out.println("tag:" + weusername.getTagName());
            weusername.sendKeys(testscript.getAppUserID());

            WebElement wepassword = driver.findElement(By.id("password"));
            //System.out.println("tag:" + wepassword.getTagName());
            wepassword.sendKeys(testscript.getAppPassword());

            WebElement weloginform = driver.findElement(By.name("loginData"));
            //System.out.println("tag:" + weloginform.getTagName());
            weloginform.submit();//from  w  w  w  .j a  va2 s.com
            log_execution = log_execution + " Login Successful";
        }

        //recoding URL; required so no need to check for nullity
        testexecution.setAppURL(driver.getCurrentUrl());
        log_execution = log_execution + " Current URL: " + driver.getCurrentUrl();
        //recoding title; required so no need to check for nullity
        testexecution.setHomePageTitle(driver.getTitle());
        log_execution = log_execution + " Page Title: " + driver.getTitle();

        if (isElementExist(testscript.getHomePageElementType(), testscript.getHomePageElement(), driver)) {
            System.out.println("Element match!" + testscript.getHomePageElement());
            log_execution = log_execution + " Home Page Element validation...";
            testexecution.setHomePageElement(testscript.getHomePageElement());
        } else {
            testexecution.setHomePageElement("not found");
        }

        //next page validation
        if (!testscript.getLevel1URL().isEmpty() || !testscript.getLevel1URL().equals("")) {
            //go to next level page
            driver.get(testscript.getLevel1URL());
            log_execution = log_execution + " Next Page validation URL: " + testscript.getLevel1URL();

            testexecution.setLevel1URL(driver.getCurrentUrl());
            System.out.println("execution log: current level 1 URL on set" + testexecution.getLevel1URL());

            if (!testscript.getLevel1PageTitle().isEmpty() || !testscript.getLevel1PageTitle().equals("")) {
                testexecution.setLevel1PageTitle(driver.getTitle());
                log_execution = log_execution + " Next Page title validation: " + driver.getTitle();
            }

            if (isElementExist(testscript.getLevel1ElementType(), testscript.getLevel1Element(), driver)) {
                testexecution.setLevel1Element(testscript.getLevel1Element());
                log_execution = log_execution + " Next Page element validation: "
                        + testscript.getLevel1Element();
            } else {
                testexecution.setLevel1Element("not found");
            }

        }
        testexecution.setLogs(log_execution);
        SmokeTestValidator_UnitTest testvalidator = new SmokeTestValidator_UnitTest(testscript);
        TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution);
        validatedTestScript.add(testingresult);

    }

    tcreader.writetoExcel(validatedTestScript);
    //Close the browser
    driver.quit();
    //return log_execution;
}

From source file:CarStoreWebSiteTest.java

@Test
public void testInsertNewCar() {

    String username = "manager";
    String password = "7777777";
    driver.findElement(By.linkText("Login")).click();
    driver.findElement(By.name("user_name")).sendKeys(username);
    driver.findElement(By.name("user_password")).sendKeys(password);

    // Look for the submit button (in the login div) and click
    // to attempt to login       
    WebElement loginButton = driver.findElement(By.name("login"));
    loginButton.submit();//from  www  . jav  a 2  s .  c om

    driver.findElement(By.linkText("Insert")).click();

    String license_plate = "ABC0000";
    String manufacturer = "Toyota";
    String model = "Camry";
    String year = "2012";
    String color = "red";
    String price = "19000.00";

    driver.findElement(By.name("license_plate")).sendKeys(license_plate);
    driver.findElement(By.name("manufacturer")).sendKeys(manufacturer);
    driver.findElement(By.name("model")).sendKeys(model);
    driver.findElement(By.name("year")).sendKeys(year);
    driver.findElement(By.name("color")).sendKeys(color);
    driver.findElement(By.name("price")).sendKeys(price);

    driver.findElement(By.name("insert_button")).click();

    String correct_value = "Inserted";
    String newPage = driver.getPageSource();

    assertTrue(newPage.contains(correct_value));

    driver.findElement(By.linkText("Delete")).click();

    driver.findElement(By.name("license_plate")).sendKeys(license_plate);

    driver.findElement(By.name("delete_button")).click();

    driver.findElement(By.linkText("Logout")).click();
}

From source file:CarStoreWebSiteTest.java

@Test
public void testInsertCarThatExists() {

    String username = "manager";
    String password = "7777777";
    driver.findElement(By.linkText("Login")).click();
    driver.findElement(By.name("user_name")).sendKeys(username);
    driver.findElement(By.name("user_password")).sendKeys(password);

    // Look for the submit button (in the login div) and click
    // to attempt to login       
    WebElement loginButton = driver.findElement(By.name("login"));
    loginButton.submit();//from   w  w w . j  ava2 s  .c  o m

    driver.findElement(By.linkText("Insert")).click();

    String license_plate = "ABC0001";
    String manufacturer = "Toyota";
    String model = "Camry";
    String year = "2012";
    String color = "red";
    String price = "19000.00";

    driver.findElement(By.name("license_plate")).sendKeys(license_plate);
    driver.findElement(By.name("manufacturer")).sendKeys(manufacturer);
    driver.findElement(By.name("model")).sendKeys(model);
    driver.findElement(By.name("year")).sendKeys(year);
    driver.findElement(By.name("color")).sendKeys(color);
    driver.findElement(By.name("price")).sendKeys(price);

    driver.findElement(By.name("insert_button")).click();

    String correct_value = "There is already a car with this license plate";
    String newPage = driver.getPageSource();

    assertTrue(newPage.contains(correct_value));

    driver.findElement(By.linkText("Logout")).click();
}

From source file:CarStoreWebSiteTest.java

@Test
public void testDeleteCarThatExists() {

    String username = "manager";
    String password = "7777777";
    driver.findElement(By.linkText("Login")).click();
    driver.findElement(By.name("user_name")).sendKeys(username);
    driver.findElement(By.name("user_password")).sendKeys(password);

    // Look for the submit button (in the login div) and click
    // to attempt to login       
    WebElement loginButton = driver.findElement(By.name("login"));
    loginButton.submit();// ww  w.jav a  2s  .  co m

    driver.findElement(By.linkText("Delete")).click();

    String license_plate = "ABC9999";

    driver.findElement(By.name("license_plate")).sendKeys(license_plate);

    driver.findElement(By.name("delete_button")).click();

    String correct_value = "There isn't a car with this license plate";
    String newPage = driver.getPageSource();

    assertTrue(newPage.contains(correct_value));

    driver.findElement(By.linkText("Logout")).click();
}

From source file:CarStoreWebSiteTest.java

@Test
public void testDeleteCarThatDontExists() {

    String username = "manager";
    String password = "7777777";
    driver.findElement(By.linkText("Login")).click();
    driver.findElement(By.name("user_name")).sendKeys(username);
    driver.findElement(By.name("user_password")).sendKeys(password);

    // Look for the submit button (in the login div) and click
    // to attempt to login       
    WebElement loginButton = driver.findElement(By.name("login"));
    loginButton.submit();/*from   w  w  w . j  a v a2s .  co  m*/

    String license_plate = "ABC9999";

    driver.findElement(By.linkText("Insert")).click();

    driver.findElement(By.name("license_plate")).sendKeys(license_plate);

    driver.findElement(By.name("insert_button")).click();

    driver.findElement(By.linkText("Delete")).click();

    driver.findElement(By.name("license_plate")).sendKeys(license_plate);

    driver.findElement(By.name("delete_button")).click();

    String correct_value = "Deleted";
    String newPage = driver.getPageSource();

    assertTrue(newPage.contains(correct_value));

    driver.findElement(By.linkText("Logout")).click();
}

From source file:CarStoreWebSiteTest.java

@Test
public void testSearchCarThatNotExists() {

    String license_plate = "ABC9779";

    driver.findElement(By.linkText("Search")).click();
    driver.findElement(By.name("license_plate")).sendKeys(license_plate);
    driver.findElement(By.name("search_button")).click();

    String correct_value = "There is no car with this criteria";
    String newPage = driver.getPageSource();

    assertTrue(newPage.contains(correct_value));
}

From source file:CarStoreWebSiteTest.java

@Test
public void testSearchWithoutFilter() {
    driver.findElement(By.linkText("Search")).click();
    driver.findElement(By.name("search_button")).click();

    String newPage = driver.getPageSource();
    String correct_value;/*from ww  w .  j  av a 2s . co  m*/
    String complement;

    for (int i = 1; i < 11; i++) {
        complement = i >= 10 ? "" + i : "0" + i;
        correct_value = "ABC00" + complement;
        assertTrue(newPage.contains(correct_value));
    }

}

From source file:CarStoreWebSiteTest.java

@Test
public void testSearchWithSingleFilter() {

    String year = "2013";

    driver.findElement(By.linkText("Search")).click();
    driver.findElement(By.name("year")).sendKeys(year);
    driver.findElement(By.name("search_button")).click();

    String newPage = driver.getPageSource();

    String correct_value = "ABC0009";
    assertTrue(newPage.contains(correct_value));
}

From source file:CarStoreWebSiteTest.java

@Test
public void testSearchWithMultipleFilterAnd() {

    String model = "Veloster";
    String color = "red";

    driver.findElement(By.linkText("Search")).click();
    driver.findElement(By.name("model")).sendKeys(model);
    driver.findElement(By.name("color")).sendKeys(color);
    Select dropdown = new Select(driver.findElement(By.name("color_logical")));
    dropdown.selectByValue(" AND ");
    driver.findElement(By.name("search_button")).click();

    String newPage = driver.getPageSource();

    String correct_value = "ABC0006";
    assertTrue(newPage.contains(correct_value));
}