Sample Solution for Lab 4. Verifying Behavior
After adding validations, your script for the add book to cart scenario might look something like this.
require 'watir' require 'spec' b = Watir::IE.start('http://localhost:3000/store/empty_cart') b.link(:href, 'http://localhost:3000/store/add_to_cart/4').click b.div(:id, 'banner').text.should == 'Your Pragmatic Cart' b.table(:index, 1)[3][2].text.should == 'Pragmatic Project Automation' b.cell(:id, 'totalcell').text.should == '$29.95'
After adding validations, your script for the purchase books scenario might look something like this.
require 'watir' require 'spec' b = Watir::IE.start('http://localhost:3000/store/empty_cart') b.link(:href, 'http://localhost:3000/store/add_to_cart/4').click b.link(:text, 'Continue shopping').click b.link(:href, 'http://localhost:3000/store/add_to_cart/12').click b.div(:id, 'banner').text.should == 'Your Pragmatic Cart' b.table(:index, 1)[3][2].text.should == 'Pragmatic Project Automation' b.table(:index, 1)[3][1].text.should == '1' b.table(:index, 1)[4][2].text.should == 'Pragmatic Version Control' b.table(:index, 1)[3][1].text.should == '1' b.cell(:id, 'totalcell').text.should == '$59.90' b.link(:text, 'Checkout').click b.div(:id, 'banner').text.should == 'Checkout' b.table(:index, 1)[3][2].text.should == 'Pragmatic Project Automation' b.table(:index, 1)[3][1].text.should == '1' b.table(:index, 1)[4][2].text.should == 'Pragmatic Version Control' b.table(:index, 1)[3][1].text.should == '1' b.cell(:id, 'totalcell').text.should == '$59.90' b.text_field(:id, 'order_name').set('Steven List') b.text_field(:id, 'order_email').set('doc@gmail.com') b.text_field(:id, 'order_address').set("1600 Pennsylvania Ave.\nWashington D.C.") b.select_list(:id, 'order_pay_type').select('Check') b.button(:name, 'commit').click b.div(:id, 'banner').text.should == 'Pragmatic Bookshelf' b.div(:id, 'notice').text.should == 'Thank you for your order.'