Skip to content

Instantly share code, notes, and snippets.

@aya-eiya
Last active August 2, 2016 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aya-eiya/11205559 to your computer and use it in GitHub Desktop.
Save aya-eiya/11205559 to your computer and use it in GitHub Desktop.
Groovyのちょっとしたこと「Gebによるテストについて」 ref: http://qiita.com/aya_eiya/items/613d4080da9a2bb283d6
package jp.eiya.aya.geb.practice
@Grab('org.gebish:geb-core')
import geb.Page
class CorrectedGoogleTopPage extends Page{
static url = 'https://www.bing.com' // fail
static at = {
title == 'Google'
searchBox.value() == ''
}
static content = {
searchBox {
$('input[type=text]')
}
}
}
import jp.eiya.aya.geb.practice.CorrectedGoogleTopPage as GoogleTopPage
JUnit 4 Runner, Tests: 1, Failures: 1, Time: 1115
Test Failure: a search word can be input(jp.eiya.aya.geb.practice.ThirdTest)
Assertion failed:
title == 'Google'
| |
Bing false
JUnit 4 Runner, Tests: 1, Failures: 1, Time: 1115
Test Failure: a search word can be input(jp.eiya.aya.geb.practice.ThirdTest)
Assertion failed:
title == 'Google'
| |
Bing false
@Grab('org.gebish:geb-core') // 注意:geb-core最新版はorg.codehaus.gebのグループではない
@Grab('org.seleniumhq.selenium:selenium-java')
import geb.Browser
Browser.drive {
go 'https://google.co.jp'
$('input[type=text]').value('groovy')
assert $('input[type=text]').value() == 'groovy'
}
package jp.eiya.aya.geb.practice
@Grab('org.gebish:geb-core')
import geb.Page
class GoogleTopPage extends Page{
static url = 'https://google.co.jp'
static content = {
searchBox {
$('input[type=text]')
}
}
}
@Grab('org.gebish:geb-core')
@Grab('org.gebish:geb-spock')
@Grab('org.seleniumhq.selenium:selenium-java')
import org.openqa.selenium.firefox.FirefoxDriver
import geb.spock.GebSpec
class SecondTest extends GebSpec {
def driver = { new FirefoxDriver() }
def 'a search word can be input'(){
setup:
go 'https://google.co.jp'
when:
$('input[type=text]').value(inputWord)
then:
$('input[type=text]').value() == expectWord
where:
inputWord | expectWord
'groovy' | 'groovy'
}
}
@Grab('org.gebish:geb-core')
@Grab('org.gebish:geb-spock')
@Grab('org.seleniumhq.selenium:selenium-java')
import org.openqa.selenium.firefox.FirefoxDriver
import geb.spock.GebSpec
import jp.eiya.aya.geb.practice.GoogleTopPage
class ThirdTest extends GebSpec {
def driver = { new FirefoxDriver() }
def 'a search word can be input'(){
setup:
to GoogleTopPage
when:
searchBox.value(inputWord)
then:
searchBox.value() == expectWord
where:
inputWord | expectWord
'groovy' | 'groovy'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment