# Scripting Web Tests

with Watir and Ruby

Workbook / Solutions / 3. Writing Scripts

## Sample Solution for Lab 3. Writing Scripts

Lab 3. Writing Scripts

Your script for the add book to cart scenario might look something like this.

    require 'watir'

    b = Watir::IE.start('http://localhost:3000/store')
    b.link(:href, 'http://localhost:3000/store/add_to_cart/4').click

Your script for the purchase books scenario might look something like this.

    require 'watir'

    b = Watir::IE.start('http://localhost:3000/store')
    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.link(:text, 'Checkout').click
    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("123 Main St.\nWashington D.C.")
    b.select_list(:id, 'order_pay_type').select('Check')
    b.button(:name, 'commit').click