Functional testing your Grails app with GEB

34
gr8conf.eu 4/6/2014 Colin Harrington

description

GEB (pronounced 'jeb') 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. We'll cover what it takes to test your grails application with GEB and discuss successful strategies and drawbacks about the tool.

Transcript of Functional testing your Grails app with GEB

Page 1: Functional testing your Grails app with GEB

gr8conf.eu

4/6/2014ColinHarrington

Page 2: Functional testing your Grails app with GEB

ColinHarrington@ColinHarrington

[email protected]

PrincipalConsultant

Page 3: Functional testing your Grails app with GEB

Whatisit?

Page 4: Functional testing your Grails app with GEB

(pronounced"jeb")

http://www.gebish.orghttps://github.com/geb/geb

Page 5: Functional testing your Grails app with GEB

=

Webdriver+

Groovy+

JQuerylikeContentSelector+

PageObjectmodel

Page 6: Functional testing your Grails app with GEB

Startedin2009byLukeDaley

v0.1in2010

0.9.2=current

Justlikewinter,

1.0iscoming.

Page 7: Functional testing your Grails app with GEB

Testing!

Screenscraping

Automating

Page 8: Functional testing your Grails app with GEB

SeleniumSeleniumRCSelenium2.0akaWebDriverSeleniumGrid

SeleniumRC<WebDriver

Page 9: Functional testing your Grails app with GEB

Code->Driving->RealBrowser

{Chrome,Firefox,InternetExploder,Safari,PhantomJS,HtmlUnit,Android,iOS,Remote}

Page 10: Functional testing your Grails app with GEB

//Createanewinstanceofthehtmlunitdriver//Noticethattheremainderofthecodereliesontheinterface,//nottheimplementation.WebDriverdriver=newHtmlUnitDriver();

//AndnowusethistovisitGoogledriver.get("http://www.google.com");

//FindthetextinputelementbyitsnameWebElementelement=driver.findElement(By.name("q"));

//Entersomethingtosearchforelement.sendKeys("Cheese!");

//Nowsubmittheform.WebDriverwillfindtheformforusfromtheelementelement.submit();

//CheckthetitleofthepageSystem.out.println("Pagetitleis:"+driver.getTitle());

driver.quit();

https://code.google.com/p/selenium/wiki/GettingStarted

Page 11: Functional testing your Grails app with GEB

http://grails.org/plugin/geb

compile":geb:0.9.2"

Page 12: Functional testing your Grails app with GEB

BuildConfig.groovy

