Saturday, 22 September 2018

Creating the Maven with Cucumber project

Creating the Maven with Cucumber project


For creating the Maven with cucumber project, follow the below navigations
Eclipse
                                New file ->
Others ->
Maven->
Maven project

Click on finish


NOTE:
·         Group Id: Unique name of the project across all projects
·         Artifact Id: Name of the jar
·         Version: Version of the jar

Copy dependencies

                Copy all dependencies into project file of pom.xml as mentioned Section 1.1


Create Feature File

A. Create Feature folder and under the folder create. feature file i.e., Test.feature
B. Write the applications Scenarios under. feature file as follows


C. Run the feature file, will generate the cucumber methods as per the business requirements in mentioned,

Feature: login action

  Scenario: Successful login to cyclos  # E:/Partha/Cucumber/MavenwithCucumberProject/Feature/TestCucumber.feature:3
    Given open the Browser
    When User able to access the URL
    And enter the username and password
    Then Applition successful login

1 Scenarios (1 undefined)
4 Steps (4 undefined)
0m0.000s
@Given("^open the Browser$")
public void open_the_Browser() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^User able to access the URL$")
public void user_able_to_access_the_URL() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^enter the username and password$")
public void enter_the_username_and_password() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^Applition successful login$")
public void applition_successful_login() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();

D. Create TestRunner.java class under the TestRunner package and the .java file should contain the code snippet

RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "Feature",
glue = {"StepDefinition"})


Create StepDefinition package and list of .java class as follows
- Create a .java file (HomePage.java) The purpose of this .java file is to store the application URL and make sure that, this class should extends from PageObject in order to preserve the objects
Code Snippet:
public class HomePage extends PageObject{

}


-          Create anther .java file i.e., BuyerStep, purpose of this .java file is to invoke the application URL
Code Snippet:
              HomePage homePage = new HomePage();                                         
   
              @Test//@Step                                                      
              public void openurl() {
                  homePage.open();
              }
}

-Create another .java file where we will write Business logics, and need to copy the cucumber generated methods


-          Copy browser executable files in to the project folder
-          Create. properties file, where we will specify on which browser will invoke the application.
-          Run the Test Runner file where it will execute as per the scenarios (requirements).

Issues facing while configuring Maven with Cucumber

                Unable to build the pom.xml sometimes, to fix this issue please make sure your Eclipse Market place file having the Natural 0.7.6 is installed (used for BDD and ATTD). 

No comments:

Post a Comment