Friday, April 24, 2015

Serenity + JUnit for automation

Several days ago I was asked to complete one technical challenge task.
Task description is to prepare automation for set of settings for e-mail processing.
In details you should automate processing of the following:


One criteria is to use Serenity and JUnit
In this article I would not like to go deeper into tests. I would like to share several steps how I configure my project in Eclipse
1) I've created the same folder structure like was published at tutorial on Serenity site. So, I've created Eclipse project with name 'demo_from_site', and created folder structure according to the demo:

Folder structure in the project
Folder structure in the project













2) I've added requried groups of user-libraries like: 

List of user libraries
List of user libraries















You may download required Selenium drivers from this repository
3) Next step is to add required list of libraries into the project: 

Added user-libraries in the project
Added user-libraries in the project




















4) After that I added file 'HomePage.java' under the 'test.java.junit.pages' package. This file contains class 'HomePage', that extends the 'Page Object' class. Also I've added 'DemoSettings.java' file under the 'test.java' package and allocated special variables in class 'DemoSettings' with defult url.
5) Next step is to add class with user steps. This class should extends the 'ScenarioSteps' class:

Initial class with user steps
Initial class with user steps

















6) On the next step I've added step that will open the home page and prepare the story file for the launch, that locates under 'test.resources.stories.homepage' package:

Open home page story file
Open home page story file













7) Next stage is to added required class for handling the home page. So, I've created required file 'OpenHomePageTests.java' with class 'OpenHomePageTests' into package 'test.java.junit'. After adding it is required to attach the @RunWith (Serenity blog, JUnit) attribute to the class:

Initial class for the home page tests. In details: open home page.
OpenHomePageTests class


















8) Resolve errors by adding required import statements and adding JUnit library to reference.
9) Create instance of the WebDriver (as a result you will added two additional import statements into the project):

Instance of the WebDriver
Instance of the WebDriver














10) Add special variables to have access to user steps:

Variable to handle user steps
Variable to handle user steps













11) After that we can added our first step that just open the home page. Name of the test should be the same like name of scenario from the story:

Adding test that just open the home page
Adding test that just open the home page

















12) If we launch current project as JUnit test we will receive due to class loading. So to avoid problems with any dependencies let convert the project to Maven project:

Create new POM description for Maven
Create new POM description for Maven



















13) After converting to POM we no need libraries for both Selenium and Serenity that was created earlier.  All dependencies will be downloaded by Maven. Example of the user's dependencies tab is the following:

Dependency tab of pom file
POM file. Dependency tab.












14) To avoid of additional errors following dependency has been added:

Additional dependency
Additional dependency







15) Used version of dependencies:

Versions of dependencies
Versions of dependencies










16) We should added required information about Maven Compiler Plugin to avoid errors during the 'mvn install' operation. As well as several plugins that was pointed in Serenity documentation: http://thucydides.info/docs/serenity-staging/

No comments:

Post a Comment