Skip to content

askucins/geb-the-internet

Repository files navigation

Learning Geb with The Internet (ver. 0.58.0 - 10, February 2020)

Examples of Geb test automation of various popular use cases available, well… on the Internet :)

A list of such use cases has been collected by Dave Heaffner, and it’s available on https://github.com/tourdedave/the-internet

Available examples from The Internet

Alternatively: run The Internet examples locally

  • Install rvm

  • Install ruby 2.4.1

rvm install ruby-2.4.1
  • Install bundler

gem install bundler
bundle install
  • Start the server:

rackup
  • Pages will be available locally:

http://localhost:9292/url_path

Notes, how-tos etc.

Init Gradle project

gradle init --type groovy-library

Passing a configuration from Gradle to JVM

In build.gradle pass the gradle project property to system property:

tasks.withType(Test) {
    systemProperty 'org.askucins.webdriver', project.findProperty('webdriver')
    // [...]
}

Then in the GebConfig.groovy select your webdriver based on the passed system property:

import org.openqa.selenium.firefox.FirefoxDriver

import static org.askucins.utils.WebDriverConfiguration.chromeDriver

switch (System.getProperty('org.askucins.webdriver')) {
    case 'firefox':
        driver = { new FirefoxDriver() }
        break
    case 'chrome':
        driver = { chromeDriver([headless: false]) }
        break
    default:
        driver = { chromeDriver([headless: true]) }
}

Also, if you want to e.g. run execute tests with firefox you may run this:

gw test -Pwebdriver=firefox

Update 2020-02-23

Although that works just fine, one can use rather the built-in concept of GebConfig.environments, so then in build.gradle there would be:

tasks.withType(Test) {
    systemProperty 'geb.env', project.findProperty('webdriver') ?: 'chrome'
    // [...]
}

Aso, then in the GebConfig.groovy:

environments {
    firefox {
        atCheckWaiting = 1
        driver = { new FirefoxDriver() }
    }
    firefoxHeadless {
        atCheckWaiting = 1
        driver = { customizedFirefoxDriver([headless: true]) }
    }
    chrome {
        driver = { customizedChromeDriver([headless: false]) }
    }
    chromeHeadless {
        driver = { customizedChromeDriver([headless: true]) }
    }
}

With that setup if the gradle project property 'webdriver' is not defined that 'chrome' environment will be used, while when it is defined - an appropriate environment will be picked up, e.g.

gw test -Pwebdriver=firefox

Geb: Finding vs filtering

  • A method $(…​) (or its alias find(…​)) searches in depth, looking for descendants

  • Methods filter(…​) and not(…​) search in breadth, limiting the found content.

Also, a quote from The Book of Geb:

The find() and $() methods support the exact same argument types as the $() function. The filter(), not(), has() and hasNot() methods have the same signatures - they accept: a selector string, a predicate map or both. These methods return a new navigator object that represents the new content.

Questions

  1. Can webdriver access a JS script from the page source?

About

Learn Geb with The-Internet examples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published