http://www.technicalpage.net/search/label/SQL

BDD


BDD FrameWork / Selenium with Cucumber(Gherkin Script)
BDD stands for Behavior Driven Development , it is a framework which uses Gherkin Language. Cucumber is open source tool. Cucumber supports different languages like Java,Java Script, Groovy,C++, Python, Ruby, C#, .Net.
Cucumber can be easily integrate with Selenium.
In BDD, the test steps are written in plain English language, so that a non – technical person also can understand. 
You use seven Keywords in Gherkin script also called Gherkin syntax : Feature used once in the feature file, feature is like test suite, this gives major introduction of the project or the feature file. A single feature file is like a test  suite, it can have multiple scenarios, scenarios are test cases. Each scenario is combination of Scenario name, followed by test steps. The test steps should start with Given. The Test steps annotations are : Given, When, Then, And or But . Every test case should start with Given followed by any number of other annotations. WHEN is used once only. Given is like precondition.
Selenium used cucumber to simplify the flow , to make the flow understandable. The syntax is simple plain text. So, easy to read and understand. Each feature file is like a test suite. It has scenarios(test cases) and each test cases has test steps. The steps look like manual steps and easily understandable. Feature file can be prepared by even manual tester. And can be shared with anybody.
To use Cucumebr in Selenium, You need to add jar files of cucumber and add the cucumber plugin from the Eclipse marketplace. You can find the cucumber jar files at “cucumber.io” or “mvnrepository.com”.
To create feature file and Add scenario/s: Create a folder in the Eclipse Project. In the folder add a file with the extension “.feature”. Add your test steps using Feature, Scenario, Given, When, And , Then, But whichever are relevant in your flow and save the file. Format of Feature and Scenario are Feature: and Scenario: . To run , click the feature file and click Run As – Cucumber feature. It runs and shows the feature file text in the output with some additional information as a result or might not show any result. To run this in Selenium, create test definition class and test runner class. Test runner is a class without main method. Above the class name, below the package name and import statements write below code:
@RunWith(Cucumber.class)
@Cucumber.Options(
features="path of feature file",
//add below options if needed
glue = {path of the step definition file/class} ,
format={pretty html format, xml format, json format},
monochrome=true/false , // to display console output in proper readable format.
strict=true/false , // checks the feature and step definition mapping if any missing or undefined.
dryRun=true/false // checks the feature and step definition mapping if any missing or undefined.
)
public class TestRunnerClassName(){
}
This is the Test runner class. Now right click this class and run as Junit.Test

Cucumber Options:

dryRun checks the mapping of the feature file scenario steps and the step definition. Checks the mapping of steps and step definition. For every step in ff, there should be step definition(code) with the respective annotation:@Given, @When, @Then…..
If any step definition is missing, the code will not run when you try to run. To check the mapping, make dryRun=True and run. After the mapping is correct, then make dryRun=false and run the test case.
To quickly check if mapping is correct or not , just make it true and run. This is quickest.
Feature: here you give the path of feature file. If more then one feature file, then give them with comma separation. If you give folder path then all the feature file inside that will be executed.
Glue : path of package of step definition class. Give path of particular class or path of package if you want to run all the class?.
Monochrome : if you make monochrome = true, then console output will be in readable or understandable format.
Format: to display the console output in readable proper format. To print output in html or json format or XML format. XML report is very easy and quick to understand.Depending upon the name of output folder and name of output file given, the folder and file/report are created. Which you can share with your team or lead/manager. For example ,for html:


After execution, a test output folder is created automatically. Inside which there is index.html file is created which is test report.
Strick : fails the execution if there is any pending or undefined steps are there. This is useful when dryRun is false. This also checks the mapping of step definition and ff steps. When step definition is missing for any step, it executes the code unlike dryRun, but fail at the step saying pending exception. Useful when dryRun is not used or dryRun is false.

In Progress....

No comments:

Post a Comment