In our previous blog post, we published how to create/setup a Ruby-Cucumber project with a sample script. Now we are going to show you how to create a page with Page Object gem.
We, at Codoid are handling multiple software automation testing projects using various automation testing tools and frameworks, but working with Ruby-cucumber along with Page Object gem is unique and wonderful experience.
Let’s move on to topic.
Step Definition
Given(/^I launch (.*) url$/) do |url| on(LoginPage).navigate_to url end And(/^I click on Login tab$/) do on(LoginPage).click_login_tab end And(/^I enter username$/) do on(LoginPage).enter_username("xxxxxxxxxxx") end And(/^I enter password$/) do on(LoginPage).enter_password("yyyyyyyyyyy") end When(/^I click Login button$/) do on(LoginPage).click_login_button end Then(/^I see Home page$/) do on(LoginPage).verify_home_page_header end
Page
class LoginPage include PageObject link(:lnk_login_tab, :text => 'Login') text_field(:txt_username, :id => 'userId') text_field(:txt_password, :id => 'password') button(:btn_login, :id => 'log_in_button') div(:elmnt_dashboard, :text => 'Dashboard') def click_login_tab() #Click Login tab in Codoid.com-Automation Testing Company lnk_login_tab end def enter_username(username) #Enter Username self.txt_username=username end def enter_password(password) #Enter Password self.txt_password=password end def click_login_button #Click Login button btn_login end def verify_home_page_header() #Wait for Home page after login elmnt_dashboard_element.when_visible end end
Feel free to contact us, if you have any questions/suggestions.
Comments(0)