Selenium Java Interview Questions And Answers – Part 4

Selenium Java Interview Questions And Answers – Part 4

Selenium Java Interview Questions and Answers Part-4

1) What is Cucumber?

Cucumber is a tool that supports Behaviour-Driven-Development(BDD) which is used to write acceptance tests for the web application. Cucumber can be used along with Selenium, Watir, and Capybara etc. Cucumber supports many other languages like Perl, PHP, Python, Net etc.

2) What are the advantages of Cucumber?

– Cucumber supports different languages like Java.net and Ruby.
– It acts as a bridge between the business requirements and development code.
– It allows the test script to be written without knowledge of any code, it allows the involvement of non-programmers as well.
– It serves the purpose of end-to-end test framework unlike other tools.
– Due to simple test script architecture, Cucumber provides code reusability.

3) What are the 2 files required to execute a Cucumber test scenario?

Step definition file and Test Runner file are the 2 files required to run a cucumber test scenario.

3) What language is used by Cucumber?

Cucumber uses Gherkin language. It is a domain specific language which helps you to describe business behavior without the need to go into detail of implementation. This text acts as documentation and skeleton of your automated tests.

4) What is meant by a feature file ?

The file, in which Cucumber tests are written, is known as feature files. The extension of the feature file needs to be “.feature”.

5) What does a feature file consists of?

Feature file consists of different test scenarios written using Gherkin language in Given/When/And/Then format.

6) What are the various keywords that are used in Cucumber for writing a scenario?

Most common keywords used in Cucumber are:
– Feature
– Background
– Scenario
– Given
– When
– Then
– And
– But

7) What is Scenario Outline in Cucumber and its purpose?

Same scenario can be executed for multiple sets of data using scenario outline. The data is provided by a tabular structure.

8) What programming language is used by Cucumber?

Cucumber supports a variety of different programming languages including Java, JavaScript, PHP, Net, Python, Perl, etc. with various implementations.

9) What is the purpose of Step Definition file in Cucumber?

A Step Definition is a Java method with an expression that links it to one or more Gherkin steps. When Cucumber executes a Gherkin step in a scenario, it will look for a matching step definition to execute.

To illustrate how this works, look at the following Gherkin Scenario:

Scenario: Login
Given user logins to the site

The user logins to the site part of the step (the text following the Given keyword) will match the following step definition:

public class StepDefinitions {
@Given("user logins to the site")
public void user_login_to_site () {
System.out.println("User is logged into the site")

10) What are the major advantages of Cucumber framework?

– It is helpful to involve business stakeholders who can’t easily read code
– Cucumber Testing 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

11) Provide an example of a feature file using the Cucumber framework.

Feature: Login to site
Scenario: User login with valid credentials
Given user is on login page
When user enters valid username
And user enters valid password
Then login success message is displayed

12) Provide an example of Scenario Outline using Cucumber framework?

Feature − Scenario Outline
Scenario Outline − Login for facebook
Given user navigates to Facebook
When I enter Username as "<username>" and Password as "<password>"
Then login should be unsuccessful
| username  | password  |
| username1 | password1 |
| username2 | password2 |

13) What is the purpose of Behaviour Driven Development (BDD) methodology in the real world?

Behavior Driven Development is a software development approach that allows the tester/business analyst to create test cases in simple text language (English). The simple language used in the scenarios helps even non-technical team members to understand what is going on in the software project.

14) What is the limit for the maximum number of scenarios that can be included in the feature file?

You can have as many scenarios as you like, but it is recommended to keep the number at 3-5. Having too many steps in an example, will cause it to lose it’s expressive power as specification and documentation.

15) What is the use of Background keyword in Cucumber?

A Background allows you to add some context to the scenarios in the feature. It can contain one or more Given steps. It is run before each scenario, but after any Before hooks. In your feature file, put the Background before the first Scenario. You can only have one set of Background steps per feature. If you need different Background steps for different scenarios, you’ll need to split them into different feature files.

16) What symbol is used for parameterization in Cucumber?

The steps can use <> delimited parameters that reference headers in the examples table. Cucumber will replace these parameters with values from the table before it tries to match the step against a step definition.

17) What is the purpose of Examples keyword in Cucumber?

A Scenario Outline must contain an Examples (or Scenarios) section. Its steps are interpreted as a template which is never directly run. Instead, the Scenario Outline is run once for each row in the Examples section beneath it.

18) What is the file extension for a feature file?

Extension for a feature file is .feature

19) Provide an example of step definition file in Cucumber.

public class StepDefinitions {
@Given("user logins to the site")
public void user_login_to_site () {
System.out.println("User is logged into the site")

20) What is the purpose of Cucumber Options tag?

@CucumberOptions annotation provides the same options as the cucumber jvm command line. For Example: we can specify the path to feature files, path to step definitions, if we want to run the execution in dry mode or not etc.

21) How can Cucumber be integrated with Selenium WebDriver?

We can integrate cucumber with selenium webdriver by adding all dependencies/jars related to selenium and cucumber in the project.

22) When is Cucumber used in real time?

Cucumber should be used for verifying the most important parts of the application using end-to-end tests. BDD should also be used to verify the wanted behaviour using integration tests. Importantly, the business should be able to understand these tests, so you can reduce uncertainty and build confidence in what you are building.

23) Provide an example of Background keyword in Cucumber?

Feature: Add items to shopping cart
Background: User is logged in
Given user navigate to login page
When user submits username and password
Then user should be logged in successfully

Scenario: Search a product and add it to shopping cart
Given user searches for dell laptop
When user adds the selected item to shopping cart
Then shopping cart should display the added item

24) What is the use of Behaviour Driven Development in Agile methodology?

The intent of BDD is to provide a single answer to what many Agile teams view as separate activities: the creation of unit tests and “technical” code on one hand, the creation of functional tests and “features” on the other hand.

25) Explain the purpose of keywords that are used for writing a scenario in Cucumber?

– Feature: The purpose of the Feature keyword is to provide a high-level description of a software feature, and to group related scenarios.
– Scenario: In addition to being a specification and documentation, a scenario is also a test. As a whole, your scenarios are an executable specification of the system.
– Given: steps are used to describe the initial context of the system – the scene of the scenario. It is typically something that happened in the past.
– When: steps are used to describe an event, or an action. This can be a person interacting with the system, or it can be an event triggered by another system.
– Then: steps are used to describe an expected outcome, or result.
– Scenario Outline: This keyword can be used to run the same Scenario multiple times, with different combinations of values.
– Background: It allows you to add some context to the scenarios in the feature. It can contain one or more Given steps.

Next Steps:

> More interview questions and answers on Selenium Java, continue to the next post (Click on Next Post link below)

> Check complete Selenium Java interview questions and answers here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Bijan Patel

Connect to me on Linked In (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

Open chat
Contact Us on Whatsapp