Quickstart Library
How To Get Started:
First, the library should be exported into an empty automation project by using:
mvn clean package -DbuildDirectory=directory/to/project/lib
For instance:
mvn clean package -DbuildDirectory=/Users/Umut/Github/Web-Automation-Sample-Cucumber/lib
There, the imported jar file should be added as a dependency in pom.xml file of that project:
<!-- Framework -->
<dependency>
<groupId>bora</groupId>
<artifactId>POM-Framework-0.0.2.jar</artifactId>
<version>0.0.2</version>
<systemPath>${project.basedir}/lib/POM-FRAMEWORK-0.0.2.jar</systemPath>
<scope>system</scope>
<type>jar</type>
</dependency>
After updating your project, the quickstart library is ready to use.
How To Use:
The quickstart library consists of many utility methods and a ready to use built in selenium grid infrastructure, compatible with page object model design. The infrastructure allows easy initialization of elements by initializing them within a constructor inside the Utilities class. In order to initialize elements inside a page class, all it takes is to extend the Utilities class. This also extends the Driver class, allowing usage of driver inside page classes.
Step 1: Create a screens package
Create page classes, add elements (use @FindBy annotation) & page methods. Remember extending Utilities class, initializing all elements within the page class.
public class HomePage extends Utilities {...}
Step 2: Create a steps package
Create page step classes, instantiate page classes, create step definitions & access page methods within these step definitions as:
public class HomePageSteps { HomePage homePage = new HomePage(); @Given("Click category card named {}") public void clickCategoryCard(String cardName) { homePage.clickCategoryCardNamed(cardName); } }Set cucumber @Before & @After steps as:
Initialize driverManager = new Initialize(); @Before public void start(){driverManager.init();} @After public void kill(Scenario scenario){driverManager.kill(scenario);}This will initialize the driver before each run, and kill it after each scenario is done. It will also capture a ss if the scenario fails, indicating scenario name and failed step info.
Step 3: Create a features package
Create .feature files, create your scenarios using the steps you have implemented in Step 2.
Step 4: Execute your tests
Selenium Grid needs to be running first, turn on Docker, then in project directory start Selenium Grid & Nodes by using the following command:
docker-compose up -dAlternatively, set selenium.grid property to false in test properties, that way the tests will run locally
The library allows the browser type to be designated on runtime, just pass:
-Dbrowser=browserName
For instance:
-Dbrowser=firefox
Chrome, Firefox, Opera, Edge & Safari are supported. In order to use this feature, please add the following plugin & property to your pom.xml:
<properties>
<browser>Chrome</browser>
<name>${project.name}</name>
</properties>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>write-project-properties</goal>
</goals>
<configuration>
<outputFile>${project.build.outputDirectory}/properties-from-pom.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
Example execution command:
In order to execute a specific feature file in a specific browser, add tags to the first line of your feature file & use:
mvn clean test -q -Dcucumber.filter.tags="@Registration and @TestEnv" -Dbrowser=chrome
To create a cucumber project:
mvn archetype:generate \ "-DarchetypeGroupId=io.cucumber" \ "-DarchetypeArtifactId=cucumber-archetype" \ "-DarchetypeVersion=6.10.4" \ "-DgroupId=hellocucumber" \ "-DartifactId=hellocucumber" \ "-Dpackage=hellocucumber" \ "-Dversion=1.0.0-SNAPSHOT" \ "-DinteractiveMode=false"