Geb - Doesn't work attr. required (groovy test)

74 Views Asked by At

I create tests (groovy, geb). I have something like this :

class test extends Module {
  static content = {
    first{ $("input", id: "one") }
    second(required: false) { $("input", id: "two") }
    third(required: false) { $("input", id: "three") } }
 
  def setNewValues(def newValues) {
    first.value(newValues.first)
    second.value(newValues.second)
    third.value(newValues.third)
  }
 
  def assertingValues(def values) { 
    assert first.value() == values.first 
    assert second.value() == values.second
    assert third.value() == values.third  
  }
}

It is the common module to different composite modules. And in different cases module can have only first input, or first and second, or first and third. Can I reuse my setNewValues and assertingValues methods for modules with different composition?

If I try to use my methods, I get "This operation is not supported on an empty navigator based geb.module.Checkbox module"

1

There are 1 best solutions below

1
erdi On

Personally I would model the modules as different classes if they contain different content - what you are trying to do feels too generic and overly smart but I might not have the full context to understand why you are approaching it this way. If you insist on doing it this way, though, then you could wrap usages of the optional content with if statements, i.e.

if (second) {
    second.value(newValues.second)
}

and

if (second) {
    assert second.value() == values.second
}