Let's package the step of adding first book to shopping cart into methods: getCurrentItemTitle
and addToShoppingCart
in "buy_book.rb". An it should look like:
And /^I add the first book to shopping cart$/ do
getCurrentItemTitle
addToShoppingCart
end
def getCurrentItemTitle
@bookTitle=@driver.find_element(:id => "productTitle").text
end
def addToShoppingCart
element=@driver.find_element :name => "submit.add-to-cart"
element.click
end