Cucumber Scenario Outline - Cucumber

What is Cucumber Scenario Outline?

Scenario outline essentially replaces variable/key phrases with the value from the table. each row in the desk is considered to be a scenario.

Let’s maintain with the same example of fb login characteristic. up to now we had been executing one scenario: Upon offering the proper consumer name, login is successful. Now, suppose we want to test if login is successful for all three possible types of inputs, which can be username, email address, or phone range. To acquire this, we will want to jot down three different scenarios, in which each situation will range with the form of input, login is successful. In this example, scenarios will appear to be the subsequent.

scenario:

Given person navigates to facebook

Once I enter accurate username and password

Then login should be successful

scenario:

Given consumer navigates to facebook

once I enter accurate email cope with and password

Then login must achieve success

scenario:

Given person navigates to facebook

After I input correct phone range and password

Then login ought to be successful

Example

Let’s create an instance of a scenario outline −

Step 1 − Create a Maven take a look at project named as ScenarioOutlinelinetest

  • Visit file → New → Others → Maven → Maven project → subsequent.
  • Offer organization identity (institution identity will pick out your mission uniquely throughout all projects).
  • Provide artifact identity (artifact id is the call of the jar without version. you could choose any name that is in lowercase).
  • Click on end.
  • Open pom.xml −
  • Go to package explorer at the left hand side of Eclipse.
  • Expand the undertaking CucumberTest.
  • Find pom.xml file.
  • Right-click and select the option, Open with “text Editor”.
  • Add dependency for Selenium − this will indicate Maven, which Selenium jar files are to be downloaded from the critical repository to the local repository.
  • Open pom.xml is in edit mode, create dependencies tag ((<dependencies></dependencies>),, in the project tag.
  • In the dependencies tag, create dependency tag ((<dependencies></dependencies>),.
  • Provide the subsequent records in the dependency tag.

  • Add dependency for Cucumber-Java: this will suggest Maven, which Cucumber files are to be downloaded from the important repository to the local repository.
  • Create one extra dependency tag.
  • Provide following information within the dependency tag.

  • Add dependency for Cucumber-JUnit: this will imply Maven, which Cucumber JUnit files are to be downloaded from the valuable repository to the local repository.
  • Create one more dependency tag.
  • Offer the following data inside the dependency tag.


  • Add dependency for JUnit - this will imply Maven, which JUnit documents are to be downloaded from the relevant repository to the local repository.
  • Create one more dependency tag.
  • Provide the following information in the dependency tag.

  • Add dependency for JUnit - this may suggest Maven, which JUnit documents are to be downloaded from the primary repository to the nearby repository.
  • Create one greater dependency tag.
  • Provide the following records in the dependency tag.


Verify binaries.

  • Once pom.xml is edited successfully, save it.
  • Go to Project → Clean − It will take a few minutes.

Step 2 − Create a package named “outline” under src/test/java

Cucumber - Scenario Outline

Step 3 − Create a characteristic report named “Outline.feature”

  • select and right-click at the package outline.
  • Click on ‘New’ file.

Give the file such as “outline.feature”

  • Write the subsequent text in the record and save it.

Feature − scenario outline

scenario outline − Login capability for a social networking site.

Given user navigates to facebook

When I enter Username as "" and Password as ""

Then login must be unsuccessful

Example −

Note − here, example annotation describes the range of enter to be furnished upon scenario execution. check situation could be completed for each of the enter provided. So, in the given instance, take a look at situation could be performed 3 instances.

Step four − Create a step definition document.

  • Select and right-click on the package outline.
  • Click on ‘New’ document.
  • Give the document name as stepdefinition.java
  • Write the following text inside the file and keep it.

Note − Inside the above code, we must outline a feature having input argument: one username and other can be for password. So for every set of enter provided in the example tag, Set of GIVEN, when and then will be accomplished.

Step 5 − Create a runner class report.

  • Select and right-click on on the package outline.
  • Click on on ‘New’ file.
  • Give the report call such as runTest.java
  • Write the subsequent text inside the document and save it.

Run the take a look at using alternative −

  • Pick out runTest.java report from package explorer.
  • Right-click on and choose the option ‘Run as’.
  • Choose JUnit test.

You will study the following matters whilst you run this class report

  • Facebook opens in a brand new Firefox net-browser instance.
  • Username1 and password1 may be exceeded as an enter to username and password field.
  • Login may be clicked.
  • Message may be displayed at the browser regarding unsuccessful login.
  • Inside the console, you may see “test pass” printed.
  • Step end result 1 to 5 could be re-completed for username2 and password2.

In nutshell, when scenario does not exchange but simplest the records value gets changed, it's far advisable to apply scenario outline statistics tables.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Cucumber Topics