How to take screenshots in a module in geb

2.3k views Asked by At

Hi we run Geb tests on the Spock framework. I am trying to take a screenshot in a module using report "Screenshot". It does not recognize the report function as it does on a Spec. How should I go about taking screenshots in a module.

Here is a example code which is in a module.

try{
    $(By.xpath("//button[@ng-click=\"ok()\"]")).click()
   }
catch (Throwable t){
                                                                  failures.add("\n Could not click on the Ok button after the Ticket created successfully message appeared")

report "Failure"
}
2

There are 2 answers

1
erdi On

The report() method is available on Browser class and an instance of that class is available as browser property inside of modules, so you can call it from within a module using:

browser.report("Failure")
0
Jascha On

Use the parent class GebReportingSpec (instead of GebSpec) to create a report of all your tests.

When you only want a screenshot of failing tests, use the config value reportOnTestFailureOnly=true in your GebConfig.groovy