Ruby Cucumber Interview Questions

by Bharathkumar, on Sep 10, 2022 4:52:29 PM

Interview Questions (30)

1.Define what is Cucumber?

Cucumber is a Behavior Driven Development (BDD) tool. Cucumber is a tool that executes plain-text functional descriptions as automated tests. The language that Cucumber understands is called Gherkin.

In BDD, users (business analysts, product owners) first write scenarios or acceptance tests that describes the behavior of the system from the customer’s perspective, for review and sign-off by the product owners before developers write their codes.

2.Cucumber execution starts from where ?

Cucumber execution will starts from support. In support first it will load the env.rb file then it will load hooks.rb and then it will start execute feature file scenario steps.

3.Define what is support, env.rb and hooks.rb ?

  • Support is a foder where we can setup cucumber related support.
  • rb file will be used to load the required libraries for cucumber scenario execution
  • rb we will add hooks like before, after, beforeStep and afterStep hooks

4.Define what is profile in cucumber ?

  • We can create Cucumber profiles to run specific features and step definitions
  • We can use following command to execute a cucumber profile
  • cucumber features -p <profile_name>

Ex: cucumber features -p regression

5. Define what are before, after, beforeStep and afterStep hooks?

  • Before:execute before the feature file execution
  • After:executes after the feature file execution
  • BeforeStep:executes before the each step execution
  • AfterStep:executes after the each step execution

6.Define what are cucumber tags? why we use the tags ?

cucumber tags used to filter the scenarios. We can tag the scenarios and we can execute the scenarios based on tags,

We can add tags to scenarios with @

We can use following command to execute a cucumber tagged scenarios

cucumber features -t @<tag_name>

Ex: cucumber features -t @test

7. Define what is cucumber dry run ?
Cucumber dry run is used to compile cucumber feature files and stepDefinitions. If there is any compilations errors it will sDefine How when we use dry run

Ex: Cucumber features –dry-run

8.How to run a particular scenario from a feature file?
We can run particular scenario from a feature file by giving the scenario line number

Ex: cucumber features/test.feature:21

9. Define what is scenario outline ?

  • Scenario outline is used to execute the same scenario with different test data.
  • we will add test data in examples section

10. Define what are the keywords that we use in cucumber scenario steps ?

We use Given,when,Then,And and But keywords in cucumber scenario steps

11.Is it mandatory to use the keywords while writing scenario steps ?

No it is not mandatory to used keywords while writing scenario steps.

We can write the scenario steps like the following without using keywords

* I am on the landed page

12.Define How to generate cucumber execution reports ?

We can use the following command to generate html reports.

–format html –out report.html –format pretty

13.Define How to run a particular scenario from a feature file ?

We can run particular scenario from a feature file by giving the scenario line number

Ex: cucumber features/test.feature:21

14.Define what is Cucumber and Define what are the advantages of Cucumber?

To run functional tests written in a plain text Cucumber tool is used. It is written in a Ruby programming language.

Advantages of Cucumber

  • You can inolve business stakeholders who can not code
  • End user experience is priority
  • High code reuse

15.Define what are the 2 files required to execute a Cucumber test scenario?

The 2 files required to execute a Cucumber test scenario are

  • Features
  • Step Definition

16. Define what is feature file in Cucumber? Define what does feature file consist of ?
Feature file in cucumber consist of parameters or conditions required for executing code, they are

  • Feature
  • Scenario
  • Scenario Outline
  • Given
  • When
  • Then

17. Give an example of behaviour driven test in plain text?

  • Feature:Visit XYZ page in abc.com
  • Scenario:Visit abc.com
  • Given:I am on abc.com
  • When:I click on XYZ page
  • Then:I should see ABC page

18.Explain Define what is Scenario Outline in feature file?
Scenario Outline: Same scenario can be executed for multiple sets of data using scenario outline. The data is provided by a tabular structure separated by (I I).

19. Define what is step definition in Cucumber?
A step definition is the actual code implementation of the feature mentioned in feature file.

20. Give the example for step definition using “Given” function?
For example to make visitor visit the site “Yahoo” the command we use for given

Given (/^ I am on www.yahoo.com$/) do

Browser.goto “http://www.yahoo.com”

end – This will visit www.yahoo.com

21. Define what are the difference between Jbehave and Cucumber?

