-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmtt_course_checkout_epen_enroll.rb
182 lines (152 loc) · 7.52 KB
/
mtt_course_checkout_epen_enroll.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#tester starts at
# "http://beta.mindbodygreen.com/trainings/meditation-teacher-training"
# NOTES: This script currently does not work becuase the course is no longer open for enrollment
test(id: 89962, title: "MTT Course Checkout Test for Installation Payment when Enrollment Open") do
# You can use any of the following variables in your code:
# - []
# used to run Saucelabs with version 45 of Firefox. Version 50 was causing problems with some functionality
Capybara.register_driver :sauce do |app|
@desired_cap = {
'platform': "Windows 7",
'browserName': "firefox",
'version': "45",
'screenResolution': "1920x1080",
'name': "mbg_mtt_course_chkout_open_enrl",
}
Capybara::Selenium::Driver.new(app,
:browser => :remote,
:url => 'http://@ondemand.saucelabs.com:80/wd/hub',
:desired_capabilities => @desired_cap
)
end
# chrome testing
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
# used for random email
rand_num=Random.rand(899999999) + 100000000
#Starting point
visit "http://beta.mindbodygreen.com/trainings/meditation-teacher-training"
step id: 1,
action: "Close out any popups. Scroll down and click on the See Pricing Plans button under the large image screenshot.png. Wait 5 seconds.",
response: "Does it scroll down to the Enroll Now To Reserve Your Spot section?" do
# *** START EDITING HERE ***
expect(page).to have_content("Meditation")
# action
#close popups
for i in 1..5 do
if page.has_selector?(:css, 'div.listbuilder-popup-scale')
page.find(:css, "div[class*='sumome-react-wysiwyg-close-button'", wait: 10).click
break
end
end
# This step currently fails beacuse the class is no longer open for enrollment
# The following JS checks if the .price-container div which holds the course pricing info is in view as a result of clicking the Enroll button
expect(page.evaluate_script("function() {var elm = document.querySelector('.price-container');var vph = $(window).height(),st = $(window).scrollTop(),y = $(elm).offset().top;return (y < (vph + st));}();").inspect).to eql("false")
within(:css, '#training-sub-nav') do
page.find(:css, 'a', :text => 'Enroll').click
end
# response
sleep(1) #needed because following step does not cause a wait
# The following JS checks if the .price-container div which holds the course pricing info is in view as a result of clicking the Enroll button
expect(page.evaluate_script("function() {var elm = document.querySelector('.price-container');var vph = $(window).height(),st = $(window).scrollTop(),y = $(elm).offset().top;return (y < (vph + st));}();").inspect).to eql("true")
#page.save_screenshot('screenshot_step_1.png')
# *** STOP EDITING HERE ***
end
step id: 2,
action: "Click on the Enroll Now button under the Installation Payment section. Wait 5 seconds.",
response: "Does it take you to another page showing you the checkout page with the Shopping Cart with two classes in it?" do
# *** START EDITING HERE ***
# action
within(:css, '#payment-section') do
page.find(:css, 'a', :text => 'Enroll').click
end
# Workaround to handle improper redirect to staging env
# ***********Begin Workaround************
sleep(2)
visit 'https://beta.mindbodygreen.com/classes/checkout'
# ***********End Workaround**************
# response
expect(page).to have_content('Your Shopping Cart ( 2 )', wait: 30)
expect(page).to have_content('TRAININGS')
#page.save_screenshot('screenshot_step_2.png')
# *** STOP EDITING HERE ***
end
step id: 3,
action: "Scroll down to the Payment Information section and enter your email address {{random.email}} at the top of the page."\
" Then click on the Name on Card field",
response: "Were you able to click on the Name on Card field without any warning popups?" do
# *** START EDITING HERE ***
email = "automation#{rand_num}@nowhere.com"
# action
fill_in 'emailCheckout', with: email
page.execute_script('window.scrollTo(0,-1000)')
# response
# wait to make sure there is no pop-up
if page.has_selector?(:css, 'div.listbuilder-popup-scale')
page.find(:css, "div[class*='sumome-react-wysiwyg-close-button'").click
end
#page.execute_script('window.scrollTo(0,-10000)')
#page.save_screenshot('screenshot_step_3.png')
# *** STOP EDITING HERE ***
end
step id: 4,
action: "Enter {{random.full_name}} in the Name on Card field, 5111111111111111 in the Credit Card field, {{random.address_zip}}"\
" in the Postal Code field, {{random.number}}{{random.number}}{{random.number}} in the CVC field, select a random country"\
" from the Billing Country, and a future month and year from the Billing Month and Billing Year fields. Check the box to"\
" agree to the terms of sale. Click the Purchase button",
response: "Does the page refresh with an error regarding your credit card?" do
# *** START EDITING HERE ***
rand_name = ('a'..'z').to_a.shuffle[0,8].join
name = "Automation Name#{rand_name}"
cc_num = '5111111111111111'
postal = (Random.rand(89999)+10000).to_s + '-098'
cvc = Random.rand(899) + 100
# action
within(:css, '#credit-card') do
fill_in 'billingName', with: name
fill_in 'creditCardNumber', with: cc_num
fill_in 'postalCode', with: postal
fill_in 'cvc', with: cvc.to_s
scroll_offset = 2000
page.execute_script("window.scrollTo(0,#{scroll_offset})")
page.select 'United States', :from => 'country'
page.select '12', :from => 'month'
page.select '2022', :from => 'year'
page.check 'agreePrivacy'
page.click_button 'Complete My Order'
end
# response
expect(page).to have_content('We were unable to complete this transaction due to an error processing your credit card. The error returned was'\
' "There was an error with your user information - Credit card number is invalid." Please make any necessary corrections and try again.'\
' If this error persists, please contact us at [email protected].')
#page.save_screenshot('screenshot_step_4.png')
# *** STOP EDITING HERE ***
end
step id: 5,
action: "Change the credit card number to 4111111111111111 (four followed by fifteen ones), re-check the box to agree to"\
" the terms of sale, and click Purchase.",
response: "Do you see 'Sign in' option ?" do
# *** START EDITING HERE ***
if page.has_selector?(:css, 'div.listbuilder-popup-scale')
page.find(:css, "div[class*='sumome-react-wysiwyg-close-button'").click
end
cc_num = '4111111111111111'
# action
within(:css, '#credit-card') do
fill_in 'creditCardNumber', with: cc_num
scroll_offset = 2000
page.execute_script("window.scrollTo(0,#{scroll_offset})")
page.check 'agreePrivacy'
page.click_button 'Complete My Order'
end
# response
if page.has_selector?(:css, 'div.listbuilder-popup-scale')
page.find(:css, "div[class*='sumome-react-wysiwyg-close-button'", wait: 10).click
end
expect(page).to have_content('Purchase Confirmation')
#page.save_screenshot('screenshot_step_5.png')
# *** STOP EDITING HERE ***
end
sleep(10)
end