43742

Using Spock Data Tables to Test Geb Page Objects

Question:

Full Disclosure: I'm very new to both Geb and Spock.

As part of a test suite I'm working on, we have to test run the same test on several page elements. I would love to be able to abstract this behavior using a Spock data-table. However, when I do this, Geb complains that it doesn't recognize the page property.

Here is a bare-bones example of what I'm talking about:

when: textBox = value submit() then:"value is updated" at SuccessPage textBox == value where: textBox | value box1 | val1 box2 | val2 box3 | val3

In this example, boxes 1-3 are defined in the <em>content</em> object of a <em>Page</em>.

These tests work when I do them independently, but not when I use a data table. Why isn't the Geb element getting substituted correctly?

Answer1:

Data tables are executed outside of the context of the test for which they are specified. They have to be executed that way to know how to actually construct multiple iterations of your test based on them. In that context box1 does not point to a page property as you're browser is not yet pointing at SuccessPage.

To get around it you will need to use content names (which will be instances of String) and resolve them as properties of the page when you are in the right context:

when: page."$textBox" = value submit() then:"value is updated" at SuccessPage page."$textBox" == value where: textBox | value 'box1' | val1 'box2' | val2 'box3' | val3

Recommend

  • Softlayer REST API for tagging machines
  • Can an objective C method signature specify an enum type?
  • Any method to denote object assignment?
  • How to highlight calls to object methods and user-created functions? (SublimeText, python)
  • Starting mysql in new EC2 instance throws “can't connect through socket” error
  • Angular forms and password managers
  • code crashing when finding the eldest age (Edit) [closed]
  • What's the difference between var and _var in Rust?
  • c++ vector of class object pointers
  • Git + Smart HTTP problems (cannot push/pull)
  • oAuth and Codeigniter with MongoDB
  • NSCell with divisions
  • php: efficiently running functions with one-time loaded classes multiple times in optional files
  • Different block behavior between debug and release configuration
  • Skin detection in the CIELab and HSV color space
  • asp.net login page issue
  • Trying find how to cancel TabControl.SelectionChanged in silverlight
  • Unity3d - How to make method calling from another class that belongs to another game object efficien
  • Why do I need to force git to sync my remote repository?
  • WCF REST Service returns HTTP 400 Bad Request
  • How to make a local git repository that mirrors an upstream repository?
  • Send multimedia commands
  • How to save dynamically created textboxes and their values
  • Symfony 2 error page response
  • C#: Import/Export Settings into/from a File
  • Which open source license has no forking [closed]
  • abstracting over a collection
  • Salesforce Different WSDL files and when to use
  • How to add a focus style to an editable ComboBox in WPF
  • Invalid object name 'dbo.Item'
  • How to revert to previous XCode version?
  • Alternative to overridePendingTransition() - Android
  • Email format validation in mvc3 view
  • How do I fake an specific browser client when using Java's Net library?
  • How to get a value (ex: baseURL) in every Karate feature?
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • javascript inside java/jsp code
  • How to get next/previous record number?
  • Confusion with PayPal's monthly billing cycle
  • Checking variable from a different class in C#