-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreview_post_and_reply.rb
365 lines (290 loc) · 12.7 KB
/
review_post_and_reply.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
#tester starts at
# https://lemonsarebetter.herokuapp.com/widget.php?network=rainforestqa.fyre.co&site=383920&articleId=ekrfjherf34823&appType=reviews&userId=user1_9080908090
test(id: 42097, title: "Review Post and Reply") do
# You can use any of the following variables in your code:
# - []
# added by Daniel
Capybara.save_path = "review_post_and_reply/"
# 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': "1440x900",
'name': "livefyre_review_post_and_reply",
}
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 => :firefox)
end
# browser name to be used to determine which behavior to emulate
browser_name = Capybara.current_session.driver.browser.capabilities.browser_name
# Random number to append to user_ids
random_num = rand(10000000...99999999).to_s
user1_id = "user1_" + random_num
user2_id = "user2_" + random_num
# App url for the two different users
base_url1 = "https://lemonsarebetter.herokuapp.com/widget.php?network=rainforestqa.fyre.co"\
"&site=383920&articleId=ekrfjherf34823&appType=reviews&userId=user1_#{random_num}"
base_url2 = "https://lemonsarebetter.herokuapp.com/widget.php?network=rainforestqa.fyre.co"\
"&site=383920&articleId=ekrfjherf34823&appType=reviews&userId=user2_#{random_num}"
step id: 1,
action: "Review app url loads",
response: "Do you see Review app loaded with 'Average User Rating', 'Rating Breakdown',"\
" 'Sign in' option and 'Write review' button?" do
# *** START EDITING HERE ***
# action
visit base_url1
# response
expect(page).to have_content('Average User Rating', wait: 90)
expect(page).to have_content('Rating Breakdown')
expect(page).to have_content('Sign in')
expect(page).to have_content('Write review')
#page.save_screenshot('screenshot_step_1.png')
# *** STOP EDITING HERE ***
end
step id: 2,
action: "Click on 'Sign in' option",
response: "Do you see next to avatar 'user1_{{random.number}}'?" do
# *** START EDITING HERE ***
# action
page.find(:css, "a[role='button']", :text => 'Sign in', :match => :first).click
# reponse
expect(page).to have_selector(:css, "a[role='button']", :text => user1_id)
#page.save_screenshot('screenshot_step_2.png')
# *** STOP EDITING HERE ***
end
step id: 3,
action: "Click on 'Write review' button",
response: "Do you see Review comment widget with 5 empty stars, 'Title...'' section,"\
" empty comment section, and 'Post review' button?" do
# *** START EDITING HERE ***
# action
page.find(:css, 'button', :text => 'Write review').click
# response
expect(page).to have_no_selector(:css, 'button', :text => 'Write review', wait: 10)
within(:css, '.fyre-editor.fyre-reviews-editor.fyre-editor-small') do
expect(page).to have_css('.goog-ratings')
expect(page).to have_content("Post review")
expect(find(:css, '.goog-ratings')['aria-valuenow']).to eql(nil)
expect(page.find(:css, '.fyre-editor-title')['placeholder']).to eql("Title...")
case browser_name
when 'firefox'
within_frame(find(:css, '[aria-label=editor]')) do
expect(page.find(:css, 'p')['text']).to eql(nil)
end
when 'chrome'
expect(page.find(:css, '.fyre-editor-editable.editable.fyre-editor-field')['text']).to eql(nil)
end
end
#page.save_screenshot('screenshot_step_3.png')
# *** STOP EDITING HERE ***
end
step id: 4,
action: "Enter text in 'Title...', text in comment section and choose star rating from top right side,"\
" then click 'Post review' button",
response: "Do you see your review posted on the stream below with title, comment text, star options "\
"selected in yellow and username?" do
# *** START EDITING HERE ***
title = "automation" + random_num
review = "User1 Review " + random_num
star_rating = rand(0...9)
rating_perc = star_rating*10 + 10
rating_style = "width: #{rating_perc}%"
# action
within(:css, ".fyre-editor.fyre-reviews-editor.fyre-editor-small") do
page.find(:css, "input[class='fyre-editor-title']").set(title)
case browser_name
when 'firefox'
within_frame(find(:css, '[aria-label=editor]')) do
page.find(:css, '.editable.fyre-editor-field>p').click
# typing out individual chars because of occassional errors during post
for x in 0...review.length do
page.find(:css, '.editable.fyre-editor-field>p').send_keys(review[x])
end
page.find(:css, 'p', :text => review)
end
when 'chrome'
page.find(:css, '.fyre-editor-editable.editable.fyre-editor-field').click
for x in 0...review.length do
page.find(:css, '.fyre-editor-editable.editable.fyre-editor-field').send_keys(review[x])
end
end
all(:css, "span[class*='ratings-star']")[star_rating].click
page.find(:css, "div[role='button']", :text => 'Post review', :match => :first).click
end
# response
within(:css, "article[data-author-id^='#{user1_id}']", wait: 20, :match => :first) do
expect(page).to have_selector(:css, ".fyre-reviews-rated>label[style^='#{rating_style}']")
expect(page).to have_content(user1_id)
expect(page).to have_content(title)
expect(page).to have_content(review)
end
expect(page).to have_no_selector(:css, 'span.fyre-editor-spinner', wait: 10)
#page.save_screenshot('screenshot_step_4.png')
# *** STOP EDITING HERE ***
end
step id: 5,
action: "Go to user avatar and click on 'Sign out' option",
response: "Do you see 'Sign in' option ?" do
# *** START EDITING HERE ***
# Currently the new post is not visible in a sorted list for up to 10 minutes. The
# => work around is to either wait 10 minutes or not use the sort by newest. Uncomment to use sort
#for i in 1..10 do
# page.find(:css, "a[role='button']", :text => user1_id).click
# sleep(60)
#end
# action
within(:css, '.fyre-login-bar') do
page.find(:css, ".fyre-user-profile-link.fyre-user-loggedin").hover
page.find(:css, "a[title='Sign out']").click
end
# response
expect(page).to have_content('Sign in')
#page.save_screenshot('screenshot_step_5.png')
# *** STOP EDITING HERE ***
end
step id: 6,
action: "Review app url loads",
response: "Do you see Review app loaded with 'Average User Rating', 'Rating Breakdown', "\
"'Sign in' option and 'Write review' button?" do
# *** START EDITING HERE ***
# action
visit base_url2
# response
expect(page).to have_content('Average User Rating', wait: 15)
expect(page).to have_content('Rating Breakdown')
expect(page).to have_content('Sign in')
expect(page).to have_content('Write review')
#page.save_screenshot('screenshot_step_6.png')
# *** STOP EDITING HERE ***
end
step id: 7,
action: "Click on 'Sign in' option",
response: "Do you see next to avatar 'user2_{{random.number}}'?" do
# *** START EDITING HERE ***
# action
within(:css, '.fyre-login-bar') do
page.find(:css, "a[role='button']", :text => 'Sign in', :match => :first).click
end
# reponse
within(:css, '.fyre-login-bar') do
expect(page).to have_selector(:css, "a[role='button']", :text => user2_id, :match => :first)
end
#page.save_screenshot('screenshot_step_7.png')
# *** STOP EDITING HERE ***
end
step id: 8,
action: "Click on 'Most Helpful' sort option then click 'Newest' option",
response: "Do you see user1's most recent comment shows up?" do
# *** START EDITING HERE ***
# Currently there is a bug that prevents using the latest because it takes 10 minutes for the Post to show up
# => uncomment below if you want to use the sort and you have uncommented the section above that waits 10 minutes
# action
#within(:css, '.fyre-widget') do
# page.find(:css, '.fyre-reviews-write').hover
#end
#within(:css, '.fyre-stream-sort') do
# page.find(:css, 'label', :text => 'Most helpful').click
# page.find(:css, 'a', :text => 'Newest').click
#end
# response
expect(page).to have_selector(:css, "article[data-author-id^='#{user1_id}']")
#page.save_screenshot('screenshot_step_8.png')
# *** STOP EDITING HERE ***
end
step id: 9,
action: "Click on the 'Reply' option from top comment.",
response: "Do you see a comment widget show up with 'Share' and 'Post' button ?" do
# *** START EDITING HERE ***
# action
within(:css, "article[data-author-id^='#{user1_id}']") do
page.find("a", :text => 'Reply', :match => :first).click
end
# response
within(:css, "article[data-author-id^='#{user1_id}']", :match => :first) do
expect(page).to have_content('Post')
expect(page).to have_content('Share')
case browser_name
when 'firefox'
within_frame(find(:css, '[aria-label=editor]')) do
expect(page.find(:css, 'p')['text']).to eql(nil)
end
when 'chrome'
expect(page.find(:css, '.fyre-editor-editable.editable.fyre-editor-field')['text']).to eql(nil)
end
end
#page.save_screenshot('screenshot_step_9.png')
# *** STOP EDITING HERE ***
end
step id: 10,
action: "Enter text in the reply comment widget and click 'Post' button",
response: "Do you see your reply get posted and the reply count increments, also empty reply comment widget ?" do
# *** START EDITING HERE ***
reply = "User2 Reply " + random_num
# action
within(:css, "article[data-author-id^='#{user1_id}']", :match => :first) do
case browser_name
when 'firefox'
within_frame(find(:css, '[aria-label=editor]')) do
page.find(:css, '.editable.fyre-editor-field>p').click
for x in 0...reply.length do
page.find(:css, '.editable.fyre-editor-field>p').send_keys(reply[x])
end
page.find(:css, 'p', :text => reply)
end
when 'chrome'
page.find(:css, '.fyre-editor-editable.editable.fyre-editor-field').click
for x in 0...reply.length do
page.find(:css, '.fyre-editor-editable.editable.fyre-editor-field').send_keys(reply[x])
end
end
page.find(:css, "div[role='button']", :text => 'Post', :match => :first).click
end
# response
within(:css, "article[data-author-id^='#{user1_id}']", wait: 20) do
within(:css, "article[data-author-id^='#{user2_id}']") do
expect(page).to have_content(reply)
expect(page).to have_content(user2_id)
end
end
expect(page).to have_no_selector(:css, 'span.fyre-editor-spinner', wait: 10)
#page.save_screenshot('screenshot_step_10.png')
# *** STOP EDITING HERE ***
end
step id: 11,
action: "Click the '1 Reply' option again.",
response: "Do you see Reply comment widget closes ?
" do
# *** START EDITING HERE ***
# action
within(:css, "article[data-author-id^='#{user1_id}']", :match => :first) do
case browser_name
when 'firefox'
expect(page).to have_selector(:css, 'iframe')
when 'chrome'
expect(page).to have_selector(:css, '.fyre-editor-editable.editable.fyre-editor-field')
end
page.find(:css, "a", :text => '1 Reply').click
end
# response
within(:css, "article[data-author-id^='#{user1_id}']", :match => :first) do
case browser_name
when 'firefox'
expect(page).to have_no_selector(:css, 'iframe', wait: 10)
when 'chrome'
expect(page).to have_no_selector(:css, '.fyre-editor-editable.editable.fyre-editor-field', wait: 10)
end
end
page.find(:css, "a[role='button']", :text => user2_id).hover
page.find(:css, "a[role='button']", :text => 'Sign out').click
#page.save_screenshot('screenshot_step_11.png')
# *** STOP EDITING HERE ***
end
end