Can Serenity+Cucumber+Geb work together?

143 views
Skip to first unread message

AlexB

unread,
Mar 27, 2019, 7:42:04 AM3/27/19
to Geb User Mailing List
Hi all!

I'm wondering if it's possible to bundle serenity+cucumber+geb in one test framework.
At the moment I'm using Serenity+Cucumber+RestAssured for API testing. And now I need to add UI tests.
I did find some examples of Cucumber+Geb projects. I tried to add the needed settings to my existing project, but it doesn't work meanwhile.

When setting up Serenity+Cucumber project I realized that it's very important to use correct libraries (like not to use Cucumber libraries instead of Serenity libraries). So I guess there is a risk that the Cucumer+Geb example will not work for Serenity+Cucumber+Geb.

So before I spent many hours trying to set my project up using this example, maybe somebody could advise:
1) if it's indeed possible to use the 3 frameworks together
2) what I must take into account (use as a dependency/etc.) to have it work.

Thank you in advance!
Alex

Alexander Kriegisch

unread,
Mar 27, 2019, 9:59:37 PM3/27/19
to geb-...@googlegroups.com
Hi Alex.

How about sharing the project you have so far? Let everyone see what you
tried and where you got stuck. You didn't even mention how you want to
build your project. Maven? Gradle maybe?

Regards
--
Alexander Kriegisch
https://scrum-master.de


AlexB schrieb am 27.03.2019 18:42:

> I'm wondering if it's possible to bundle serenity+cucumber+geb in one
> test framework.
>
> At the moment I'm using Serenity+Cucumber+RestAssured for API testing.
> And now I need to add UI tests.
>
> I did find some examples of Cucumber+Geb projects. I tried to add the
> needed settings to my existing project, but it doesn't work meanwhile.
>
>
> When setting up Serenity+Cucumber project I realized that it's very
> important to use correct libraries (like not to use Cucumber libraries
> instead of Serenity libraries). So I guess there is a risk that the
> Cucumer+Geb example will not work for Serenity+Cucumber+Geb.
>
>
> So before I spent many hours trying to set my project up using this
> example, maybe somebody could advise:
>
> 1. if it's indeed possible to use the 3 frameworks together
>
> 2. what I must take into account (use as a dependency/etc.) to have
> it work.

AlexB

unread,
Mar 28, 2019, 5:04:51 AM3/28/19
to Geb User Mailing List
Hi Alexander,

Unfortunately I can't provide you with the full project as it's under NDA. However, I can give some details:

