Why Geb with Groovy and Spock

Without evading the cliched and customary introductory article on WHY a particular stack for web browser automation, I shall start the article with:

Geb : According to official page

"Geb is a browser automation solution.
It brings together the power of WebDriver, the elegance of jQuery content selection, the robustness of Page Object modelling and the expressiveness of the Groovy language.
It can be used for scripting, scraping and general automation — or equally as a functional/web/acceptance testing solution via integration with testing frameworks such as Spock, JUnit & TestNG
."

Scraping is nothing but extracting data from websites. GEB is a wrapper over Selenium Webdriver, thence it supports all the browsers that webdriver supports (including HTMLUnitdriver).
Geb provides a concise and Groovy interface to the content and controls in your browser. This is implemented through the Navigator API which is a jQuery inspired mechanism for finding, filtering and interacting with DOM elements. (worth reading).

Geb provides some convenient methods for waiting for a certain condition to be true. This is useful for testing pages using AJAX, timers or effects. For instance.


waitFor {} // use default configuration
waitFor(10) {} // wait for up to 10 seconds, using the default retry interval
waitFor(10, 0.5) {} // wait for up to 10 seconds, waiting half a second in between retries
waitFor("verySlow") {} // use the preset “quick” as the wait settings


In the config file the global wait and presets can be set as:
 
 GEB offers a templated way using Groovy closures to gather content of a page using DSL(Domain specific language). The reusability of page object model can further be enhanced using Modules.

Groovy: The below definition from the official page says all about it:

"Groovy is a powerful, optionally typed and dynamic language, with static-typing and static compilation capabilities, for the Java platform aimed at improving developer productivity thanks to a concise, familiar and easy to learn syntax. It integrates smoothly with any Java program, and immediately delivers to your application powerful features, including scripting capabilities, Domain-Specific Language authoring, runtime and compile-time meta-programming and functional programming"

Spock: With the help of JUnit runner, Spock is compatible with most IDEs, build tools, and continuous integration servers. Spock is inspired from JUnit, jMock, RSpec, Groovy, Scala, Vulcans, and other fascinating life forms. Spock offers a very smooth way of writing BDD tests as below:
As you can see the given/when/then statements make logical sense . The :where keyword enables data-driven testing. @Unroll tag helps the runner treat eat data set a separate test case.




Comments

Popular Posts