Summary
Here is a GINT version of a simple selenium test used as a standard example.
First run
The first time this is run, it will take a long time (minutes) to download all the selenium dependencies. Be patient!
Selenium and browsers
You probably need to test against multiple browsers. We recommend Chrome or FireFox as the primary development browser. Get your tests running with one of these browsers and then add the other later. Safari is not recommended for development, it just is not as dependable for running Selenium tests . We have had few problems using Chrome or FireFox. Consider not turning on automatic browser updates especially for your continuous integration server so you can manually control when updates occur. Browser changes can cause Selenium to fail until Selenium gets upgraded to a supporting level.
Examples
// GINT version of http://seleniumhq.org/docs/03_webdriver.html#setting-up-webdriver-project. Include the browser specific driver(s) that you intend to test with. // This version takes advantage of the seleniumHelper functions to make it easier @Grapes([ @Grab(group='org.swift.tools', module='gint', version='2.8.0'), @Grab(group='org.seleniumhq.selenium', module='selenium-java', version='3.11.0'), @Grab(group='org.seleniumhq.selenium', module='selenium-firefox-driver', version='3.11.0'), @Grab(group='org.seleniumhq.selenium', module='selenium-chrome-driver', version='3.11.0'), @Grab(group='org.seleniumhq.selenium', module='selenium-safari-driver', version='3.11.0'), @Grab(group='org.seleniumhq.selenium', module='selenium-ie-driver', version='3.11.0'), @Grab(group='org.seleniumhq.selenium', module='selenium-edge-driver', version='3.11.0'), ]) import org.swift.tools.* import org.openqa.selenium.* import org.openqa.selenium.support.ui.* includeTool << Helper // helper utilities includeTool << SeleniumHelper includeTool << Gint // gint framework gint.initialize(this) // required // Open driver and track. Firefox is the default unless browser is set. Valid browsers are firefox, chrome, safari, or ie gint.addSetUp(seleniumHelper.getInitializeTestcase()) gint.add( name: 'test', inline: { seleniumHelper.gotoUrl(url: 'http://www.google.com') def element = seleniumHelper.findElement(name: 'q') element.sendKeys('Cheese!') // Enter something to search for element.submit() // Now submit the form. WebDriver will find the form for us from the element helper.logWithFormat('title', seleniumHelper.getDriver().getTitle()) // show the title of the initial screen // Google's search is rendered dynamically with JavaScript. Wait for the page to load, timeout after 10 seconds (new WebDriverWait(seleniumHelper.getDriver(), 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.getTitle().toLowerCase().startsWith("cheese!") } }) assert seleniumHelper.getDriver().getTitle()?.toLowerCase()?.startsWith('cheese!') // Should see: "cheese! - Google Search" }, ) gint.finalizeTest() // final preparations for running tests // Selenium clean up target(name: 'final', description: 'Close the driver at the final stage of the script', prehook: [], posthook: []) { seleniumHelper.close() }
gant -f src/main/groovy/selenium.gant = = = = = = selenium started at Wed Sep 12 08:08:37 CDT 2012 = = = = = = [info] Run last failed testcases: test [start] test [ending] test [info] title . . . . . . . . . . . . . . . . . . : Google [complete] test - 4.766 secs [info] Successful testcases . . . . . . . . . . : 1 <<< TEST SUCCESSFUL [info] Total testcases . . . . . . . . . . . . . : 1 [info] Elapsed run time . . . . . . . . . . . . : 12.484 secs = = = = = = selenium completed at Wed Sep 12 08:08:49 CDT 2012 = = = = = = [info] Final: run driver quit BUILD SUCCESSFUL Total time: 14.75 seconds
Browser Support
Use the browser parameter in gint.properties or from a command line. Values supported are:
- chrome - Google Chrome - this is the default for 2.8 and higher
- firefox - Mozilla Firefox - default for releases <= 2.7
- safari - OSX Safari
- ie - Internet Explorer
- edge - Microsoft Edge
Selenium Grid Support
Selenium Grid is an important tool for test automation environments now included with Selenium Server.
Selenium-Grid allows you run your tests on different machines against different browsers in parallel.
Starting with GINT 2.8, a new parameter called seleniumHub that can be set in gint.properties, as a command line parameter, or set directly in a testcase. If provided, it will be used as the url to the Selenium grid hub server address. Usually, something like https://localhost:4444/wd/hub or similar.