Cucumber
How to Download & Install CUCUMBER in Windows
Cucumber installation could be tiresome but its relatively easy. Here is a roadmap of components that need...
In this tutorial, we will create Cucumber Scripts to test two scenarios
Step 1) Open RubyMine Editor via windows start menu
Step 2) In Rubymine Editor, click on Create New Project
Step 3) Select the Project location and click "Create."
Step 4) Create a file directory
Step 5) Name the directory as "features"
Step 6) Create and Save File in "yourfolder/features/" with name "yourfilename.feature"
Step 7) To execute our scenario, save the following program in the Feature File
Code:
Feature: Multiplication
I multiply two numbers
Scenario: multiply a and b
Given I have variable a
And I have variable b
When I multiplication a and b
Then I display the Result
Step 8) Now let's Run our First feature file!
Click on "Start Command Prompt With Ruby"
And the output you get is
You see the error because you have to write step definitions file for feature file
Step 7) Let's create step definition file for our Feature File!
Create a new folder in Rubymine editor with name "step_definition"
Step 8) Save File As below in "yourfolder/features/step_ definitions" with name test_step.rb
Step 9) Write the following code into the step file
Code :
Given(/^I have variable a$/) do
@a = 50
end
And(/^I have variable b$/) do
@b = 70
end
When(/^I multiplication a and b$/) do
@mul = @a * @b
end
Then(/^I display the Result$/) do
puts "Multiplication of #{@a} and #{@b} is #{@mul}"
end
Step 10) Now, again run our feature file:
The result is
In this example we use Ruby
Test Scenario: Verify output when Email id is NOT entered
Test Steps:
Test Scenario: Verify output when Email id is entered
Test Steps:
Feature: gtupapers Demopage Login To Login in Demopage we have to enter login details Scenario: Register On gtupapers Demopage without email Given I am on the gtupapers homepage When enter blank details for Register Then error email shown Scenario: Register On gtupapers Demopage with valid email Given I am on the gtupapers homepage When enter details for Register Then login details shown
Code in Step Definition File
require 'watir-webdriver'
require 'colorize'
browser = Watir::Browser.new
Given (/^I am on the gtupapers homepage$/)do
browser.goto "http://demo.gtupapers.com"
end
When (/^enter blank details for Register$/)do
browser.text_field(:name,"emailid").set(" ")
browser.button(:name,"btnLogin").click
end
Then (/^error email shown$/)do
puts " Email is Required".red
browser.close
end
When (/^enter details for Register$/)do
browser = Watir::Browser.new
browser.goto "http://demo.gtupapers.com"
browser.text_field(:name,"emailid").set("This email address is being protected from spambots. You need JavaScript enabled to view it.")
browser.button(:name,"btnLogin").click
end
Then (/^login details shown$/)do
puts " Sucessfully register"
browser.close
end
Run the code in command prompt and you get
Cucumber installation could be tiresome but its relatively easy. Here is a roadmap of components that need...
What is Cucumber? Cucumber is a testing tool that supports Behavior Driven Development (BDD). It...
For every cucumber project there is a single directory at the root of the project named " features...
What is Gherkin Language? Gherkin is a business readable language which helps you to describe...
Training Summary Behavior Driven Development (BDD) is a rising methodology to test and check your...