-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathv01_buying_backpack_SimpleLineByLineCode.rb
62 lines (47 loc) · 2.1 KB
/
v01_buying_backpack_SimpleLineByLineCode.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
require 'webdrivers'
require 'watir'
# Open chrome browser
browser = Watir::Browser.new :chrome
# Navigate to saucedemo.com
browser.goto "https://saucedemo.com"
# Login to saucedemo.com
browser.text_field(id: 'user-name').set('standard_user')
browser.text_field(id: 'password').set('secret_sauce')
browser.button(id: 'login-button').click
# Add backpack to cart:
browser.button(id: 'add-to-cart-sauce-labs-backpack').click
# Navigate to cart page:
browser.a(class: 'shopping_cart_link').click
# Navigate to chechout information page
browser.button(id: 'checkout').click
# Provide checkout information and navigate to checkout overview page
browser.text_field(id: 'first-name').set('turiyam')
browser.text_field(id: 'last-name').set('krishna')
browser.text_field(id: 'postal-code').set('78759')
browser.button(id: 'continue').click
# Complete checkout:
browser.button(id: 'finish').click
puts "Is the cbackpack order placed?: #{browser.div(id: 'checkout_complete_container').h2(class: "complete-header").text == 'Thank you for your order!'}"
sleep 1 # It's not really needed but added to look at the last page.
# Lets say, you want to buy another backpack. For that you repeat same steps:
# Navigate to saucedemo.com
browser.goto "https://saucedemo.com"
# Login to saucedemo.com
browser.text_field(id: 'user-name').set('standard_user')
browser.text_field(id: 'password').set('secret_sauce')
browser.button(id: 'login-button').click
# Add backpack to cart:
browser.button(id: 'add-to-cart-sauce-labs-backpack').click
# Navigate to cart page:
browser.a(class: 'shopping_cart_link').click
# Navigate to chechout information page
browser.button(id: 'checkout').click
# Provide checkout information and navigate to checkout overview page
browser.text_field(id: 'first-name').set('turiyam')
browser.text_field(id: 'last-name').set('krishna')
browser.text_field(id: 'postal-code').set('78759')
browser.button(id: 'continue').click
# Complete checkout:
browser.button(id: 'finish').click
puts "Is the cbackpack order placed?: #{browser.div(id: 'checkout_complete_container').h2(class: "complete-header").text == 'Thank you for your order!'}"
sleep 1