GEB and Spock Training

I am a manual tester trying to learn GEB and Spock. To find out about this, should I have prior knowledge of java or groovy? I read a GEB book, what are the background, books or learning resources? Please help. Thanks.

+8
testing groovy automated-tests spock geb
source share
1 answer

I tried compiling some things and some “good to use”, which I found very useful when I took Geb.

  • A bit of Groovy Magic . Most of what you need to learn Groovy is described in this guide, but for obvious reasons, if you're obsessed with the language, you can consider Groovy in action . Although Java is not required to build Groovy, if you work with Java (except for closures) or even with a Python background, you can probably skip the tutorial for 15 minutes and you are already there).

  • Little selenium. The bigger the better, but don't be afraid, this single page tells you everything you need to know about the Selenium Webdriver that you usually use. But to emphasize, the more the better.

  • jQuery selectors (everyone says it's easy, but frankly, I turn to the guide at least twice an hour. I'm stupid, so ...). If you are new to jQuery, you need to start with the main selectors and click on the left navigation menu again. Note that not all jQuery selectors are applicable for Geb, but the Geb tutorial selector section was not very comprehensive and attractive.

  • At the end of my test boxes, I need to create a fancy report that extends to several test boxes, and I had dependencies between the test tests. So, instead of Spock, I went TestNG . Honestly, I did not give Spock a lot of chances.

  • PageObjects is not really a prerequisite for Geb, but PageObjects are so amazing that you never wanted to think about Geb outside of This. PageObjects is a nice little template that says that you attach the structure of your HTML page to an object so that the actual test doesn't touch it. Hah Gotcha. Let me say this in plain English.

Let's say you have a registration form with an input text field with the identifier "nametext". How do you get a text field handle? In terms of the DOM, in javascript, you just do

document.getElementById("nametext") 

In Selenium you would do a very similar thing

  driver.findElement(By.id("nametext")) 

So, if you want to fill in Jason in your text box in Selenium, you would do

 driver.findElement(By.id("nametext")).sendKeys("Jason"); 

If you do this for all of your input fields, very soon your test cases will become ugly and hateful. Instead, in terms of OO, you encapsulate. You create a new class, say RegistrationPage and wrap your findElement and sendKeys , as in:

 public class RegistrationPage{ … public RegistrationPage fillRegistrationForm(String name, String email){ driver.findElement(By.id("nametext")).sendKeys(name); driver.findElement(By.id("emailtext")).sendKeys(email); } } 

and from your test register, you would say

  RegistrationPage regPage=new RegistrationPage(); regPage.fillRegistrationForm("Jason","jason@bourne.com"); 

(An even better idea is to wrap your input values ​​in a class and pass it to fillRegistrationForm)

In fact, Geb makes better use of PageObjects - jQuery selectors to save

 class InputFormPage extends Page{ … static content={ name {$("input", id:"entry_0")} emailAddress {$("input", id:"entry_1")} } } 

and in your test file you just say

  name.value ("Jason") emailAddress.value ("jason@bourne.com") 
+28
source share

All Articles