0

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"

kriegaex
  • 63,017
  • 15
  • 111
  • 202

1 Answers1

0

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
}
erdi
  • 6,944
  • 18
  • 28
  • thank you @erdi had to do something like this. Although I also found how to solve my problem. I added a check, for example first.navigator.empty || first.value () == values.first But this had to be abandoned, because in case something happens to first, the tests will pass. – acmesun Oct 14 '21 at 07:54