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:com.safeway.app.appcert.smoketester.SmokeTester.java

@Test
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 + " Start 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  ww  .ja  va  2s .c  om*/
        }

        //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 + " Login Successful";
        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);
        System.out.println("Execution Log: " + log_execution);
        log_execution = "";
        SmokeTestValidator testvalidator = new SmokeTestValidator(testscript);
        TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution);
        validatedTestScript.add(testingresult);

    }

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

From source file:com.seleniumtests.it.driver.support.pages.DriverTestPageNativeActions.java

License:Apache License

public void switchToSubFrame() {
    WebElement el = driver.findElement(By.name("mySecondIFrame"));
    driver.switchTo().frame(el);
}

From source file:com.seleniumtests.it.driver.support.pages.DriverTestPageNativeActions.java

License:Apache License

public void switchToSecondFrameByElement() {
    WebElement el = driver.findElement(By.name("mySecondIFrame"));
    driver.switchTo().frame(el);
}

From source file:com.seleniumtests.it.driver.TestDriver.java

License:Apache License

@Test(groups = { "it", "ut" })
public void testFindElements() {
    // 2 elements to find
    Assert.assertEquals(new HtmlElement("", By.name("divFindName")).findElements().size(), 2);

    // 4 elements to find, one in a branch
    Assert.assertEquals(new HtmlElement("", By.className("myClass")).findElements().size(), 4);
}

From source file:com.seleniumtests.it.driver.TestDriver.java

License:Apache License

/**
 * Check that if no element is returned, no error is raised but we should have searched several times
 *///from w  ww .  j a  v  a2s.  c  o  m
@Test(groups = { "it", "ut" })
public void testFindElementsNotExist() {
    SeleniumTestsContextManager.getThreadContext().setReplayTimeout(7);
    long start = new Date().getTime();
    Assert.assertEquals(new HtmlElement("", By.name("foobar")).findElements().size(), 0);
    Assert.assertTrue(new Date().getTime() - start > 6500);
}

From source file:com.seleniumtests.it.util.TestByC.java

License:Apache License

@Test(groups = { "it" })
public void testFindElementsBySeveralCriteria() {
    Assert.assertEquals(/*from  www.  j av  a  2 s.com*/
            new TextFieldElement("", ByC.and(By.tagName("input"), By.name("textField"))).findElements().size(),
            2);
}

From source file:com.seleniumtests.it.util.TestByC.java

License:Apache License

@Test(groups = { "it" })
public void testFindElementBySeveralCriteria() {
    TextFieldElement el = new TextFieldElement("", ByC.and(By.tagName("input"), By.name("textField")));
    Assert.assertEquals(el.getTagName(), "input");
    Assert.assertEquals(el.getAttribute("name"), "textField");
}

From source file:com.seleniumtests.it.util.TestByC.java

License:Apache License

@Test(groups = { "it" }, expectedExceptions = NoSuchElementException.class)
public void testFindElementBySeveralCriteriaNothingFound() {
    SeleniumTestsContextManager.getThreadContext().setReplayTimeout(7);
    new TextFieldElement("", ByC.and(By.tagName("input"), By.name("noElement"))).getTagName();
}

From source file:com.seleniumtests.it.util.TestByC.java

License:Apache License

@Test(groups = { "it" })
public void testFindElementsBySeveralCriteriaNothingFound() {
    SeleniumTestsContextManager.getThreadContext().setReplayTimeout(7);
    Assert.assertEquals(//from  w w w .  j  a  v  a  2  s . c om
            new TextFieldElement("", ByC.and(By.tagName("input"), By.name("noElement"))).findElements().size(),
            0);
}