Over a million developers have joined DZone.

Showing A Use To DELEGATE_FIRST Closure Resolve Strategy: Selenium Navigation

·
// 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
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}