DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Marcos has posted 4 posts at DZone. View Full User Profile

Showing A Use To DELEGATE_FIRST Closure Resolve Strategy: Selenium Navigation

08.15.2008
| 3682 views |
  • submit to reddit
        // Show how to use groovy closures to write more clear selenium code

// More details here: http://snippets.dzone.com/posts/show/5922
// first, add a method to Selenium class
Selenium.metaClass.execute = { closure ->
    closure.delegate = delegate
    closure.resolveStrategy = Closure.DELEGATE_FIRST
    closure()
}


// making selenium stuff more clear

def selenium = getSelenium()
selenium.execute {
    type "field", "value"
    click "submitButton"
    waitForPageToLoad "5000"
    // do some more stuff
}