This is our first blog post on Ruby Cucumber automation testing and as an automation testing services company, we would like to share basic and advanced techniques of automation testing with software testing & quality assurance communities.
In this article, we will show you how to create a feature file and implementation code using RubyMine. Before following up the below steps, make sure you have already configured RubyMine
Step1-Create Empty Ruby Project
File->New Project
Step2-Create Gem file
Select project directory, right click and click New->File
Create Gem file with the following Gem details as shown below.
Note: These Gem details will be published in our next article.
source 'https://rubygems.org/' gem 'cucumber', '1.2.1' gem 'rspec', '2.10.0' gem 'ffi', '1.3.1' gem 'watir-webdriver', '0.7.0' gem 'watir' gem 'selenium-webdriver' gem 'headless', '0.2.2' gem 'titleize', '1.2.1' gem 'json', '1.7.7' gem 'gherkin', '<= 2.11.6' gem 'syntax'
Step3-Directory Structure
Create sub folders as shown below
—>features
————->Project1
——————->feature
——————->pages
——————->step_definitions
————->Support
Step4-Create Shared Driver
Create SharedDriver.rb inside Support folder with the following code.
require 'rubygems' require 'rspec' require 'watir-webdriver' include Selenium #Creating Remote WebDriver browser = Watir::Browser.new(:remote, :url => "http://SauceUsername:[email protected]:80/wd/hub", :desired_capabilities => WebDriver::Remote::Capabilities.firefox) #If you want to run it locally, use Watir::Browser.new :firefox Before do @browser = browser end
Step5-Create Feature file
Create sample.feature file inside feature folder with the below steps
Feature: Sample Feature Scenario: Sample Scenario Given I launch https://codoid.com And I click on Login tab And I enter username And I enter password When I click Login button Then I see Home page
Step6-Create Step Definitions
Create Step Definitions with pending steps
Given(/^I launch http://www.codoid.com$/) do pending end And(/^I click on Login tab$/) do pending end And(/^I enter username$/) do pending end And(/^I enter password$/) do pending end When(/^I click Login button$/) do pending end Then(/^I see Home page$/) do pending end
Step7-Create Page Object
class LoginPage attr_accessor :loginTab,:txtUsername,:txtPassword,:btnLogin def initialize(browser) @browser = browser @loginTab = @browser.a(:text => "Login") @txtUsername = @browser.text_field(:id => "userId") @txtPassword = @browser.text_field(:id => "password") @btnLogin = @browser.element(:id => "log_in_button") end def visit @browser.goto "https://codoid.com" end def clickLoginTab() @loginTab.click end def enterUsername(username) @txtUsername.set username end def enterPassword(password) @txtPassword.set password end def clickLoginButton @btnLogin.click end def verifyHomePageHeader() @browser.element(:text => "Dashboard").wait_until_present end end
Step8-Call Page Methods in Step Definitions
Given(/^I launch http://www.codoid.com$/) do @LoginPage = LoginPage.new(@browser) @LoginPage.visit end And(/^I click on Login tab$/) do @LoginPage.clickLoginTab end And(/^I enter username$/) do @LoginPage.enterUsername("xxxxxxx") end And(/^I enter password$/) do @LoginPage.enterPassword("yyyyyyy") end When(/^I click Login button$/) do @LoginPage.clickLoginButton end Then(/^I see Home page$/) do @LoginPage.verifyHomePageHeader end
Step9-Create cucumber.yml file
Create cucumber.yml file inside project directory as shown below
default: --format html --out=Report.html
Step10-Run the feature file
Once execution is done, open the report file
You will see the report as shown below
In the subsequent articles, we will share more topics and advanced techniques. Stay tuned!
Comments(0)