Functional testing your Grails app with GEB
-
Upload
gr8conf -
Category
Technology
-
view
1.045 -
download
7
description
Transcript of Functional testing your Grails app with GEB
gr8conf.eu
4/6/2014ColinHarrington
Whatisit?
(pronounced"jeb")
http://www.gebish.orghttps://github.com/geb/geb
=
Webdriver+
Groovy+
JQuerylikeContentSelector+
PageObjectmodel
Startedin2009byLukeDaley
v0.1in2010
0.9.2=current
Justlikewinter,
1.0iscoming.
Testing!
Screenscraping
Automating
SeleniumSeleniumRCSelenium2.0akaWebDriverSeleniumGrid
SeleniumRC<WebDriver
Code->Driving->RealBrowser
{Chrome,Firefox,InternetExploder,Safari,PhantomJS,HtmlUnit,Android,iOS,Remote}
//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
http://grails.org/plugin/geb
compile":geb:0.9.2"
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
http://github.com/geb/geb-example-grails
$(«cssselector»,«indexorrange»,«attribute/textmatchers»)
$("a",class:"brand")
$("div.some-classp:first[title='something']")
$("div.footer").find(".copyright")
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()}
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"}
Special'js'objectreadglobalscope
js."document.title"=="BookofGeb"
js.gloallyVisibleJavascriptFunction(1,2)
js.exec()ExecutesarbitraryCode
js.exec(1,2,"returnarguments[0]+arguments[1];")==3
Built-inSupportforjQuery
js.exec'jQuery("div#a").mouseover();'
isequivalentto:
$("div#a").jquery.mouseover()
Directdownloading
alert(),confirm()support
Multiplewindows
UntrustedCertificatehandling
DirectDriverinteraction
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")}
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
ThinkTemplates
Reusablemodulesthatexistacrossmultiplepagehierarchies.Headerpanel
classExampleModuleextendsModule{staticcontent={button{$("input",type:"submit")}}}
classExamplePageextendsPage{staticcontent={theModule{moduleExampleModule}}}
ScreenshotAndPageSourceReporter
Browser.drive{reportGroup"google"go"http://google.com"report"homepage"reportGroup"wikipedia"go"http://wikipedia.org"report"homepage"}
ReportsdirListenerscleanReportGroupDir()
/target/test-reports/geb/
${grails.project.test.reports.dir}/geb
Example
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/
https://saucelabs.com/
BrowserTesting,Mobileweb-apptesting.
Video&screenshotsupportDesktop&MobilesupportBehindthefirewalltunnelling
https://saucelabs.com/platforms
Goodluck
MarcinErdmann@marcinerdmann
https://skillsmatter.com/skillscasts/4764-advanced-geb
TomasLin@TomasLin
http://fbflex.wordpress.com/2011/12/01/a-script-to-run-grails-functional-tests-in-parallel/
PartitioningXVFB=XVirtualFrameBuffer
Grailsplugin:
compile":remote-control:1.5"
http://grails.org/plugin/remote-control
http://www.sikuli.org/
http://fbflex.wordpress.com/2012/10/27/geb-and-sikuli/
Others?
Thankyou