# BDD with PageObject

cd step_definations

touch buy_book.rb

Then edit it to contain following content:

# encoding: utf-8
Given /^I open "(.*?)"$/ do |site| @driver.get site end When /^I search for "(.*?)"$/ do |keyword|
searchKeyword=@driver.find_element :id => "twotabsearchtextbox"
searchKeyword.clear
searchKeyword.send_keys keyword
element=@driver.find_element :class =>"nav-submit-input"
element.click
end
And /^I open the first book$/ do element=@driver.find_element :xpath => "//div[@id=\"result_0\"]//span[@class=\"lrg bold\"]" element.click end And /^I add the first book to shopping cart$/ do
@bookTitle=@driver.find_element(:id => "productTitle").text

The # encoding: utf-8 here is to support multiple languages, if you just want to use English all the time and anywhere in your test, you can get rid of it.
If you need to change control to a new popuped window, you can use @driver.switch_to.window @driver.window_handles.last.