geb-presentasjon-141015140022-conversion-gate02.pdf
-
Upload
sagar-dumaniya -
Category
Documents
-
view
1 -
download
0
Transcript of geb-presentasjon-141015140022-conversion-gate02.pdf
![Page 2: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/2.jpg)
Agenda1. Introduction to Geb
WebDriverTest framework integrationsNavigation APIPage objectsModule objectsContent DSLMultiple Environments
2. Our project-setup
2 / 19
![Page 3: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/3.jpg)
IntroductionAutomating the interaction between web browsers and web contentAcceptance Testing Web ApplicationsScreen scrapingGreat documentation: http://www.gebish.org/manual/current/
3 / 19
![Page 4: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/4.jpg)
Example geb.Browser
Browser.drive { go "http://myapp.com/login"
$("h1").text() == "Please Login"
$("form.login"). { username = "admin" password = "password" login().click() }
$("h1").text() == "Admin Section"}
4 / 19
![Page 5: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/5.jpg)
TechnologyWebDriver (support many browsers)Groovy (remove java-boilerplate)Spock, JUnit or TestNG (easy to integrate with IDE and build systems)Navigator API (jQuery-like content selection)
5 / 19
![Page 6: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/6.jpg)
WebDriverGeb builds on the WebDriver browser automation librarGeb can work with any browser that WebDriver canGeb provides an abstraction layer, but you can access WebDriver directlyGeb never talks to the actual browser.
You need specific driver for each browser you want to work with:
< > < >org.seleniumhq.selenium</ > < >selenium-firefox-driver</ > < >2.20.0</ ></ >
6 / 19
![Page 7: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/7.jpg)
Test framework integrationGeb works with existing popular tools like Spock, JUnit, TestNG andCucumber.You pick what you like; but Geb encurages Spock.
7 / 19
![Page 8: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/8.jpg)
Spock example geb.spock.GebSpec
{
"first result for wikipedia search should be wikipedia"() { given: to GoogleHomePage
expect: at GoogleHomePage
when: search.field.value("wikipedia")
then: waitFor { at GoogleResultsPage } }}
More about Spock @ https://code.google.com/p/spock/ 8 / 19
![Page 9: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/9.jpg)
Navigator APIInspired by jQuery.Content is selected via the $ function, which returns a Navigator objectMakes it super easy to select content
// match all 'div' elements on the page$("div")
// match the first 'div' element on the page$("div", 0)
// match all 'div' elements with a title attribute value of 'section'$("div", title: "section")
// The parent of the first paragraph$("p", 0).parent()
//<div>foo</div>$("div", text: "foo")
// Using patterns$("p", text: ~/p./).size() == 2$("p", text: startsWith("p")).size() == 2
http://www.gebish.org/manual/current/intro.html#the_jquery_ish_navigator_api 9 / 19
![Page 10: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/10.jpg)
Page ObjectsLess fragile code with better abstractions and modellingPromotes resuseMakes it easier to write testsPages (and modules) can be arranged in inheritance hierarchies.
Within your web app’s UI there are areas that your tests interact with. APage Object simply models these as objects within the test code. This reducesthe amount of duplicated code and means that if the UI changes, the fix needonly be applied in one place. (webdriver...)
10 / 19
![Page 11: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/11.jpg)
Page Objects: example {
url = "/login" at = { title == "Login to our super page" } content = { loginButton(to: AdminPage) { $("input", type: "submit", name: "login") } }}
{ at = { assert $("h1").text() == "Admin Page" }}
Browser.drive { to LoginPage loginButton.click() at AdminPage}
to changes the browser’s page instance.click on login-button changes page to the "Admin page"at explicitly asserts that we are on the expected page
11 / 19
![Page 12: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/12.jpg)
Module ObjectsReusable fragments that can be used across pagesUseful for modelling things like UI widgets that are used across multiplepagesWe can define a Navigator context when including the module in a Page.Module will then only see "its own part" of the dom via the navigator api
12 / 19
![Page 13: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/13.jpg)
Module Objects: example {
content = { button { $("input", type: "submit") } }}
{ content = { theModule { module ExampleModule } }}
Browser.drive { to ExamplePage theModule.button.click()}
13 / 19
![Page 14: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/14.jpg)
Content DSLContent definitions can build upon each other.Content definitions are actually templates.
{ content = { results { $("li.g") } result { i -> results[i] } resultLink { i -> result(i).find("a.l", 0) } firstResultLink { resultLink(0) } }}
Optional Content
{ content = { errorMsg(required: ) { $("p.errorMsg") } }}
14 / 19
![Page 15: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/15.jpg)
Dynamic content {
content = { linkTotrigger {$("a"} awesomeContainer(required: ) { $("div.awesome") } }}
Browser.drive { to DynamicPage linkTotrigger.click() waitFor { awesomeContainer }}
By default, it will look for it every 100ms for 5s before giving up.
15 / 19
![Page 16: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/16.jpg)
Multiple EnvironmentsThe Groovy ConfigSlurper mechanism has built in support forenvironment sensitive configuration
system property to determine the environment to use
remoteDriver = {..}driver = { FirefoxDriver() }baseUrl = "http://iad.finn.no:3002/"iadUrl = "http://dev.finn.no"
environments { 'dev' { baseUrl = "http://dev.finn.no/talent/" iadUrl = "http://dev.finn.no" driver = remoteDriver } 'prod' { baseUrl = "http://www.finn.no/talent/" iadUrl = "http://www.finn.no" driver = remoteDriver }}
16 / 19
![Page 17: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/17.jpg)
Our project-setupKjører tester lokalt mot lokal serverKan kjøre tester som en del av maven-bygget
men valgt å ikke gjøre dette siden vi er avhengig av finndev-login-tjensten
Sparker i gang en testkjøring mot dev straks en ny artifakt er deployet idev.
17 / 19
![Page 18: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/18.jpg)
FINN.no :: TestreportsJUnit-listner that intgrates Geb with http://testreports.finn.noSupport @Tags annotationGives status and screenshots for each testEasy setup with the maven-surfire-plugin
< > < >org.apache.maven.plugins</ > < >maven-surefire-plugin</ > < >2.16</ > < > < > < >**/*Spec.*</ > </ > < > < >target/test-reports/geb</ > < >${artifactId}</ > </ > < > < > < >listener</ > < >no.finntech.test.report.runner.GebTestReportRunListener</ > </ > </ > 18 / 19
![Page 19: geb-presentasjon-141015140022-conversion-gate02.pdf](https://reader036.fdocuments.us/reader036/viewer/2022072008/55cf901a550346703ba30390/html5/thumbnails/19.jpg)
Demo time
19 / 19