Previously I used Robot Framework to automate testing of applications, but a new client asked pay attention to Spock + GEB. I've never used it, but I need to quickly compare two of these tools and make a choice. Please help me to understand how they differ and what are the strengths / weaknesses of each.
Geb is a browser automation solution. 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 or JUnit. Spock. Spock is a testing and specification framework for Java and Groovy applications.
Geb is a Web automation framework using Groovy. Geb uses WebDriver to test web applications using either real browsers or the HtmlUnit library.
What is it? 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.
I tell you about Geb, i use gebish for testing web-applications more 6 months. That's all his benefits:
Now more details about each of them.
Geb leverages the WebDriver library for browser automation. This means that Geb works with any browser that WebDriver works with, and the list of browsers that WebDriver works with is growing all the time.
The core supported browsers are:
There is also experimental support for:
WebDriver also supports remote drivers. This allows you to automate a browser running on another machine! This means you can easily run your test suite against an IE browser from the comfort of your Mac or Linux machine (and vice versa).
Geb takes inspiration from jQuery to provide a concise and effective way to get at content. This is called the Navigator API.
The dollar function can be used anywhere to select content based on CSS selectors, attribute matchers and/or indexes.
// CSS 3 selectors
$("div.some-class p:first[title='something']")
// Find via index and/or attribute matching
$("h1", 2, class: "heading")
$("p", name: "description")
$("ul.things li", 2)
// 'text' is special attribute for the element text content
$("h1", text: "All about Geb")
// Use builtin matchers and regular expressions
$("p", text: contains("Geb"))
$("input", value: ~/\d{3,}-\d{3,}-\d{3,}/)
// Chaining
$("div").find(".b")
$("div").filter(".c").parents()
$("p.c").siblings()
Geb has first class support for the Page Object pattern, leveraging Groovy's DSL capabilities to allow you the developer to easily define the interesting parts of your pages in a concise, maintanable and extensible manner.
import geb.Page
class LoginPage extends Page {
static url = "http://myapp.com/login"
static at = { heading.text() == "Please Login" }
static content = {
heading { $("h1") }
loginForm { $("form.login") }
loginButton(to: AdminPage) { loginForm.login() }
}
}
class AdminPage extends Page {
static at = { heading.text() == "Admin Section" }
static content = {
heading { $("h1") }
}
}
Modern web pages are full of asynchronous operations like AJAX requests and animations. Geb provides built in support for this fact of life.
Any content lookup, or operation can be wrapped in a waitFor clause.
waitFor {
$("p.status").text() == "Asynchronous operation complete!"
}
This will keep testing the condition for a certain amount of time (which is configurable) until it passes. The same technique can be used to just wait for the content, not necessarily for the content to have some characteristic.
def dynamicParagraph = waitFor { $("p.dynamically-added") }
dynamicParagraph.text() == "Added dynamically!"
You can also define that content should be implicitly waited for in the Content DSL for page objects
import geb.Page
class DynamicPage extends Page {
static content = {
dynamicParagraph(wait: true) { $("p.dynamically-added") }
}
}
With this definition, when dynamicParagraph is requested Geb will implictly wait for a certain amount of time for it to appear.
Geb provides integration modules for popular testing frameworks such as Spock, JUnit, TestNG, EasyB and Cucumber (via Cuke4Duke)
While Geb works great with all of these frameworks, it really shines with Spock. Spock is an innovative testing framework that is a great match for using with Geb. Using Spock + Geb gives you very clear, concise and easy to understand test specifications with very little effort.
import geb.Page
import geb.spock.GebSpec
class LoginSpec extends GebSpec {
def "login to admin section"() {
given:
to LoginPage
when:
loginForm.with {
username = "admin"
password = "password"
}
and:
loginButton.click()
then:
at AdminPage
}
}
Geb is easy to integrate into any build system, and information and examples on integrating with the following build/project systems is available:
You can look my Example (Spock+GEB) here: github
Read more about geb here: Official Site
Thanks!!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With