gr8conf.eu	
4/6/2014
Colin	Harrington
Colin	Harrington
@ColinHarrington
colin.harrington@objectpartners.com
Principal	Consultant
What	is	it?
(pronounced	"jeb")
http://www.gebish.org
https://github.com/geb/geb
=
Webdriver	
+
Groovy	
+
JQuery	like	Content	Selector
+
Page	Object	model
Started	in	2009	by	Luke	Daley	
v0.1	in	2010
0.9.2	=	current
Just	like	winter,	
1.0	is	coming.
Testing!
Screen	scraping
Automating
Selenium
Selenium	RC
Selenium	2.0	aka	WebDriver
Selenium	Grid
Selenium	RC			<			WebDriver
Code	->	Driving	->	Real	Browser
{	Chrome,	Firefox,	Internet	Exploder,	
Safari,	PhantomJS,	HtmlUnit,	
Android,	iOS,	Remote	}
//	Create	a	new	instance	of	the	html	unit	driver
//	Notice	that	the	remainder	of	the	code	relies	on	the	interface,	
//	not...
http://grails.org/plugin/geb
compile	":geb:0.9.2"
BuildConfig.groovy
dependencies	{
				test("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion")
				test("or...
http://github.com/geb/geb-example-grails
$(«css	selector»,	«index	or	range»,	«attribute	/	text	matchers»)
$("a",	class:	"brand")	
$("div.some-class	p:first[title='...
click()	
Sending	Keystokes:
$("input",	name:	firstName)	<<	asdf
$("input",	name:	"firstName")	<<	Keys.chord(Keys.CONTROL,	"c...
waitFor	{}	//	use	default	configuration
//	wait	for	up	to	10	seconds,	using	the	default	retry	interval
waitFor(10)	{}	
//	...
Special	'js'	object
read	global	scope
js."document.title"	==	"Book	of	Geb"	
js.gloallyVisibleJavascriptFunction(1,2)
js.ex...
Built-in	Support	for	jQuery
js.exec	'jQuery("div#a").mouseover();'	
is	equivalent	to:	
$("div#a").jquery.mouseover()
Direct	downloading
alert(),	confirm()	support
Multiple	windows
Untrusted	Certificate	handling
Direct	Driver	interaction
class	GoogleHomePage	extends	Page	{
				static	url	=	"http://google.com/?complete=0"
				static	at	=	{	title	==	"Google"	}...
class	GoogleHomePage	extends	Page	{
				static	url	=	"http://google.com/?complete=0"
				static	at	=	{	title	==	"Google"	}...
Think	Templates
Reusable	modules	that	exist	across	multiple	page	hierarchies.
Header	panel
class	ExampleModule	extends	Mod...
ScreenshotAndPageSourceReporter
Browser.drive	{
				reportGroup	"google"
				go	"http://google.com"
				report	"home	page"...
/target/test-reports/geb/
${grails.project.test.reports.dir}/geb
Example
Install	and	run	the	Remote	WebDriver	client/server
Opens	a	port
listens	for	commands
http://www.objectpartners.com/2012/04...
https://saucelabs.com/
Browser	Testing,	
Mobile	web-app	testing.
Video	&	screenshot	support
Desktop	&	Mobile	support
Behin...
Good	luck
Marcin	Erdmann
@marcinerdmann
https://skillsmatter.com/skillscasts/4764-advanced-geb
Tomas	Lin
@TomasLin
http://fbflex.wordpress.com/2011/12/01/a-script-to-run-grails-functional-
tests-in-parallel/
Partitioning
XVFB	=	X	Virtual	Frame	Buffer
Grails	plugin:
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?
Thank	you
Functional testing your Grails app with GEB
Upcoming SlideShare
Loading in...5
×

Functional testing your Grails app with GEB

1,511

Published on

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.

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,511
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
31
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Functional testing your Grails app with GEB

  1. 1. gr8conf.eu 4/6/2014 Colin Harrington
  2. 2. Colin Harrington @ColinHarrington colin.harrington@objectpartners.com Principal Consultant
  3. 3. What is it?
  4. 4. (pronounced "jeb") http://www.gebish.org https://github.com/geb/geb
  5. 5. = Webdriver + Groovy + JQuery like Content Selector + Page Object model
  6. 6. Started in 2009 by Luke Daley v0.1 in 2010 0.9.2 = current Just like winter, 1.0 is coming.
  7. 7. Testing! Screen scraping Automating
  8. 8. Selenium Selenium RC Selenium 2.0 aka WebDriver Selenium Grid Selenium RC < WebDriver
  9. 9. Code -> Driving -> Real Browser { Chrome, Firefox, Internet Exploder, Safari, PhantomJS, HtmlUnit, Android, iOS, Remote }
  10. 10. // Create a new instance of the html unit driver // Notice that the remainder of the code relies on the interface, // not the implementation. WebDriver driver = new HtmlUnitDriver(); // And now use this to visit Google driver.get("http://www.google.com"); // Find the text input element by its name WebElement element = driver.findElement(By.name("q")); // Enter something to search for element.sendKeys("Cheese!"); // Now submit the form. WebDriver will find the form for us from the element element.submit(); // Check the title of the page System.out.println("Page title is: " + driver.getTitle()); driver.quit(); https://code.google.com/p/selenium/wiki/GettingStarted
  11. 11. http://grails.org/plugin/geb compile ":geb:0.9.2"
  12. 12. BuildConfig.groovy dependencies { test("org.seleniumhq.selenium:selenium-chrome-driver:$seleniumVersion") test("org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion") // You usually only need one of these, but this project uses both test "org.gebish:geb-spock:$gebVersion" test "org.gebish:geb-junit4:$gebVersion" } GebConfig.groovy driver = { new ChromeDriver() } environments { // run as “grails -Dgeb.env=chrome test-app” // See: http://code.google.com/p/selenium/wiki/ChromeDriver chrome { driver = { new ChromeDriver() } } // run as “grails -Dgeb.env=firefox test-app” // See: http://code.google.com/p/selenium/wiki/FirefoxDriver firefox { driver = { new FirefoxDriver() } } } http://www.gebish.org/manual/current/all.html#grails
  13. 13. http://github.com/geb/geb-example-grails
  14. 14. $(«css selector», «index or range», «attribute / text matchers») $("a", class: "brand") $("div.some-class p:first[title='something']") $("div.footer").find(".copyright")
  15. 15. click() Sending Keystokes: $("input", name: firstName) << asdf $("input", name: "firstName") << Keys.chord(Keys.CONTROL, "c") WebDriver API directly: Actions, Drag and Drop, interact {...} Control-click, etc. interact { clickAndHold($('#element')) moveByOffset(400, -150) release() }
  16. 16. waitFor {} // use default configuration // wait for up to 10 seconds, using the default retry interval waitFor(10) {} // wait for up to 10 seconds, waiting half a second in between retries waitFor(10, 0.5) {} // use the preset “quick” as the wait settings waitFor("quick") {} Browser.drive { $("input", value: "Make Request") waitFor { $("div#result").present } assert $("div#result").text() == "The Result" }
  17. 17. Special 'js' object read global scope js."document.title" == "Book of Geb" js.gloallyVisibleJavascriptFunction(1,2) js.exec() Executes arbitrary Code js.exec(1, 2, "return arguments[0] + arguments[1];") == 3
  18. 18. Built-in Support for jQuery js.exec 'jQuery("div#a").mouseover();' is equivalent to: $("div#a").jquery.mouseover()
  19. 19. Direct downloading alert(), confirm() support Multiple windows Untrusted Certificate handling Direct Driver interaction
  20. 20. class GoogleHomePage extends Page { static url = "http://google.com/?complete=0" static at = { title == "Google" } static content = { searchField { $("input[name=q]") } searchButton(to: GoogleResultsPage) { $("input[value='Google Search']") } } void search(String searchTerm) { searchField.value searchTerm searchButton.click() } } class GoogleResultsPage extends Page { ... } Browser.drive { to GoogleHomePage search "Chuck Norris" at GoogleResultsPage resultLink(0).text().contains("Chuck") }
  21. 21. class GoogleHomePage extends Page { static url = "http://google.com/?complete=0" static at = { title == "Google" } static content = { searchField { $("input[name=q]") } searchButton(to: GoogleResultsPage) { $("input[value='Google Search']") } } void search(String searchTerm) { searchField.value searchTerm searchButton.click() } } Accessible via page.searchField
  22. 22. Think Templates Reusable modules that exist across multiple page hierarchies. Header panel class ExampleModule extends Module { static content = { button { $("input", type: "submit") } } } class ExamplePage extends Page { static content = { theModule { module ExampleModule } } }
  23. 23. ScreenshotAndPageSourceReporter Browser.drive { reportGroup "google" go "http://google.com" report "home page" reportGroup "wikipedia" go "http://wikipedia.org" report "home page" } Reports dir Listeners cleanReportGroupDir()
  24. 24. /target/test-reports/geb/ ${grails.project.test.reports.dir}/geb Example
  25. 25. Install and run the Remote WebDriver client/server Opens a port listens for commands 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/
  26. 26. https://saucelabs.com/ Browser Testing, Mobile web-app testing. Video & screenshot support Desktop & Mobile support Behind the firewall tunnelling https://saucelabs.com/platforms
  27. 27. Good luck
  28. 28. Marcin Erdmann @marcinerdmann https://skillsmatter.com/skillscasts/4764-advanced-geb
  29. 29. Tomas Lin @TomasLin http://fbflex.wordpress.com/2011/12/01/a-script-to-run-grails-functional- tests-in-parallel/
  30. 30. Partitioning XVFB = X Virtual Frame Buffer
  31. 31. Grails plugin: compile ":remote-control:1.5" http://grails.org/plugin/remote-control
  32. 32. http://www.sikuli.org/ http://fbflex.wordpress.com/2012/10/27/geb-and-sikuli/ Others?
  33. 33. Thank you
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×