User:Conquest19/sandbox

Geb (Browser Automation solution in Groovy, pronounced Jeb). Geb is free, open source software licensed under the Apache License, Version 2.0. 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.

Cross Browser Automation
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:

FireFox Internet Explorer Google Chrome Opera There is also experimental support for:

Chrome on Android Safari on iPhone & iPad

Remote Browsers
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).

Headless Browsers
You can also use the headless, in process, Java browser emulator HTMLUnit with WebDriver.

See the driver configuration section of the manual for information about setting up Geb to run with different drivers.

Navigating Content
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

Form Control Shortcuts
Geb has handy shortcuts for reading and writing form control values.

assert $("form").name == "Jeb" $("form").name = "Geb" assert $("form").name == "Geb"

Page Objects
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") } } } Pages define their location, an “at checker” and content (among other things). Defining this information as part of the page allows you to separate the implementation details from the intention.

import geb.Browser Browser.drive { to LoginPage assert at(LoginPage) loginForm.with { username = "admin" password = "password" }   loginButton.click assert at(AdminPage) }

Testing
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 } }

Build System Integration
Geb is easy to integrate into any build system, and information and examples on integrating with the following build/project systems is available:

Gradle Grails Maven