Selenium Cucumber Interview Ques
Selenium Cucumber Interview Ques
Selenium Cucumber Interview Ques
4) What are the various keywords that are used in Cucumber for writing a
scenario?
Mentioned below are the keywords that are used for writing a scenario:
Given
When
Then
And
While feature files are written in an easily understandable language like, Gherkin, Step
Definition files are written in programming languages such as Java, .Net, Ruby, etc.
Example:
|filename|
|file1|
|file2|
The main aim of the Behavior Driven Development framework is to make various project
roles such as Business Analysts, Quality Assurance, Developers, and Support Teams
understand the application without diving deep into the technical aspects.
12) What is the limit for the maximum number of scenarios that can be included in
the feature file?
A feature file can contain a maximum of 10 scenarios, but the number can vary from
project to project and from one organization to another. But it is generally advisable to
limit the number of scenarios included in the feature file.
{
driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("www.facebook.com");
}
In Agile methodology, user stories can be written in the format of feature file and the
same can be taken up for implementation by the developers.
23) Explain the purpose of keywords that are used for writing a scenario in
Cucumber.
“Given” keyword is used to specify a precondition for the scenario.
“When” keyword is used to specify an operation to be performed.
“Then” keyword is used to specify the expected result of a performed action.
“And” keyword is used to join one or more statements together into a single
statement.
24) What is the name of the plugin that is used to integrate Eclipse with
Cucumber?
Cucumber Natural Plugin is the plugin that is used to integrate Eclipse with Cucumber.
TestRunner class is used to provide the link between the feature file and the step
definition file. The next question provides a sample representation of how the
TestRunner class will look like. A TestRunner class is generally an empty class with no
class definition.
26) Provide an example of the TestRunner class in Cucumber.
Package com.sample.TestRunner
importorg.junit.runner.RunWith;
importcucumber.api.CucumberOptions;
importcucumber.api.junit.Cucumber;
@RunWith(Cucumber.class)
@CucumberOptions(features="Features",glue={"StepDefinition"})
public class Runner
{
}
29) What is the use of features property under the Cucumber Options tag?
Features property is used to let the Cucumber framework identify the location of the
feature files.
30) What is the use of glue property under the Cucumber Options tag?
Glue property is used to let the Cucumber framework identify the location of step
definition files.
31) What is the maximum number of steps that are to be written within a
scenario?
3-4 steps.
33) What is the main aim of the Behavior Driven Development (BDD) framework?
The main aim of the Behavior Driven Development framework is to make various project
roles such as Business Analysts, Quality Assurance, Developers, etc., understand the
application without diving deep into the technical aspects.
34) What are the two files required to execute a Cucumber test scenario?
Following are the two files required to execute a Cucumber test scenario:
Features
Step Definition
40) What is the difference between RSpec and Cucumber? When should we use
RSpec and when to use Cucumber?
RSpec and Cucumber both are the example of testing frameworks. RSpec uses
traditional Unit Testing. It means it uses testing a class or part of the application in
isolation from the rest of the application. So your model does what your model is
supposed to do, the controller does what it is supposed to do, etc. RSpec and
Cucumber both are used for Acceptance Testing, also called ATDD, BDD, etc.
provides the facility to write tests in a human-readable language called Gherkin. The
Selenium-Cucumber framework supports programming languages such as Java, .NET,
PHP, Python, Perl, etc.
44) What do you understand by TDD, and what are the different processes used in
TDD?
TDD is an acronym that stands for Test-Driven Development. This is a software
development technique used to create the test cases first and then write the code
underlying those test cases. Although TDD is a development technique, it can also be
used for automation testing development. TDD takes more time for development
because it tends to find very few defects. The result provided by the TDD development
technique has improved the quality of code, and that can be more reusable and flexible.
TDD also helps developers to achieve high test coverage of about 90-100%. The only
disadvantage for developers following TDD is to write their test cases before writing the
code.
Following is the list of simple 6 step process used by TDD methodology:
First, write the test case: You have to write an automated test case according to your
requirements.
Run all the test cases: Now, run these automated test cases on the currently
developed code.
Develop the code for that test case: In this process, you must write the code to make
that test case work as expected if the test case fails.
Run test cases again: Now, you have to rerun the test cases and check if all the test
cases developed so far are implemented.
Refactor your code: This is an optional step. But, it is advised to refactor your code to
make it more readable and reusable. That's why it is essential.
Repeat steps 1- 5 for new test cases: This is the last step. Here, you have to repeat
the cycle for the other test cases until all the test cases are implemented.
46) What are the main differences between TDD and BDD?
Following is the list of main differences between TDD and BDD:
TDD BDD
TDD stands for Test-Driven Development. It is BDD stands for Behavior Driven Development. It is a
a test-centered development process. This Behavior centered development process.
In TDD, writing a test fails because the In BDD, creating an executable specification that
specified functionality doesn't exist, then fails because the feature doesn't exist, then writing
writing the most straightforward code that can the most straightforward code that can make the
make the test pass, then refactoring to remove spec pass. You repeat this until a release candidate
duplication, etc. is ready to ship.
TDD tests are written using programming BDD tests are written in a human-readable format
languages such as Java, .Net, Python, Ruby, using Given-When-Then steps. These tests are
etc. readable and understandable by non-technical
persons also.
TDD tests are difficult to read by non- BDD tests are readable by non-programmers also
programmers as they are written in specific as they are written in a human-readable format.
programming languages.
The critical difference between TDD and BDD On the other hand, BDD is a team methodology.
is the scope. TDD is a development practice.
In TDD, the developers write the test cases. In BDD, the automated specifications are created by
users or testers then the developers wiring them to
the code under test.
48) How can you use the Options tag in the Cucumber framework?
In the Cucumber framework, the Options tag is a part of the TestRunner file and comes
in the form of an annotation called @CucumberOptions. It contains two parameters
feature and glue.
Feature parameter: The feature parameter is used to specify the path of the
feature file.
Glue parameter: The glue parameter is used to specify the path of the step
definition file.
)
public class TestRunner {
}
We have to import org.junit.runner.RunWith for the @RunWith annotation and
cucumber.api.CucumberOptions for the @CucumberOptions annotation.
48) What are the two build management tools that can be integrated with
Cucumber?
Following are the two build management tools that can be integrated with Cucumber:
Gradle
Maven
Some scenarios may require certain preconditions for execution, such as launching the
application, establishing a database connection, configuring the test data, and so on.
Also, certain postconditions should be executed, such as terminating database
connection, closing the browser, refreshing test data, application log out, and so on. All
these conditions are handled in Cucumber with the help of the hooks. The @Before
hook executes before the actual scenario, and the @After hook executes after the
actual scenario even if the test corresponding to the actual scenario fails.
For the @Before annotation, we have to import cucumber.api.java.en.Before and for the
@After annotation, we have to import cucumber.api.java.en.After.
We use to compile the cucumber feature files and step definitions. If there occur any
compilation errors, then it shows them on the console.
54) What If You Don’t Use The Cucumber Keywords In Test Steps?
Please note that it’s not mandatory to write keywords in test steps.
For example, we can build a test step like the one shown in the next line.
e.g.- We are testing using cucumber.
55) When Would You Use Rspec And When To Use Cucumber?
RSpec is more successful in doing unit testing.
As you know that Cucumber is a behaviour-driven development tool. So you can use it
for System and Integration testing.
57) What Is The Right Way To Execute A Specific Scenario From The Feature
File?
We can select the target scenario from a feature file by providing its line number.
cucumber features/test.feature:10 --format html > testfeature.html