Selenium Cucumber Interview Questions

By | January 25, 2019

Cucumber


  1. What is BDD? What are advantages of it?
    BDD stand for Behaviour-Driven Development. It is basically set of practices A common misunderstanding BDD is that they it is
    testing technique but it is not. It is about software deveolpment process in which Automation tests are by product.
    The BDD flavour development uses natural language(Gherkin) to describe tests.
    Advantages of BDD:
    Rework caused by misunderstood or vague requirements.
    Technical debt caused by reluctance to refactor code.
    Slow feedback cycles caused by silos and hand-overs.
  2. What is Cucumber? Which syntax it will use?
    Cucumber is a tool that supports Behaviour-Driven Development(BDD).
    It uses Gherkin syntax rules.
    Cucumber reads executable specifications/scenarios written in plain text with some basic Gherkin syntax rules.
    Each scenario is a list of steps for Cucumber to work through.

    In nutshell, Each test case in Cucumber is called a scenario, and scenarios are grouped
    into features. Each scenario contains several steps.

  3. What are keywords in Gherkin?
    Keywords for English are:
    Feature : Each Gherkin file begins with the Feature keyword. Feature keyword is the
    name of the feature, and the remaining lines are its description
    Background : A Background allows you to add some context to the scenarios in the feature. Which can be reused across scenarios.
    Scenario : Each scenario is an example of how the system should behave in a particular situation.
    Given,When,Then,And, But (for steps) : Used to define steps
    * : You can replace Given,When,Then,And, But with * . However it will be vague/unclear.
    Examples : Examples is kind of table which lists rows of values to be used o test a scenario. Multiple input values to same scenario.
    Scenario Outline : This keyword is used to run the same Scenario multiple times, with different combinations of values.
    So Scenario Outline must contain an Examples section to provide multiple sets of data.

    | (Data Tables) : To provide data. Examples keyword will use this.
    # (Comments) : Used to write comments.

  4. What are the basic files used in cucumber? How does it work?
    Main files are:
    1. Feature file:
    Cucumber, reads specifications from plain-language text files called features.
    Example: 1 scenario which has 3 steps

                Feature: Selling Price
                 Scenario: Selling book
                   Given the price of a "book" is 150c
                   When I buy 1 "book"
                   Then the total price should be 150c
            
    

    When you save and run this feature file: Sample code for step definitions will get generated(In this case its written in Java).

                You can implement missing steps with the snippets below:
                @Given("^the price of a \"(.*?)\" is (\\d+)c$")
                public void the_price_of_a_is_c(String arg1, int arg2) throws Throwable {
                // Write code here that turns the phrase above into concrete actions
                throw new PendingException();
                }
                @When("^I buy (\\d+) \"(.*?)\"$")
                public void i_buy(int arg1, String arg2) throws Throwable {
                // Write code here that turns the phrase above into concrete actions
                throw new PendingException();
                }
                @Then("^the total price should be (\\d+)c$")
                public void the_total_price_should_be_c(int arg1) throws Throwable {
                // Write code here that turns the phrase above into concrete actions
                throw new PendingException();
                }
    

    2. Step Definitions:
    step definitions map the business-readable language of each step into code to carry out whatever action is being described by the step.

                package step_definitions;
                import cucumber.api.java.en.*;
                import cucumber.api.PendingException;
                public class CheckoutSteps {
                @Given("^the price of a \"(.*?)\" is (\\d+)c$")
                public void thePriceOfAIsC(String arg1, int arg2) throws Throwable {
                // Write code here that turns the phrase above into concrete actions
                throw new PendingException();
                }
                @When("^I checkout (\\d+) \"(.*?)\"$")
                public void iCheckout(int arg1, String arg2) throws Throwable {
                // Write code here that turns the phrase above into concrete actions
                throw new PendingException();
                }
                @Then("^the total price should be (\\d+)c$")
                public void theTotalPriceShouldBeC(int arg1) throws Throwable {
                // Write code here that turns the phrase above into concrete actions
                throw new PendingException();
                }
                }
    

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.