Total Pageviews

Thursday, 27 September 2018

CUCUMBER

TestNG frame work is TDD , test driven development immediately we write code but in BDD we write code along with business logic

Advantage with BDD is that u can write features immediately and code part we can take up later.
In BDD frame work any one can contribute in writing the features. Business Analyst or Manual Tester or any one from agile team can write feature file and automation tester can write
code based on that feature file.

Disadvantage: We have to write too much, In testNG we dont have to write this much just right @test,@aftermethod etc


Keywords in Cucumber:

Feature: It defines logical test functionality you will test in feature file. example:
               Feature: LogIn Action Test

Background: This keyword is used to define steps which are common to all scenarios in feature file. example:
     Background: User is logged in
          Given: user on login page
          When: User enter creds iand enters
          Then: home page displayed

Now the given when then inside background will be repeated before every scenario

Scenario: Each feature will contain some number of test to be tested. Each test is called scenario and each scenario will be followed by given,when,then steps.

Scenario Outline: Some scenarios can be executed for multiple set of data using scenario outline.  Data provided by tabular structure separated by |

Given: Defines precondition of test
When: It defines the test action which will be executed
Then: Keyword defines outcome of previous step. We define post condition with then
And: And keyword is used to add conditions to step  example :
          When : user navigate to login page
   And : user enters username and password

But: But keyword is used for negative testing example:
        Given User is on Home Page
        When User Navigate to LogIn Page
        And User enters UserName and Password
        But The user credentials are wrong
        Then Message displayed Wrong UserName & Password


*: Star keyword defies whole purpose of given when then, just use * in place of given , when , then and test will still work fine


Feature File: Features file contain high level description of the Test Scenarios in simple language. Language is known as Gherkin.

StepDefinition file: StepDefinition File maps test case steps in feature file with methods.


Cucumber Options:




  • Parameterization without Example Keyword



Parameterization with Example Keyword:





Parameterization Using Tables:












Use of Tags:





Hooks:
There are two types of hooks in cucumber. @before and @after, which are executed before and after scenarios.

@Before(order = int) : This runs in increment order, means value 0 would run first and 1 would be after 0

So just Define @before and @after in stepdefinition file , and at the time of execution these will be executed before and after scenario


BackGround Vs Hooks:
Background in Cucumber is used to define a step or series of steps which are common to all the tests in the particular feature file.
So if you have mentioned background in a feature file then it will run before every scenario for that particular feature file.
while suppose you have mentioned hooks with @before annotation the it is going to run before all scenarios of all the feature files which u are running.

The background is run before each of your scenarios but after any of your @Before hook.

Any feature level dependency should be tie with the background and any scenario level dependency should be tie with hooks.

It is a good practice to keep the background short.







No comments:

Post a Comment