Getting started

Nozomi Ito edited this page Oct 16, 2017 · 28 revisions

The set up step to use Sahagin-Groovy with Geb.

1. sahagin-groovy.jar dependency

Unlike Sahagin-Java, Sahagin-Groovy does not require any additional JVM argument.

If you use Gradle

Add dependency to your build.gradle file.

dependencies {
    // use the current latest version
    compile 'org.sahagin:sahagin-groovy:0.10.1'
}

If you use Maven

Add dependency to your pom.xml file.

<dependencies>
  <dependency>
    <groupId>org.sahagin</groupId>  
    <artifactId>sahagin-groovy</artifactId>  
    <!-- use the current latest version --> 
    <version>0.10.1</version>
  </dependency>
</dependencies>

2. Add annotations and options

Add @PageDoc annotations to your Geb page object class declarations, and define testDoc for each page object content in "contentTestDoc" field.

import geb.Page
import org.sahagin.runlib.external.PageDoc
import org.sahagin.runlib.external.TestDoc

@PageDoc("Contact page")
class ContactPage extends Page {
    static url = "...."
    static content = {
        name { $(name: "your-name") }
        mail { $(name: "your-mail") }
        ....
    }
    static contentTestDoc = {
        name { "name" }
        mail { "mail address" }
        ....
    }

    ....
}

You can also add @TestDoc annotations to test methods just like Sahagin-Java, see 2. Add annotations of Sahagin-Java.

Content DSLs without contentTestDoc, or classes or methods without the annotations, are also displayed on the Sahagin report, so you don't need to add them to all your content DSLs, classes and methods.

3. Screen capture set up

To take screen captures, call GebAdapter.setAdapter method with Geb Browser instance used in each test at Spock setup method or JUnit4 @Before method or other test set up method.

The following code is Geb and Spock example:

import geb.spock.GebSpec
import org.sahagin.groovy.runlib.external.adapter.geb.GebAdapter

class SampleSpec extends GebSpec {

    def setup() {
        GebAdapter.setAdapter(getBrowser())
    }

    ....
}

and the following code is Geb and JUnit4 example:

import geb.junit4.GebTest
import org.sahagin.groovy.runlib.external.adapter.geb.GebAdapter

class SampleSpec extends GebTest {

    @Before
    void setUp() {
        GebAdapter.setAdapter(getBrowser())
    }

    ....
}

4. Create configuration file sahagin.yml

Create a file "sahagin.yml" on the Groovy project root directory.

Then change the "testDir" value to the directory your test files are located.

# Sahagin configuration file written by YAML style.

groovy:
  # Root directory of test Groovy files
  # (absolute path or relative path from this YAML file).
  # All test methods and methods or content DSLs with TestDoc 
  # must be located under this directory.
  testDir: src/test/groovy

If you use not Spock but JUnit4, you must add the following additional entry:

groovy:
   testFramework: jUnit4

5. Run test and generate report

Run your Spock or JUnit4 tests.

After the tests run, the HTML report sahagin-rerpot/index.html is generated on the sahagin.yml directory.

6. Set up Jenkins plug-in

Jenkins Sahagin plug-in displays HTML report generated by Sahagin Groovy on Jenkins.

Set up the plug-in according to 6. Set up Jenkins plug-in of Sahagin-Java.

Next Step

If you want to know more about Sahagin-Groovy features, go to Various features.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.