Changeset 948 for branches/features


Ignore:
Timestamp:
May 29, 2011, 12:58:10 PM (13 years ago)
Author:
gav
Message:

Functional tests, factor out login method.

Location:
branches/features/purchaseOrders/test/functional
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/features/purchaseOrders/test/functional/GebReportingSpecBase.groovy

    r937 r948  
    11import geb.spock.GebReportingSpec
     2import gnumims.functional.pages.HomePage
     3import gnumims.functional.pages.LoginPage
    24
    35/**
    4  *
     6 * Provides a base class for functional testing.
     7 * Significantly speedup functional test development:
     8 *  Run `grails test run-app`.
     9 *  In a separate process run `grails interactive`
     10 *  At the prompt `test-app functional: -baseUrl=http://localhost:8080/gnuMims -echoOut`
     11 *  Hit enter to repeat tests very quickly.
    512 */
    613class GebReportingSpecBase extends GebReportingSpec {
     
    815    String getBaseUrl() { "http://localhost:8080/$appName/" }
    916    File getReportDir() { new File("target/test-reports/geb-pages") }
     17
     18    /**
     19     * Logs into the application either via a target page that requires
     20     * authentication or by directly requesting the login page.
     21     */
     22    def login(username, password, targetPage = null, params = [:]) {
     23        if (targetPage) {
     24            to([*:params], targetPage)
     25            page LoginPage
     26        }
     27        else {
     28            to LoginPage
     29        }
     30
     31        form.j_username = username
     32        form.j_password = password
     33
     34        //if (targetPage) login.click(targetPage)
     35        if (targetPage) loginButton.click(HomePage) // gnuMims will always start at HomePage.
     36        else loginButton.click(HomePage)
     37    }
    1038}
  • branches/features/purchaseOrders/test/functional/LoginSpec.groovy

    r947 r948  
    1515    }
    1616
    17     def "When we click login we go to the home page"() {
     17    def "When we login, we go to the home page"() {
    1818        when:
    19         to LoginPage
    20         form.j_username = "admin"
    21         form.j_password = "pass"
    22         login.click()
     19        login('admin', 'pass')
    2320
    2421        then:
     
    2623    }
    2724
    28     def "When we click logout, we go to the logout page"() {
     25    def "When we logout, we go to the logout page"() {
    2926        when:
    3027        logout.click()
     
    3734    def "If we type in the wrong password"() {
    3835        when:
    39         to LoginPage
    40         form.j_username = "admin"
    41         form.j_password = "bogus"
    42         login.click()
     36        login('admin', 'bogus')
    4337
    4438        then:
  • branches/features/purchaseOrders/test/functional/gnumims/functional/pages/LoginPage.groovy

    r947 r948  
    66
    77    static content = {
    8         login(to:HomePage) { $('#loginForm input[value=Login]') }
     8        loginButton(to:HomePage) { $('#loginForm input[value=Login]') }
    99        form { $("#loginForm") }
    1010        password { $("input[name=j_password]").value() }
Note: See TracChangeset for help on using the changeset viewer.