+ All Categories
Home > Software > Groovy Browser Automation

Groovy Browser Automation

Date post: 02-Jul-2015
Category:
Upload: spring-io
View: 1,474 times
Download: 0 times
Share this document with a friend
Description:
Speaker: Colin Harrington 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.
34
SpringOne2GX 2014 Colin Harrington
Transcript
Page 1: Groovy Browser Automation

SpringOne2GX

2014ColinHarrington

Page 2: Groovy Browser Automation

ColinHarrington@ColinHarrington

[email protected]

PrincipalConsultant

Page 3: Groovy Browser Automation

Whatisit?

Page 4: Groovy Browser Automation

(pronounced"jeb")

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

Page 5: Groovy Browser Automation

=

Webdriver+

Groovy+

JQuerylikeContentSelector+

PageObjectmodel

Page 6: Groovy Browser Automation

Startedin2009byLukeDaley

v0.1in2010

0.9.3=current

Justlikewinter,

1.0iscoming.

Page 7: Groovy Browser Automation

Testing!

Screenscraping

Automating

Page 8: Groovy Browser Automation

SeleniumSeleniumRCSelenium2.0akaWebDriverSeleniumGrid

SeleniumRC<WebDriver

Page 9: Groovy Browser Automation

Code->Driving->RealBrowser

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

Page 10: Groovy Browser Automation

//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: Groovy Browser Automation

http://grails.org/plugin/geb

compile":geb:0.9.2"

Page 12: Groovy Browser Automation

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

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

Page 14: Groovy Browser Automation

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

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

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

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

Page 15: Groovy Browser Automation

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

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

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

Built-inSupportforjQuery

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

isequivalentto:

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

Page 19: Groovy Browser Automation

Directdownloading

alert(),confirm()support

Multiplewindows

UntrustedCertificatehandling

DirectDriverinteraction

Page 20: Groovy Browser Automation

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

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

ThinkTemplates

Reusablemodulesthatexistacrossmultiplepagehierarchies.Headerpanel

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

classExamplePageextendsPage{staticcontent={theModule{moduleExampleModule}}}

Page 23: Groovy Browser Automation

ScreenshotAndPageSourceReporter

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

ReportsdirListenerscleanReportGroupDir()

Page 24: Groovy Browser Automation

/target/test-reports/geb/

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

Example

Page 25: Groovy Browser Automation

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

https://saucelabs.com/

BrowserTesting,Mobileweb-apptesting.

Video&screenshotsupportDesktop&MobilesupportBehindthefirewalltunnelling

https://saucelabs.com/platforms

Page 27: Groovy Browser Automation

Goodluck

Page 28: Groovy Browser Automation

MarcinErdmann@marcinerdmann

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

Page 29: Groovy Browser Automation

TomasLin@TomasLin

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

Page 30: Groovy Browser Automation

PartitioningXVFB=XVirtualFrameBuffer

Page 31: Groovy Browser Automation

Grailsplugin:

compile":remote-control:1.5"

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

Page 32: Groovy Browser Automation

http://www.sikuli.org/

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

Others?

Page 33: Groovy Browser Automation
Page 34: Groovy Browser Automation

Thankyou


Recommended