Although Cucumber and Jbehave are meant for the same purpose, acceptance tests are completely different frameworks

  • Jbehave is Java based and Cucumber is Ruby based
  • Jbehave are based on stories while Cucumber is based on features

22.Explain Define what is test harness?

A test harness for cucumber and rspec allows for separating responsibility between setting up the context and interacting with the browser and cleaning up the step definition files

23. Explain when to use Rspec and when to use Cucumber?
Rspec is used for Unit Testing

Cucumber is used behaviour driven development.

Cucumber can be used forSystem and Integration Tests

24. Define what is the language used for expressing scenario in feature file ?

Gherkin language is used to express scenario in feature files and ruby files containing unobtrusive automation for the steps in scenarios

25.Explain Define what is regular expressions?

A regular expression is a pattern describing a certain amount of text. The most basic regular expression consists of a single literal character

26.Define what is cucumber.yml file in cucumber ?

in cucumber.yml file we will create profiles

27.Define what softare do you need to run a Cucumber Web Test ?

  • Ruby and its Development Kit
  • Cucumber
  • IDE like ActiveState
  • Watir ( To simulate browser)
  • Ansicon and rspec (if required)

28.Define what does a features/ support file contains ?
Features/ support file contains supporting ruby code. Files in support load before those in step_definitions, which can be useful for environment configuration.

29.Define what is BDD Framework.Define what is the benefit of BDD in selenium ?

  • BDD is becoming widely accepted practice in agile software development, and Cucumber-JVM is a mainstream tool used to implement this practice in Java. Cucumber-JVM is based on Cucumber framework, widely used in Ruby on Rails world as well as in Java and .Net.
  • Cucumber-JVM allows developers, QA, and non-technical or business participants to write features and scenarios in a plain text file using Gherkin language with minimal restrictions about grammar in a typical Given, When, and Then structure.
  • The feature file is then supported by a step definition file, which implements automated steps to execute the scenarios written in a feature file. Apart from testing APIs with Cucumber-JVM, we can also test UI level tests by combining Selenium WebDriver.

30. Define what is #{} and Define How do you use it?

P42, interpolation. most case used as puts “#{x} + #{y}” = “#{x+y}”

31.Define what is error handling and Define How do you do error handling?

P584: Raise, Rescue

32.Define what is the difference between class and module?

P141, P142
Class can do: inheritance, having instance, while module CAN NOT. Can be required.
Module can do: make namespace to avoid name clash, can be included.
#instantiate from class within module
Module A
Class B
End
b= A::B.new

33.Define Cucumber Report:

Cucumber generates its own html format. Define However better reporting can be done using Jenkins or bamboo tool. Details of reporting are covered in next topic of cucumber.

34.Define what are the benefits?

  • It is helpful to involve business stakeholders who can’t easily read code
  • Cucumber focuses on end-user experience
  • Style of writing tests allow for easier reuse of code in the tests
  • Quick and easy set up and execution
  • Efficient tool for testing

35. What are cucumber tags? why we use the tags?

cucumber tags used to filter the scenarios. We can tag the scenarios and we can execute the scenarios based on tags,

We can add tags to scenarios with @

We can use following command to execute a cucumber tagged scenarios

cucumber features -t @<tag_name>

36.What does a features/ support file contains?

Features/ support file contains supporting ruby code. Files in support load before those in step_definitions, which can be useful for environment configuration.

37Cucumber execution starts from where?

Cucumber execution will starts from support. In support first it will load the env.rb file then it will load hooks.rb and then it will start execute feature file scenario steps.

38.What is support, env.rb and hooks.rb ?

  • Support is a foder where we can setup cucumber related support.
  • rb file will be used to load the required libraries for cucumber scenario execution
  • rb we will add hooks like before, after, beforeStep and afterStep hooks

39.What is profile in cucumber?
We can create Cucumber profiles to run specific features and step definitions

We can use following command to execute a cucumber profile

cucumber features -p <profile_name>

Ex: cucumber features -p regression

40. There are three ways to invoke a method in ruby. Can you give me at least two?
Here, I’m looking for the dot operator (or period operator), the Object#send method, or method(:foo).call

object = Object.new

puts object.object_id

#=> 282660

puts object.send(:object_id)

#=> 282660

puts object.method(:object_id).call # (Kudos to Ezra)

#=> 282660

Topics:Interview Questions with Answers

Comments

Subscribe