2020-07-06 21:06:19 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-05-06 15:13:24 +08:00
|
|
|
### Notes
|
|
|
|
# Only CSS selector is working, Jquery is not working
|
|
|
|
# e.g.: buttons = all("a.btn:contains(#{text}),input.btn[value=#{text}]")
|
|
|
|
# Change wait time to 0, otherwise waiting default time (30s) to get empty array of elements
|
|
|
|
|
|
|
|
|
|
|
|
### Improvments
|
|
|
|
# Threads? When first is successful, kill others?
|
2020-05-07 04:16:40 +08:00
|
|
|
# NOT WOKRING: first(".btn:nth(#{position-1})", text: text)
|
|
|
|
# Wait time could be problem. Find&First is witing until first element appear, but all is waiting until max wait
|
|
|
|
# time, what is 30s by default. This is why override with 1 second.
|
2020-05-06 15:13:24 +08:00
|
|
|
|
2020-07-06 21:06:19 +08:00
|
|
|
def check_active_team(team)
|
|
|
|
expect(page).to have_selector '#team-switch button', text: team
|
|
|
|
end
|
2020-05-06 15:13:24 +08:00
|
|
|
|
2020-05-07 03:10:49 +08:00
|
|
|
def sci_click_on_button(text:, position: 1)
|
2020-05-06 15:13:24 +08:00
|
|
|
raise 'Position cannot be lower than 1' if position < 1
|
|
|
|
|
|
|
|
if position == 1
|
2020-05-07 04:16:40 +08:00
|
|
|
btn = first('.btn', text: text)
|
2020-05-06 15:13:24 +08:00
|
|
|
else
|
2020-05-07 04:16:40 +08:00
|
|
|
btn = all('.btn', text: text, wait: 1)[position-1]
|
2020-05-06 15:13:24 +08:00
|
|
|
end
|
|
|
|
btn.click
|
|
|
|
end
|
|
|
|
|
2020-07-06 20:52:42 +08:00
|
|
|
def sci_click_on_icon(icon_class:, position: 1, container: nil)
|
2020-05-07 04:16:40 +08:00
|
|
|
raise 'Position cannot be lower than 1' if position < 1
|
|
|
|
|
2020-07-06 20:52:42 +08:00
|
|
|
scope = container ? find(container) : page
|
|
|
|
|
2020-05-06 15:13:24 +08:00
|
|
|
if position == 1
|
2020-07-06 20:52:42 +08:00
|
|
|
icon = scope.first(".fas.#{icon_class}")
|
2020-05-06 15:13:24 +08:00
|
|
|
else
|
2020-07-06 20:52:42 +08:00
|
|
|
icon = scope.all(".fas.#{icon_class}")[position-1]
|
2020-05-06 15:13:24 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
icon.click
|
|
|
|
end
|