Friday 27 April 2018

Feature file example and their source codes in java

Example 1: Depends on the student marks, he will be notified whether he  got second class, first class or distinction in the exam.

StudentPassStatus.feature
Feature: Student Pass status 

 Student status is decided based on below criteria.
 ---------------------------------------------------
  < 60  : second class
  >= 60 && < 70 : First class
  > 70 : Distinction
 ---------------------------------------------------
 
Scenario: Checking Second Class 
 Student will be notified as second class, if he got < 60%
  
 Given I am a student 
 When I got Fifty Five percentage of marks 
 Then I should be notified as Second Class 
 
Scenario: Checking First Class 
 Student will be notified as First class, if he got >= 60 && < 70 percentage
  
 Given I am a student 
 When I got greater than or equal to sixty and < seventy percentage of marks 
 Then I should be notified as First Class 
 
Scenario: Checking Destinction 
 Student will be notified as Distinction if he got >70 percentage
  
 Given I am a student 
 When I got greate than seventy percentage of marks 
 Then I should be notified as Distinction

Cucumber generates below source code

@Given("^I am a student$")
public void i_am_a_student() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I got Fifty Five percentage of marks$")
public void i_got_Fifty_Five_percentage_of_marks() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should be notified as Second Class$")
public void i_should_be_notified_as_Second_Class() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I got greater than or equal to sixty and < seventy percentage of marks$")
public void i_got_greater_than_or_equal_to_sixty_and_seventy_percentage_of_marks() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should be notified as First Class$")
public void i_should_be_notified_as_First_Class() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I got greate than seventy percentage of marks$")
public void i_got_greate_than_seventy_percentage_of_marks() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should be notified as Distinction$")
public void i_should_be_notified_as_Distinction() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}


Example 2: Credit card validation


CreditcardValidation.feature

Feature: Credit card validation 

Scenario: Validate number of digits in credit card 

 Given I am the customer of website 
 When I entered a credit card number that is not exactly 16 digits 
 Then I should be notified with error message 
 And ask to reenter credit card number


Cucumber generates below source code.

@Given("^I am the customer of website$")
public void i_am_the_customer_of_website() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I entered a credit card number that is not exactly (\\d+) digits$")
public void i_entered_a_credit_card_number_that_is_not_exactly_digits(int arg1) throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^I should be notified with error message$")
public void i_should_be_notified_with_error_message() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^ask to reenter credit card number$")
public void ask_to_reenter_credit_card_number() throws Exception {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}


Previous                                                 Next                                                 Home

No comments:

Post a Comment