Tuesday, October 18, 2011

Geb ain't just some country hick!

Started using Geb (http://www.gebish.org/) for some simple UI automations to run via Jenkins.  Basically, login to several instances of our app every half an hour and make sure something infrastructure-wise has not taken our app down.  Only issue is something with the network (proxy config etc.) makes it run REAL slow so far...

>>>
@Grapes([
    @Grab("org.codehaus.geb:geb-core:0.6.0"),
    @Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.0rc3")
])
import geb.*
import org.openqa.selenium.firefox.FirefoxDriver

class LoginPage extends Page {
    static url = ""
   
    static content = {
        submitButton(to: MainPage) { $("input", type: "button", name: "signin") }
        usernameInput() { $("input", type: "text", name: "usernameInput") }
        passwordInput() { $("input", type: "password", name: "passwordInput") }
       
    }
}

class MainPage extends Page {
    static url = "main"
}

Browser.drive() {
    def username = config.rawConfig.username
    def password = config.rawConfig.password
    def loginTitle = config.rawConfig.loginTitle

    println "Opening login page..."
    to LoginPage
    at LoginPage
    assert $("title").text() == "Sign In"
   
    println "Setting username=$username"
    usernameInput << username
    println "Validating username..."
    assert usernameInput.value() == username
   
    println "Setting password=$password"
    passwordInput << password
    println "Validating password..."
    assert passwordInput.value() == password
   
    println "Submitting login form..."
    submitButton.click(MainPage)
    println "Waiting for main page..."
   
    at MainPage
   
    println "Checking for main title..."
    assert $("title").text() == "Main Title"
}.quit()

println "Done!"

<<<

No comments:

Post a Comment