Cucumber Notes
What is Cucumber in selenium?
Cucumber Framework in Selenium is an open-source testing framework that supports Behavior Driven Development for automation testing of web applications. The tests are first written in a simple scenario form that describes the expected behavior of the system from the user’s perspective.
What is a feature file?
A standalone unit or a single functionality (such as a login) for a project can be called a Feature. Each of these features will have scenarios that must be tested using Selenium integrated with Cucumber. A file that stores data about features, their descriptions, and the scenarios to be tested is called a Feature File
Keywords such as GIVEN, WHEN, and THEN used to write the test in Cucumber are called Annotations.
GIVEN user navigates to the login page by opening Firefox
WHEN user enters correct <username> AND <password> values
THEN user is directed to the homepage
What is step Definition?
A Steps Definitions file stores the mapping data between each step of a scenario defined in the feature file and the code to be executed.
public class Steps
{@Given("^user navigates to the login page by opening Firefox$")
//Code to Open Firefox Browser and launch the login page of application to define the GIVEN step of the feature
@When("^user enters correct username and password values$")
//take inputs for username and password fields using find element by xpath. Put the correct username and password values as inputs to define the WHEN step of the feature
@Then (“^user gets directed to homepage$”)
//Direct to the Homepage of the application as a result of correct username and password inputs in the WHEN step. This would define the THEN step of the feature
What is Test Runner File?
To run the test, one needs a Test Runner File, which is a JUnit Test Runner Class containing the Step Definition location and the other primary metadata required to run the test.
The Test Runner File uses the @RunWith() Annotation from JUnit for executing tests.
It also uses the @CucumberOptions Annotation to define the location of feature files, step definitions, reporting integrations, etc.
*In Test runner files we mention pah of report so it will generate report also
@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/Feature"
,glue={"src/main/stepDefinition"}
)
public class TestRunner {
}
* In Cucumber for Data driven testing simply in login. feature file we write Scenario Outline followed by example .so this scenario will execute a number of times depending on the input present under examples.
Feature: Login Data Driven
Scenario Outline: Login Data Driven
Given User Launch browser
And opens URL "https://demo.opencart.com/index.php"
When User navigate to MyAccount menu
And click on Login
And User enters Email as "<email>" and Password as "<password>"
And Click on Login button
Then User navigates to MyAccount Page
Examples:
| email | password |
| test333@gmail.com | test333 |
| test444@gmail.com | test444 |
*In Cucumber for data-driven testing with Excel, first we copy the DataReader file under utility package and second we need to copy excel data with login email and password save it under testdata folder and third we write the Scenario outline in Login. feature file. fourth implement step definition and five run the test runner file.
Feature: Login Data Driven with Excel
Scenario Outline: Login Data Driven Excel
Given User Launch browser
And opens URL "http://localhost/opencart/upload/"
When User navigate to MyAccount menu
And click on Login
Then check User navigates to MyAccount Page by passing Email and Password with excel row "<row_index>"
Examples:
|row_index|
|1|
|2|
|3|
*In Cucumber failed scenarios feature file name will be saved target folder with rerun.txt file .Now from test runner we will run that scenario feature only.
*In Cucmber we will not maintain separate extent report manager for reports and excelutility for excel it will directly generate a report from test runner with mentioned path for reports and for Excel reading we use dataprovide classunder utility package.
*In Cucmber we mentioned grouping with tags name .We will define tags in test runner as below
tags = "@sanity" //Scenarios tagged with @sanity,
//tags="@sanity and @regression"//scenario tagged with both sanity and regression
//tags="@sanity or @regression"// scenario tagged with both sanity and regression
//tags="@sanity and not @regression// scenario tagged with sanity but not regression
* We can run project from pom.xml .no need to mention any file names as we mentioned in testng xml files but here no need anything just run pom.xml file
*Run project from command prompt cd project folder path and mvn test
*Run project from git and jenkins
*Steps for setup Cucumber in Eclipse
Step1)First create a maven project
Step2)In pom.xml we need to add two dependencies that is Cucmber-java and Cumcumber-junit
Step3)need to install one plugin from eclipse-help-Eclipse market place then search for cucumber and install it
Comments
Post a Comment