1. I use Maven.
2. Here is pom file for my current project (Serenity+Cucumber+RestAssured).
 <modelVersion>4.0.0</modelVersion>
 <groupId>my-project-tests</groupId>
 <artifactId>my-project-tests</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 
 <properties>
       <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
       <serenity.version>2.0.30</serenity.version>
       <serenity.maven.version>2.0.30</serenity.maven.version>
       <webdriver.driver>chrome</webdriver.driver>
 </properties>
 
 <build>
       <plugins>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-jar-plugin</artifactId>
               <version>2.6</version>
               <executions>
                   <execution>
                       <goals>
                           <goal>test-jar</goal>
                       </goals>
                   </execution>
               </executions>
           </plugin>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-compiler-plugin</artifactId>
               <version>3.3</version>
               <configuration>
                   <compilerId>groovy-eclipse-compiler</compilerId>
                   <compilerVersion>1.8</compilerVersion>
                   <source>1.8</source>
                   <target>1.8</target>
                   <verbose>false</verbose>
               </configuration>
               <dependencies>
                   <dependency>
                       <groupId>org.codehaus.groovy</groupId>
                       <artifactId>groovy-eclipse-compiler</artifactId>
                       <version>2.9.2-01</version>
                   </dependency>
                   <dependency>
                       <groupId>org.codehaus.groovy</groupId>
                       <artifactId>groovy-eclipse-batch</artifactId>
                       <version>2.4.3-01</version>
                   </dependency>
               </dependencies>
           </plugin>
           <plugin>
               <groupId>org.codehaus.groovy</groupId>
               <artifactId>groovy-eclipse-compiler</artifactId>
               <version>2.9.2-01</version>
               <extensions>true</extensions>
           </plugin>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-surefire-plugin</artifactId>
               <version>2.22.1</version>
               <configuration>
                 <testFailureIgnore>true</testFailureIgnore>
               </configuration>
           </plugin>
           <plugin>
               <artifactId>maven-failsafe-plugin</artifactId>                  
               <version>2.18</version>
               <configuration>
                   <includes>
                       <include>**/features/*.feature</include>                  
                   </includes>
                   <systemProperties>
                       <webdriver.driver>${webdriver.driver}</webdriver.driver>
                    </systemProperties>
               </configuration>
           </plugin>
           <plugin>
               <groupId>net.serenity-bdd.maven.plugins</groupId>      
                <artifactId>serenity-maven-plugin</artifactId>
               <version>${serenity.maven.version}</version>
               <dependencies>
                    <dependency>
                      <groupId>net.serenity-bdd</groupId>
                      <artifactId>serenity-core</artifactId>
                      <version>2.0.30</version>
                  </dependency>
               </dependencies>
               <executions>
                   <execution>
                       <id>serenity-reports</id>
                       <phase>post-integration-test</phase>            
                        <goals>
                           <goal>aggregate</goal>                      
                        </goals>
                   </execution>
               </executions>
           </plugin>
       </plugins>
 </build>
 
 <dependencies>
   <dependency>
     <groupId>junit</groupId>
     <artifactId>junit</artifactId>
     <version>4.12</version>
     <scope>test</scope>
   </dependency>
   <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
        <version>${serenity.version}</version>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-junit</artifactId>
        <version>${serenity.version}</version>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.7.25</version>
    </dependency>
    <dependency>
       <groupId>net.serenity-bdd</groupId>
       <artifactId>serenity-cucumber</artifactId>
       <version>1.9.23</version>
   </dependency>
   <dependency>
       <groupId>net.serenity-bdd</groupId>
       <artifactId>serenity-rest-assured</artifactId>
       <version>${serenity.version}</version>
   </dependency>
   <dependency>
       <groupId>com.jayway.jsonpath</groupId>
       <artifactId>json-path-assert</artifactId>
       <version>2.2.0</version>
       <scope>test</scope>
   </dependency>
     <dependency>
         <groupId>org.hamcrest</groupId>
         <artifactId>hamcrest-all</artifactId>
         <version>1.3</version>
         <scope>test</scope>
     </dependency>
 </dependencies>
</project>

3. Here is the structure of packages:
-project
---src/test/groovy
-----com.qa.featrues
-------TestRunner.groovy
-----com.qa.features.steps
-------ApiSteps.groovy
-----com.qa.features.steps.serenity
-------ApiRequests.groovy
---sr/test/resources
-----features
-------TestScenarios.feature
---pom.xml
---serenity.properties

4. For debug purposes I run tests in Eclipse IDE through TestRunner class that looks like this:
package com.qa.features

import cucumber.api.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
import org.junit.runner.RunWith;

@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features="src/test/resources/features")
class TestRunner {

}

5. For testing purposes I run tests using command:
mvn clean verify

Please let me know if some additional information could be helpful

Regards,
Alex

Alexander Kriegisch

unread,
Mar 28, 2019, 10:59:34 PM3/28/19
to geb-...@googlegroups.com

No need to provide us here with code under NDA. Just create an MCVE reproducing your problem, something I can build and run and then verify by myself if it does what you want or not. I think you cannot expect anyone to dream up their own sample project for that. I have never used your specific tool combination, so I would appreciate something to start with. I personally use Spock + Geb + Maven, but have never used Cucumber (because Spock already is a BDD tool) and have never heard of Serenity before.


--
Alexander Kriegisch
https://scrum-master.de

--
You received this message because you are subscribed to the Google Groups "Geb User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geb-user+u...@googlegroups.com.
To post to this group, send email to geb-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/geb-user/01d0b639-23ed-43ba-9056-51ef3b9f1630%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcin Erdmann

unread,
Mar 29, 2019, 3:34:28 AM3/29/19
to geb-...@googlegroups.com
I agree with Alexander that a MVCE would be useful, not only to help others help you but for you as well - your current setup looks already fairly complex and trying Geb + Cucumber + Serenity on its own would probably help by removing all of the moving parts currently exisitng in your setup and possibly affecting what you are trying to do.

AlexB

unread,
Apr 19, 2019, 11:00:38 AM4/19/19
to Geb User Mailing List
Thank you Alexander Kriegisch and Marcin Erdmann for your replies. I found the way to do it.
Here is what I did:
0. So initially I had a Serenity+Cucumber+Java+Maven project. It's easy to set it up just by going through Serenity documentation
2. Then I asked tde-desc for some more information (see it in the same post)
3. I added following dependencies to pom.xml file:
<dependency>
   
<groupId>org.codehaus.groovy</groupId>
   
<artifactId>groovy-all</artifactId>
   
<version>2.4.13</version>
</dependency>
<dependency>
   
<groupId>org.gebish</groupId>
   
<artifactId>geb-core</artifactId>
   
<version>2.3.1</version>
</dependency>
<dependency>
   
<groupId>org.seleniumhq.selenium</groupId>
   
<artifactId>selenium-java</artifactId>
   
<version>3.14.0</version>
</dependency>



4. Added GebConfig.groovy file to src/test/resources folder. The content is absolutely typical (taken from gebish.org) so I'm not adding it here

5. Added the following code to the class with UI step definitions:

import geb.Browser

import geb.binding.BindingUpdater

import org.openqa.selenium.WebElement

import cucumber.api.java.After

import cucumber.api.java.Before


class UiSteps {

       def bindingUpdater

       def browser


        @Before
        public void initiateAdapter(){

               browser = new Browser()

               bindingUpdater = new BindingUpdater(new Binding(), browser)

               bindingUpdater.initialize()

       }

     
     
@After

        public void removeAdapter(){

                bindingUpdater.remove()

       }

}



6. Then I created a typical Geb page class with elements and methods
7. And added step definitions to the UiSteps class. Here is the example

import geb.Browser

import com.myproject.pages.JobsPage


@When("^.* navigate? to a job by (index|name|id) (.*)")

public void user_opens_a_job(findJobBy, identifier){

  Browser.drive{
   
at JobsPage

  switch(findJobBy){

      case "index":

           openJobByIndex(Integer.parseInt(identifier)) //openJobByIndex is a method in JobsPage class

          break

      case "id":

          openJobById(identifier) //openJobById is a method in JobsPage class

          break

       default:

            break

    }

  }

}


This is it. Now I'm able to run tests either through JUnit (when running them from IDE) or from maven by "mvn verify" command (when I need to get serenity report)


Reply all
Reply to author
Forward
0 new messages