dependencies{test("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion")test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion")//Youusuallyonlyneedoneofthese,butthisprojectusesbothtest"org.gebish:geb-spock:$gebVersion"test"org.gebish:geb-junit4:$gebVersion"}

GebConfig.groovy

driver={newChromeDriver()}

environments{//runas“grails-Dgeb.env=chrometest-app”//See:http://code.google.com/p/selenium/wiki/ChromeDriverchrome{driver={newChromeDriver()}}//runas“grails-Dgeb.env=firefoxtest-app”//See:http://code.google.com/p/selenium/wiki/FirefoxDriverfirefox{driver={newFirefoxDriver()}}}

http://www.gebish.org/manual/current/all.html#grails

Page 13: Functional testing your Grails app with GEB

http://github.com/geb/geb-example-grails

Page 14: Functional testing your Grails app with GEB

$(«cssselector»,«indexorrange»,«attribute/textmatchers»)

$("a",class:"brand")

$("div.some-classp:first[title='something']")

$("div.footer").find(".copyright")

Page 15: Functional testing your Grails app with GEB

click()

SendingKeystokes:$("input",name:firstName)<<asdf$("input",name:"firstName")<<Keys.chord(Keys.CONTROL,"c")

WebDriverAPIdirectly:Actions,DragandDrop,interact{...}

Control-click,etc.

interact{clickAndHold($('#element'))moveByOffset(400,-150)release()}

Page 16: Functional testing your Grails app with GEB

waitFor{}//usedefaultconfiguration

//waitforupto10seconds,usingthedefaultretryintervalwaitFor(10){}

//waitforupto10seconds,waitinghalfasecondinbetweenretrieswaitFor(10,0.5){}

//usethepreset“quick”asthewaitsettingswaitFor("quick"){}

Browser.drive{$("input",value:"MakeRequest")waitFor{$("div#result").present}assert$("div#result").text()=="TheResult"}

Page 17: Functional testing your Grails app with GEB

Special'js'objectreadglobalscope

js."document.title"=="BookofGeb"

js.gloallyVisibleJavascriptFunction(1,2)

js.exec()ExecutesarbitraryCode

js.exec(1,2,"returnarguments[0]+arguments[1];")==3

Page 18: Functional testing your Grails app with GEB

Built-inSupportforjQuery

js.exec'jQuery("div#a").mouseover();'

isequivalentto:

$("div#a").jquery.mouseover()

Page 19: Functional testing your Grails app with GEB

Directdownloading

alert(),confirm()support

Multiplewindows

UntrustedCertificatehandling

DirectDriverinteraction

Page 20: Functional testing your Grails app with GEB

classGoogleHomePageextendsPage{

staticurl="http://google.com/?complete=0"

staticat={title=="Google"}

staticcontent={searchField{$("input[name=q]")}searchButton(to:GoogleResultsPage){$("input[value='GoogleSearch']")}}voidsearch(StringsearchTerm){searchField.valuesearchTermsearchButton.click()}}

classGoogleResultsPageextendsPage{...}

Browser.drive{toGoogleHomePagesearch"ChuckNorris"

atGoogleResultsPageresultLink(0).text().contains("Chuck")}

Page 21: Functional testing your Grails app with GEB

classGoogleHomePageextendsPage{staticurl="http://google.com/?complete=0"staticat={title=="Google"}staticcontent={searchField{$("input[name=q]")}searchButton(to:GoogleResultsPage){$("input[value='GoogleSearch']")}}voidsearch(StringsearchTerm){searchField.valuesearchTermsearchButton.click()}}

Accessibleviapage.searchField

Page 22: Functional testing your Grails app with GEB

ThinkTemplates

Reusablemodulesthatexistacrossmultiplepagehierarchies.Headerpanel

classExampleModuleextendsModule{staticcontent={button{$("input",type:"submit")}}}

classExamplePageextendsPage{staticcontent={theModule{moduleExampleModule}}}

Page 23: Functional testing your Grails app with GEB

ScreenshotAndPageSourceReporter

Browser.drive{reportGroup"google"go"http://google.com"report"homepage"reportGroup"wikipedia"go"http://wikipedia.org"report"homepage"}

ReportsdirListenerscleanReportGroupDir()

Page 24: Functional testing your Grails app with GEB

/target/test-reports/geb/

${grails.project.test.reports.dir}/geb

Example

Page 25: Functional testing your Grails app with GEB

InstallandruntheRemoteWebDriverclient/serverOpensaportlistensforcommands

http://www.objectpartners.com/2012/04/24/start-building-out-automated-groovy-mobile-web-application-testing-on-your-iphone-or-

ipad-with-geb-and-spock/

Page 26: Functional testing your Grails app with GEB

https://saucelabs.com/

BrowserTesting,Mobileweb-apptesting.

Video&screenshotsupportDesktop&MobilesupportBehindthefirewalltunnelling

https://saucelabs.com/platforms

Page 27: Functional testing your Grails app with GEB

Goodluck

Page 28: Functional testing your Grails app with GEB

MarcinErdmann@marcinerdmann

https://skillsmatter.com/skillscasts/4764-advanced-geb

Page 29: Functional testing your Grails app with GEB

TomasLin@TomasLin

http://fbflex.wordpress.com/2011/12/01/a-script-to-run-grails-functional-tests-in-parallel/

Page 30: Functional testing your Grails app with GEB

PartitioningXVFB=XVirtualFrameBuffer

Page 31: Functional testing your Grails app with GEB

Grailsplugin:

compile":remote-control:1.5"

http://grails.org/plugin/remote-control

Page 32: Functional testing your Grails app with GEB

http://www.sikuli.org/

http://fbflex.wordpress.com/2012/10/27/geb-and-sikuli/

Others?

Page 33: Functional testing your Grails app with GEB
Page 34: Functional testing your Grails app with GEB

Thankyou