1. Refactor
  2. Untitled project
  3. grails-webdriver

Source

grails-webdriver / test / unit / pages / test / TestOnePage.groovy

package pages.test

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.support.FindBy
import org.openqa.selenium.WebElement

import org.codehaus.groovy.grails.plugins.webdriver.ListElement
import org.codehaus.groovy.grails.plugins.webdriver.TableElement
import org.codehaus.groovy.grails.plugins.webdriver.SelectElement
import org.codehaus.groovy.grails.plugins.webdriver.LinkElement

/**
 * Created by IntelliJ IDEA.
 * User: rob
 * Date: Nov 3, 2009
 * Time: 9:15:13 PM
 * To change this template use File | Settings | File Templates.
 */

public class TestOnePage extends NavigationPage {
    static expectedTitle = "Test Page 1"

    WebDriver driver
    
    @FindBy(id = "fourteen_id")
    WebElement fourteen

    String one
    String two
    String three
    String four
    String five
    String six
    String seven
    String eight

    @FindBy(id = "nine_id")
    String nine

    @FindBy(xpath = "//input[10]")
    String ten

    String getEleven() {
        driver.findElement(By.id("eleven_id")).value
    }

    String getTwelve() {
        twelveElement.value
    }

    String getThirteen() {
        thirteen_id.value
    }

    String getFourteen() {
        fourteen.value
    }

    List<LinkElement<TestTwoPage>> listOfLinks

    String seventeen

    String missing

    String textarea

    String mandatoryMissing

    public boolean missingIsNull() {
        getMissing() == null
    }

    final String readOnly

    String select
    SelectElement select2

    boolean uncheckedCheckbox
    boolean checkedCheckbox
    Boolean checkedCheckbox2

    boolean radio1
    boolean radio2
    boolean radio3
    boolean radio4

    ListElement navigation
    TableElement people
    TableElement<PersonRow> personTable
    PersonRow[] personRows

    TestOnePage clickTwoLinkWithWrongPage() {
        linkToTwo.click()
    }

    NotARealPage clickTwoLinkWithNotARealPage() {
        linkToTwo.click()
    }

    int getNumberOfNavigationLinks() {
        return getNavigation().size()
    }

    String getLinkHref(int row) {
        return getNavigation().getRow(row).findElement(By.tagName("a")).getAttribute("href")
    }

    String getName(int row) {
        getPeople().getCell(row, 0).text
    }

    int getAge(int row) {
        getPeople().getCell(row, 1).text as int
    }

    TestThreePage clickLink(int row) {
        getPeople().getLink(row, 2).click()
    }

    static elements = {
        listOfLinks(By.xpath("//ul[@id='listOfLinks']/li/a"))
        three(By.id("three_id")) // By as parameter
        four { By.id("four_id") } // By returned from closure
        five(find: By.id("five_id")) // Closure as map parameter
        six(javascript:false) { By.id("six_id") } // Closure and properties
        seven { driver.findElement(By.id("seven_id")) } // WebElement returned from closure
        eight { getByForEight() } // Closure calling method
        checkedCheckbox2(By.name("checkedCheckbox"))
        sixteen { By.id("sixteen_id") }
        seventeen(find: By.id("seventeen_id"), afterSet: { WebElement e -> e.sendKeys("!" + driver.class.simpleName)})
        nineteen(optional:true)
        missing(optional:true)
        mandatoryMissing(By.xpath("//div[@class='sausage']"))
        select2(By.name("select"))
        personTable(By.id("people"))
        personRows(By.xpath("//table[@id='people']/tbody/tr"))
    }
        
    By getByForEight() {
        return By.id("eight_id")
    }

}