selenium-cucumber 2.1.4 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/generate.rb +19 -20
- data/bin/helper.rb +50 -50
- data/bin/selenium-cucumber +29 -30
- data/doc/canned_steps.md +656 -656
- data/doc/installation.md +16 -16
- data/doc/selenium-cucumber-API.md +120 -120
- data/doc/selenium-cucumber-help.md +18 -18
- data/features-skeleton/my_first.feature +5 -5
- data/features-skeleton/step_definitions/custom_steps.rb +4 -4
- data/features-skeleton/support/env.rb +51 -51
- data/features-skeleton/support/hooks.rb +47 -38
- data/lib/selenium-cucumber.rb +1 -1
- data/lib/selenium-cucumber/assertion_steps.rb +89 -89
- data/lib/selenium-cucumber/click_elements_steps.rb +36 -36
- data/lib/selenium-cucumber/configuration_steps.rb +6 -6
- data/lib/selenium-cucumber/input_steps.rb +69 -69
- data/lib/selenium-cucumber/javascript_handling_steps.rb +9 -9
- data/lib/selenium-cucumber/methods/assertion_methods.rb +295 -344
- data/lib/selenium-cucumber/methods/click_elements_methods.rb +23 -23
- data/lib/selenium-cucumber/methods/configuration_methods.rb +35 -35
- data/lib/selenium-cucumber/methods/error_handling_methods.rb +86 -86
- data/lib/selenium-cucumber/methods/input_methods.rb +67 -67
- data/lib/selenium-cucumber/methods/javascript_handling_methods.rb +9 -9
- data/lib/selenium-cucumber/methods/misc_methods.rb +34 -34
- data/lib/selenium-cucumber/methods/mobile_methods.rb +241 -241
- data/lib/selenium-cucumber/methods/navigate_methods.rb +165 -165
- data/lib/selenium-cucumber/methods/progress_methods.rb +15 -15
- data/lib/selenium-cucumber/methods/required_files.rb +10 -10
- data/lib/selenium-cucumber/methods/screenshot_methods.rb +6 -6
- data/lib/selenium-cucumber/mobile_steps.rb +99 -99
- data/lib/selenium-cucumber/navigation_steps.rb +105 -105
- data/lib/selenium-cucumber/progress_steps.rb +18 -18
- data/lib/selenium-cucumber/screenshot_steps.rb +5 -5
- data/lib/selenium-cucumber/version.rb +5 -5
- metadata +69 -91
- data/example/android/android_app/HinduCalendar.zip +0 -0
- data/example/android/android_app/HinduCalendar/HinduCalendar.apk +0 -0
- data/example/android/android_app/HinduCalendar/README.md +0 -19
- data/example/android/android_app/HinduCalendar/Results.html +0 -472
- data/example/android/android_app/HinduCalendar/features/01_HC_homepage_menu_validation.feature +0 -36
- data/example/android/android_app/HinduCalendar/features/02_HC_homepage_menu_navigation.feature +0 -71
- data/example/android/android_app/HinduCalendar/features/03_HC_Create_Save_View_Delete_Kundali.feature +0 -63
- data/example/android/android_app/HinduCalendar/features/actual_images/test.png +0 -0
- data/example/android/android_app/HinduCalendar/features/expected_images/test.png +0 -0
- data/example/android/android_app/HinduCalendar/features/image_difference/test.png +0 -0
- data/example/android/android_app/HinduCalendar/features/my_first.feature +0 -1
- data/example/android/android_app/HinduCalendar/features/screenshots/test.png +0 -0
- data/example/android/android_app/HinduCalendar/features/step_definitions/01_HC_homepage_menu_validation.rb +0 -81
- data/example/android/android_app/HinduCalendar/features/step_definitions/02_HC_homepage_menu_navigation.rb +0 -132
- data/example/android/android_app/HinduCalendar/features/step_definitions/03_HC_Create_Save_View_Delete_Kundali.rb +0 -413
- data/example/android/android_app/HinduCalendar/features/step_definitions/custom_steps.rb +0 -5
- data/example/android/android_app/HinduCalendar/features/support/env.rb +0 -51
- data/example/android/android_app/HinduCalendar/features/support/hooks.rb +0 -38
- data/example/android/android_app/android_app_calculator.zip +0 -0
- data/example/android/android_app/android_app_calculator/AndroidCalculator.apk +0 -0
- data/example/android/android_app/android_app_calculator/features/actual_images/test.png +0 -0
- data/example/android/android_app/android_app_calculator/features/calculator.feature +0 -36
- data/example/android/android_app/android_app_calculator/features/expected_images/test.png +0 -0
- data/example/android/android_app/android_app_calculator/features/image_difference/test.png +0 -0
- data/example/android/android_app/android_app_calculator/features/my_first.feature +0 -13
- data/example/android/android_app/android_app_calculator/features/screenshots/test.png +0 -0
- data/example/android/android_app/android_app_calculator/features/step_definitions/custom_steps.rb +0 -5
- data/example/android/android_app/android_app_calculator/features/support/env.rb +0 -51
- data/example/android/android_app/android_app_calculator/features/support/hooks.rb +0 -38
- data/example/android/android_web/android_web_gmail_login.zip +0 -0
- data/example/android/android_web/android_web_gmail_login/features/actual_images/test.png +0 -0
- data/example/android/android_web/android_web_gmail_login/features/expected_images/test.png +0 -0
- data/example/android/android_web/android_web_gmail_login/features/gmail_login.feature +0 -12
- data/example/android/android_web/android_web_gmail_login/features/image_difference/test.png +0 -0
- data/example/android/android_web/android_web_gmail_login/features/my_first.feature +0 -1
- data/example/android/android_web/android_web_gmail_login/features/screenshots/test.png +0 -0
- data/example/android/android_web/android_web_gmail_login/features/step_definitions/custom_steps.rb +0 -5
- data/example/android/android_web/android_web_gmail_login/features/support/env.rb +0 -51
- data/example/android/android_web/android_web_gmail_login/features/support/hooks.rb +0 -38
- data/example/desktop web/desktop_web_gmail_login.zip +0 -0
- data/example/desktop web/desktop_web_gmail_login/features/actual_images/test.png +0 -0
- data/example/desktop web/desktop_web_gmail_login/features/expected_images/test.png +0 -0
- data/example/desktop web/desktop_web_gmail_login/features/gmail_login.feature +0 -10
- data/example/desktop web/desktop_web_gmail_login/features/gmail_multi_login.feature +0 -22
- data/example/desktop web/desktop_web_gmail_login/features/image_difference/test.png +0 -0
- data/example/desktop web/desktop_web_gmail_login/features/my_first.feature +0 -1
- data/example/desktop web/desktop_web_gmail_login/features/result.html b/data/example/desktop → web/desktop_web_gmail_login/features/result.html +0 -0
- data/example/desktop web/desktop_web_gmail_login/features/screenshots/test.png +0 -0
- data/example/desktop web/desktop_web_gmail_login/features/step_definitions/custom_steps.rb +0 -5
- data/example/desktop web/desktop_web_gmail_login/features/support/env.rb +0 -51
- data/example/desktop web/desktop_web_gmail_login/features/support/hooks.rb +0 -38
- data/example/desktop web/desktop_web_gmail_login/result.html +0 -478
data/lib/selenium-cucumber.rb
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Dir[File.dirname(__FILE__) + '/selenium-cucumber/*.rb'].each { |file| require file }
|
|
1
|
+
Dir[File.dirname(__FILE__) + '/selenium-cucumber/*.rb'].each { |file| require file }
|
|
@@ -1,89 +1,89 @@
|
|
|
1
|
-
require_relative 'methods/assertion_methods'
|
|
2
|
-
|
|
3
|
-
# page title checking
|
|
4
|
-
Then(/^I should\s*((?:not)?)\s+see page title as "(.*?)"$/) do |present, title|
|
|
5
|
-
check_title(title, present.empty?)
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
Then(/^I should\s*((?:not)?)\s+see page title having partial text as "(.*?)"$/) do |present, partial_text_title|
|
|
9
|
-
check_partial_title(partial_text_title, present.empty?)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# step to check element text
|
|
13
|
-
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have text as "(.*?)"$/) do |type, access_name, present, value |
|
|
14
|
-
validate_locator type
|
|
15
|
-
check_element_text(type, value, access_name, present.empty?)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# step to check element partial text
|
|
19
|
-
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have partial text as "(.*?)"$/) do |type, access_name, present, value |
|
|
20
|
-
validate_locator type
|
|
21
|
-
check_element_partial_text(type, value, access_name, present.empty?)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# step to check attribute value
|
|
25
|
-
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have attribute "(.*?)" with value "(.*?)"$/) do |type, access_name, present, attrb, value|
|
|
26
|
-
validate_locator type
|
|
27
|
-
check_element_attribute(type, attrb, value, access_name, present.empty?)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# step to check element enabled or not
|
|
31
|
-
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+be (enabled|disabled)$/) do |type, access_name, present, state|
|
|
32
|
-
validate_locator type
|
|
33
|
-
flag = state == 'enabled'
|
|
34
|
-
flag = !flag unless present.empty?
|
|
35
|
-
check_element_enable(type, access_name, flag)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
# step to check element present or not
|
|
39
|
-
Then(/^element having (.+) "(.*?)" should\s*((?:not)?)\s+be present$/) do |type, access_name, present|
|
|
40
|
-
validate_locator type
|
|
41
|
-
check_element_presence(type, access_name, present.empty?)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# step to assert checkbox is checked or unchecked
|
|
45
|
-
Then(/^checkbox having (.+) "(.*?)" should be (checked|unchecked)$/) do |type, access_name, state|
|
|
46
|
-
validate_locator type
|
|
47
|
-
flag = state == 'checked'
|
|
48
|
-
is_checkbox_checked(type, access_name, flag)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# steps to assert radio button checked or unchecked
|
|
52
|
-
Then(/^radio button having (.+) "(.*?)" should be (selected|unselected)$/) do |type, access_name, state|
|
|
53
|
-
validate_locator type
|
|
54
|
-
flag = state == 'selected'
|
|
55
|
-
is_radio_button_selected(type, access_name, flag)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# steps to assert option by text from radio button group selected/unselected
|
|
59
|
-
Then(/^option "(.*?)" by (.+) from radio button group having (.+) "(.*?)" should be (selected|unselected)$/) do |option, attrb, type, access_name, state|
|
|
60
|
-
validate_locator type
|
|
61
|
-
flag = state == 'selected'
|
|
62
|
-
is_option_from_radio_button_group_selected(type, attrb, option, access_name, flag)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# steps to check link presence
|
|
66
|
-
Then(/^link having text "(.*?)" should\s*((?:not)?)\s+be present$/) do |access_name, present|
|
|
67
|
-
check_element_presence('link', access_name, present.empty?)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
Then(/^link having partial text "(.*?)" should\s*((?:not)?)\s+be present$/) do |access_name, present|
|
|
71
|
-
check_element_presence('partial_link_text', access_name, present.empty?)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
# step to assert javascript pop-up alert text
|
|
75
|
-
Then(/^I should see alert text as "(.*?)"$/) do |actual_value|
|
|
76
|
-
check_alert_text(actual_value)
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
# step to assert dropdown list
|
|
80
|
-
Then(/^option "(.*?)" by (.+) from dropdown having (.+) "(.*?)" should be (selected|unselected)$/) do |option, by, type, access_name, state|
|
|
81
|
-
validate_locator type
|
|
82
|
-
flag = state == 'selected'
|
|
83
|
-
is_option_from_dropdown_selected(type, by, option, access_name, state)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
# step to assert difference in images
|
|
87
|
-
Then(/^actual image having (.+) "(.*?)" and expected image having (.+) "(.*?)" should be similar$/) do |actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name|
|
|
88
|
-
does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
|
|
89
|
-
end
|
|
1
|
+
require_relative 'methods/assertion_methods'
|
|
2
|
+
|
|
3
|
+
# page title checking
|
|
4
|
+
Then(/^I should\s*((?:not)?)\s+see page title as "(.*?)"$/) do |present, title|
|
|
5
|
+
check_title(title, present.empty?)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
Then(/^I should\s*((?:not)?)\s+see page title having partial text as "(.*?)"$/) do |present, partial_text_title|
|
|
9
|
+
check_partial_title(partial_text_title, present.empty?)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# step to check element text
|
|
13
|
+
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have text as "(.*?)"$/) do |type, access_name, present, value |
|
|
14
|
+
validate_locator type
|
|
15
|
+
check_element_text(type, value, access_name, present.empty?)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# step to check element partial text
|
|
19
|
+
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have partial text as "(.*?)"$/) do |type, access_name, present, value |
|
|
20
|
+
validate_locator type
|
|
21
|
+
check_element_partial_text(type, value, access_name, present.empty?)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# step to check attribute value
|
|
25
|
+
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have attribute "(.*?)" with value "(.*?)"$/) do |type, access_name, present, attrb, value|
|
|
26
|
+
validate_locator type
|
|
27
|
+
check_element_attribute(type, attrb, value, access_name, present.empty?)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# step to check element enabled or not
|
|
31
|
+
Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+be (enabled|disabled)$/) do |type, access_name, present, state|
|
|
32
|
+
validate_locator type
|
|
33
|
+
flag = state == 'enabled'
|
|
34
|
+
flag = !flag unless present.empty?
|
|
35
|
+
check_element_enable(type, access_name, flag)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# step to check element present or not
|
|
39
|
+
Then(/^element having (.+) "(.*?)" should\s*((?:not)?)\s+be present$/) do |type, access_name, present|
|
|
40
|
+
validate_locator type
|
|
41
|
+
check_element_presence(type, access_name, present.empty?)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# step to assert checkbox is checked or unchecked
|
|
45
|
+
Then(/^checkbox having (.+) "(.*?)" should be (checked|unchecked)$/) do |type, access_name, state|
|
|
46
|
+
validate_locator type
|
|
47
|
+
flag = state == 'checked'
|
|
48
|
+
is_checkbox_checked(type, access_name, flag)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# steps to assert radio button checked or unchecked
|
|
52
|
+
Then(/^radio button having (.+) "(.*?)" should be (selected|unselected)$/) do |type, access_name, state|
|
|
53
|
+
validate_locator type
|
|
54
|
+
flag = state == 'selected'
|
|
55
|
+
is_radio_button_selected(type, access_name, flag)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# steps to assert option by text from radio button group selected/unselected
|
|
59
|
+
Then(/^option "(.*?)" by (.+) from radio button group having (.+) "(.*?)" should be (selected|unselected)$/) do |option, attrb, type, access_name, state|
|
|
60
|
+
validate_locator type
|
|
61
|
+
flag = state == 'selected'
|
|
62
|
+
is_option_from_radio_button_group_selected(type, attrb, option, access_name, flag)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# steps to check link presence
|
|
66
|
+
Then(/^link having text "(.*?)" should\s*((?:not)?)\s+be present$/) do |access_name, present|
|
|
67
|
+
check_element_presence('link', access_name, present.empty?)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
Then(/^link having partial text "(.*?)" should\s*((?:not)?)\s+be present$/) do |access_name, present|
|
|
71
|
+
check_element_presence('partial_link_text', access_name, present.empty?)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# step to assert javascript pop-up alert text
|
|
75
|
+
Then(/^I should see alert text as "(.*?)"$/) do |actual_value|
|
|
76
|
+
check_alert_text(actual_value)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# step to assert dropdown list
|
|
80
|
+
Then(/^option "(.*?)" by (.+) from dropdown having (.+) "(.*?)" should be (selected|unselected)$/) do |option, by, type, access_name, state|
|
|
81
|
+
validate_locator type
|
|
82
|
+
flag = state == 'selected'
|
|
83
|
+
is_option_from_dropdown_selected(type, by, option, access_name, state)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# step to assert difference in images
|
|
87
|
+
Then(/^actual image having (.+) "(.*?)" and expected image having (.+) "(.*?)" should be similar$/) do |actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name|
|
|
88
|
+
does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
|
|
89
|
+
end
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
require_relative 'methods/click_elements_methods'
|
|
2
|
-
|
|
3
|
-
# click on web element
|
|
4
|
-
When(/^I click on element having (.+) "(.*?)"$/) do |type, access_name|
|
|
5
|
-
validate_locator type
|
|
6
|
-
click(type, access_name)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
Then(/^I forcefully click on element having (.+) "(.*?)"$/) do |type, access_name|
|
|
10
|
-
validate_locator type
|
|
11
|
-
click_forcefully(type, access_name)
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# double click on web element
|
|
15
|
-
Then(/^I double click on element having (.+) "(.*?)"$/) do |type, access_value|
|
|
16
|
-
validate_locator type
|
|
17
|
-
double_click(type, access_value)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
# steps to click on link
|
|
21
|
-
Then(/^I click on link having text "(.*?)"$/) do |access_name|
|
|
22
|
-
click('link', access_name)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
Then(/^I click on link having partial text "(.*?)"$/) do |access_name|
|
|
26
|
-
click('partial_link_text', access_name)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
When(/^I tap on element having (.+) "(.*?)"$/) do |type, access_name|
|
|
30
|
-
validate_locator type
|
|
31
|
-
click(type, access_name)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
require_relative 'methods/click_elements_methods'
|
|
2
|
+
|
|
3
|
+
# click on web element
|
|
4
|
+
When(/^I click on element having (.+) "(.*?)"$/) do |type, access_name|
|
|
5
|
+
validate_locator type
|
|
6
|
+
click(type, access_name)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
Then(/^I forcefully click on element having (.+) "(.*?)"$/) do |type, access_name|
|
|
10
|
+
validate_locator type
|
|
11
|
+
click_forcefully(type, access_name)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# double click on web element
|
|
15
|
+
Then(/^I double click on element having (.+) "(.*?)"$/) do |type, access_value|
|
|
16
|
+
validate_locator type
|
|
17
|
+
double_click(type, access_value)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# steps to click on link
|
|
21
|
+
Then(/^I click on link having text "(.*?)"$/) do |access_name|
|
|
22
|
+
click('link', access_name)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
Then(/^I click on link having partial text "(.*?)"$/) do |access_name|
|
|
26
|
+
click('partial_link_text', access_name)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
When(/^I tap on element having (.+) "(.*?)"$/) do |type, access_name|
|
|
30
|
+
validate_locator type
|
|
31
|
+
click(type, access_name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require_relative 'methods/configuration_methods'
|
|
2
|
-
|
|
3
|
-
# step to print configuration
|
|
4
|
-
Then(/^I print configuration$/) do
|
|
5
|
-
print_congifugartion
|
|
6
|
-
end
|
|
1
|
+
require_relative 'methods/configuration_methods'
|
|
2
|
+
|
|
3
|
+
# step to print configuration
|
|
4
|
+
Then(/^I print configuration$/) do
|
|
5
|
+
print_congifugartion
|
|
6
|
+
end
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
require_relative 'methods/input_methods'
|
|
2
|
-
|
|
3
|
-
# enter text into input field steps
|
|
4
|
-
Then(/^I enter "([^\"]*)" into input field having (.+) "([^\"]*)"$/) do |text, type, access_name|
|
|
5
|
-
validate_locator type
|
|
6
|
-
enter_text(type, text, access_name)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
# clear input field steps
|
|
10
|
-
Then(/^I clear input field having (.+) "([^\"]*)"$/) do |type, access_name|
|
|
11
|
-
validate_locator type
|
|
12
|
-
clear_text(type, access_name)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# select option by text/value from dropdown/multiselect
|
|
16
|
-
Then(/^I select "(.*?)" option by (.+) from\s*((?:multiselect)?)\sdropdown having (.+) "(.*?)"$/) do |option, option_by, present, type, access_name|
|
|
17
|
-
validate_locator type
|
|
18
|
-
validate_option_by option_by
|
|
19
|
-
select_option_from_dropdown(type, option_by, option, access_name)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
# select option by index from dropdown/multiselect
|
|
23
|
-
Then(/^I select (\d+) option by index from\s*((?:multiselect)?)\sdropdown having (.+) "(.*?)"$/) do |option, present, type, access_name|
|
|
24
|
-
validate_locator type
|
|
25
|
-
select_option_from_dropdown(type, 'index', (option.to_i) -1, access_name)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
# step to select option from mutliselect dropdown list
|
|
29
|
-
Then(/^I select all options from multiselect dropdown having (.+) "(.*?)"$/) do |type, access_name|
|
|
30
|
-
validate_locator type
|
|
31
|
-
select_all_option_from_multiselect_dropdown(type, access_name)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# step to unselect option from mutliselect dropdown list
|
|
35
|
-
Then(/^I unselect all options from multiselect dropdown having (.+) "(.*?)"$/) do |type, access_name|
|
|
36
|
-
validate_locator type
|
|
37
|
-
unselect_all_option_from_multiselect_dropdown(type, access_name)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
# check checkbox steps
|
|
41
|
-
Then(/^I check the checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
|
42
|
-
validate_locator type
|
|
43
|
-
check_checkbox(type, access_name)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
# uncheck checkbox steps
|
|
47
|
-
Then(/^I uncheck the checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
|
48
|
-
validate_locator type
|
|
49
|
-
uncheck_checkbox(type, access_name)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
# steps to toggle checkbox
|
|
53
|
-
Then(/^I toggle checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
|
54
|
-
validate_locator type
|
|
55
|
-
toggle_checkbox(type, access_name)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
# step to select radio button
|
|
59
|
-
Then(/^I select radio button having (.+) "(.*?)"$/) do |type, access_name|
|
|
60
|
-
validate_locator type
|
|
61
|
-
select_radio_button(type, access_name)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
# steps to select option by text from radio button group
|
|
65
|
-
Then(/^I select "(.*?)" option by (.+) from radio button group having (.+) "(.*?)"$/) do |option, option_by, type, access_name|
|
|
66
|
-
validate_locator type
|
|
67
|
-
validate_option_by option_by
|
|
68
|
-
select_option_from_radio_button_group(type, option_by, option, access_name)
|
|
69
|
-
end
|
|
1
|
+
require_relative 'methods/input_methods'
|
|
2
|
+
|
|
3
|
+
# enter text into input field steps
|
|
4
|
+
Then(/^I enter "([^\"]*)" into input field having (.+) "([^\"]*)"$/) do |text, type, access_name|
|
|
5
|
+
validate_locator type
|
|
6
|
+
enter_text(type, text, access_name)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
# clear input field steps
|
|
10
|
+
Then(/^I clear input field having (.+) "([^\"]*)"$/) do |type, access_name|
|
|
11
|
+
validate_locator type
|
|
12
|
+
clear_text(type, access_name)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# select option by text/value from dropdown/multiselect
|
|
16
|
+
Then(/^I select "(.*?)" option by (.+) from\s*((?:multiselect)?)\sdropdown having (.+) "(.*?)"$/) do |option, option_by, present, type, access_name|
|
|
17
|
+
validate_locator type
|
|
18
|
+
validate_option_by option_by
|
|
19
|
+
select_option_from_dropdown(type, option_by, option, access_name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# select option by index from dropdown/multiselect
|
|
23
|
+
Then(/^I select (\d+) option by index from\s*((?:multiselect)?)\sdropdown having (.+) "(.*?)"$/) do |option, present, type, access_name|
|
|
24
|
+
validate_locator type
|
|
25
|
+
select_option_from_dropdown(type, 'index', (option.to_i) -1, access_name)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# step to select option from mutliselect dropdown list
|
|
29
|
+
Then(/^I select all options from multiselect dropdown having (.+) "(.*?)"$/) do |type, access_name|
|
|
30
|
+
validate_locator type
|
|
31
|
+
select_all_option_from_multiselect_dropdown(type, access_name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# step to unselect option from mutliselect dropdown list
|
|
35
|
+
Then(/^I unselect all options from multiselect dropdown having (.+) "(.*?)"$/) do |type, access_name|
|
|
36
|
+
validate_locator type
|
|
37
|
+
unselect_all_option_from_multiselect_dropdown(type, access_name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# check checkbox steps
|
|
41
|
+
Then(/^I check the checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
|
42
|
+
validate_locator type
|
|
43
|
+
check_checkbox(type, access_name)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# uncheck checkbox steps
|
|
47
|
+
Then(/^I uncheck the checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
|
48
|
+
validate_locator type
|
|
49
|
+
uncheck_checkbox(type, access_name)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# steps to toggle checkbox
|
|
53
|
+
Then(/^I toggle checkbox having (.+) "(.*?)"$/) do |type, access_name|
|
|
54
|
+
validate_locator type
|
|
55
|
+
toggle_checkbox(type, access_name)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# step to select radio button
|
|
59
|
+
Then(/^I select radio button having (.+) "(.*?)"$/) do |type, access_name|
|
|
60
|
+
validate_locator type
|
|
61
|
+
select_radio_button(type, access_name)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# steps to select option by text from radio button group
|
|
65
|
+
Then(/^I select "(.*?)" option by (.+) from radio button group having (.+) "(.*?)"$/) do |option, option_by, type, access_name|
|
|
66
|
+
validate_locator type
|
|
67
|
+
validate_option_by option_by
|
|
68
|
+
select_option_from_radio_button_group(type, option_by, option, access_name)
|
|
69
|
+
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
require_relative 'methods/javascript_handling_methods'
|
|
2
|
-
|
|
3
|
-
Then(/^I accept alert$/) do
|
|
4
|
-
handle_alert('accept')
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
Then(/^I dismiss alert$/) do
|
|
8
|
-
handle_alert('dismiss')
|
|
9
|
-
end
|
|
1
|
+
require_relative 'methods/javascript_handling_methods'
|
|
2
|
+
|
|
3
|
+
Then(/^I accept alert$/) do
|
|
4
|
+
handle_alert('accept')
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
Then(/^I dismiss alert$/) do
|
|
8
|
+
handle_alert('dismiss')
|
|
9
|
+
end
|
|
@@ -1,344 +1,295 @@
|
|
|
1
|
-
require 'net/https'
|
|
2
|
-
require_relative 'required_files'
|
|
3
|
-
|
|
4
|
-
# This file contains assertion methods which are called from assertion_steps.rb
|
|
5
|
-
|
|
6
|
-
# Method to return page title
|
|
7
|
-
def get_page_title
|
|
8
|
-
$driver.title
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
# Method to verify title
|
|
12
|
-
# param 1 : String : expected title
|
|
13
|
-
# param 2 : Boolean : test case [true or flase]
|
|
14
|
-
def check_title(title, test_case)
|
|
15
|
-
page_title = get_page_title
|
|
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
|
-
# param
|
|
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
|
-
# param
|
|
97
|
-
|
|
98
|
-
#
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
#
|
|
119
|
-
# param
|
|
120
|
-
# param
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# method to
|
|
139
|
-
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
140
|
-
# param 2 : String : Locator value
|
|
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
|
-
if
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
#
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if
|
|
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
|
-
# Verify image extension and call respective compare function
|
|
298
|
-
if image_type == 'png'
|
|
299
|
-
return compare_png_images(expected_img_url, actual_img_url)
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
compare_jpeg_images(expected_img_url, actual_img_url)
|
|
303
|
-
end
|
|
304
|
-
|
|
305
|
-
# Comparing jpg images
|
|
306
|
-
def compare_jpeg_images(expected_img_url, actual_img_url)
|
|
307
|
-
if open(expected_img_url).read == open(actual_img_url).read
|
|
308
|
-
return true
|
|
309
|
-
else
|
|
310
|
-
puts 'Difference in images'
|
|
311
|
-
return false
|
|
312
|
-
end
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
# Comparing png images
|
|
316
|
-
def compare_png_images(expected_img_url, actual_img_url)
|
|
317
|
-
images = [
|
|
318
|
-
ChunkyPNG::Image.from_file(expected_img_url),
|
|
319
|
-
ChunkyPNG::Image.from_file(actual_img_url)
|
|
320
|
-
]
|
|
321
|
-
|
|
322
|
-
diff = []
|
|
323
|
-
|
|
324
|
-
images.first.height.times do |y|
|
|
325
|
-
images.first.row(y).each_with_index do |pixel, x|
|
|
326
|
-
diff << [x, y] unless pixel == images.last[x, y]
|
|
327
|
-
end
|
|
328
|
-
end
|
|
329
|
-
|
|
330
|
-
if diff.length != 0
|
|
331
|
-
puts "\npixels (total): #{images.first.pixels.length}"
|
|
332
|
-
puts "pixels changed: #{diff.length}"
|
|
333
|
-
puts "pixels changed (%): #{(diff.length.to_f / images.first.pixels.length) * 100}%"
|
|
334
|
-
|
|
335
|
-
x, y = diff.map { |xy| xy[0] }, diff.map { |xy| xy[1] }
|
|
336
|
-
images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0, 255, 0))
|
|
337
|
-
cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
|
|
338
|
-
images.last.save("./features/image_difference/difference_#{cur_time}.png")
|
|
339
|
-
|
|
340
|
-
puts "\nDifference between images saved as : difference_#{cur_time}.png\n"
|
|
341
|
-
return false
|
|
342
|
-
end
|
|
343
|
-
true
|
|
344
|
-
end
|
|
1
|
+
require 'net/https'
|
|
2
|
+
require_relative 'required_files'
|
|
3
|
+
|
|
4
|
+
# This file contains assertion methods which are called from assertion_steps.rb
|
|
5
|
+
|
|
6
|
+
# Method to return page title
|
|
7
|
+
def get_page_title
|
|
8
|
+
$driver.title
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Method to verify title
|
|
12
|
+
# param 1 : String : expected title
|
|
13
|
+
# param 2 : Boolean : test case [true or flase]
|
|
14
|
+
def check_title(title, test_case)
|
|
15
|
+
page_title = get_page_title
|
|
16
|
+
|
|
17
|
+
if test_case
|
|
18
|
+
expect(page_title).to eq title
|
|
19
|
+
else
|
|
20
|
+
expect(page_title).to_not eq title
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Method to verify partial title
|
|
25
|
+
# param 1 : String : partial title string
|
|
26
|
+
# param 2 : Boolean : test case [true or flase]
|
|
27
|
+
def check_partial_title(partial_text_title, test_case)
|
|
28
|
+
page_title = get_page_title
|
|
29
|
+
|
|
30
|
+
if test_case
|
|
31
|
+
expect(page_title).to include(partial_text_title)
|
|
32
|
+
else
|
|
33
|
+
expect(page_title).to_not include(partial_text_title)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Method to get element text
|
|
38
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
39
|
+
# param 2 : String : Locator value
|
|
40
|
+
def get_element_text(access_type, access_name)
|
|
41
|
+
$driver.find_element(:"#{access_type}" => "#{access_name}").text
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Method to check element text
|
|
45
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
46
|
+
# param 2 : String : Expected element text
|
|
47
|
+
# param 3 : String : Locator value
|
|
48
|
+
# param 4 : Boolean : test case [true or flase]
|
|
49
|
+
def check_element_text(access_type, expected_value, access_name, test_case)
|
|
50
|
+
element_text = get_element_text(access_type, access_name)
|
|
51
|
+
if test_case
|
|
52
|
+
expect(element_text).to eq expected_value
|
|
53
|
+
else
|
|
54
|
+
expect(element_text).to_not eq expected_value
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Method to check partial element text
|
|
59
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
60
|
+
# param 2 : String : Expected element partial text
|
|
61
|
+
# param 3 : String : Locator value
|
|
62
|
+
# param 4 : Boolean : test case [true or flase]
|
|
63
|
+
def check_element_partial_text(access_type, expected_value, access_name, test_case)
|
|
64
|
+
element_text = get_element_text(access_type, access_name)
|
|
65
|
+
|
|
66
|
+
if test_case
|
|
67
|
+
expect(element_text).to include(expected_value)
|
|
68
|
+
else
|
|
69
|
+
expect(element_text).to_not include(expected_value)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Method to return element status - enabled?
|
|
74
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
75
|
+
# param 2 : String : Locator value
|
|
76
|
+
def is_element_enabled(access_type, access_name)
|
|
77
|
+
$driver.find_element(:"#{access_type}" => "#{access_name}").enabled?
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Element enabled checking
|
|
81
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
82
|
+
# param 2 : String : Expected element text
|
|
83
|
+
# param 4 : Boolean : test case [true or flase]
|
|
84
|
+
def check_element_enable(access_type, access_name, test_case)
|
|
85
|
+
result = is_element_enabled(access_type, access_name)
|
|
86
|
+
if test_case
|
|
87
|
+
expect(result).to be true
|
|
88
|
+
else
|
|
89
|
+
expect(result).to be false
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# method to get attribute value
|
|
94
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
95
|
+
# param 2 : String : Expected element text
|
|
96
|
+
# param 3 : String : atrribute name
|
|
97
|
+
def get_element_attribute(access_type, access_name, attribute_name)
|
|
98
|
+
$driver.find_element(:"#{access_type}" => "#{access_name}").attribute("#{attribute_name}")
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# method to check attribute value
|
|
102
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
103
|
+
# param 2 : String : atrribute name
|
|
104
|
+
# param 3 : String : atrribute value
|
|
105
|
+
# param 4 : String : Locator value
|
|
106
|
+
# param 5 : Boolean : test case [true or flase]
|
|
107
|
+
def check_element_attribute(access_type, attribute_name, attribute_value, access_name, test_case)
|
|
108
|
+
|
|
109
|
+
attr_val = get_element_attribute(access_type, access_name, attribute_name)
|
|
110
|
+
|
|
111
|
+
if test_case
|
|
112
|
+
expect(attr_val).to eq(attribute_value)
|
|
113
|
+
else
|
|
114
|
+
expect(attr_val).to_not eq(attribute_value)
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# method to get element status - displayed?
|
|
119
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
120
|
+
# param 2 : String : Locator value
|
|
121
|
+
def is_element_displayed(access_type, access_name)
|
|
122
|
+
begin
|
|
123
|
+
$driver.find_element(:"#{access_type}" => "#{access_name}").displayed?
|
|
124
|
+
rescue Selenium::WebDriver::Error::NoSuchElementError
|
|
125
|
+
# elements not found return false
|
|
126
|
+
false
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
# method to check element presence
|
|
131
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
132
|
+
# param 2 : String : Locator value
|
|
133
|
+
# param 3 : Boolean : test case [true or flase]
|
|
134
|
+
def check_element_presence(access_type, access_name, test_case)
|
|
135
|
+
expect(is_element_displayed(access_type, access_name)).to be test_case
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
# method to assert checkbox check/uncheck
|
|
139
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
140
|
+
# param 2 : String : Locator value
|
|
141
|
+
# param 3 : Boolean : test case [true or flase]
|
|
142
|
+
def is_checkbox_checked(access_type, access_name, should_be_checked = true)
|
|
143
|
+
checkbox = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
|
144
|
+
|
|
145
|
+
expect(checkbox.selected?).to be should_be_checked
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# method to assert radio button selected/unselected
|
|
149
|
+
# param 1 : String : Locator type (id, name, class, xpath, css)
|
|
150
|
+
# param 2 : String : Locator value
|
|
151
|
+
# param 3 : Boolean : test case [true or flase]
|
|
152
|
+
def is_radio_button_selected(access_type, access_name, should_be_selected = true)
|
|
153
|
+
radio_button = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
|
154
|
+
expect(radio_button.selected?).to be should_be_selected
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# method to assert option from radio button group is selected/unselected
|
|
158
|
+
def is_option_from_radio_button_group_selected(access_type, by, option, access_name, should_be_selected = true)
|
|
159
|
+
radio_button_group = $driver.find_elements(:"#{access_type}" => "#{access_name}")
|
|
160
|
+
|
|
161
|
+
getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text }
|
|
162
|
+
|
|
163
|
+
ele = radio_button_group.find { |rb| getter.call(rb, by) == option }
|
|
164
|
+
|
|
165
|
+
expect(ele.selected?).to be should_be_selected
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# method to get javascript pop-up alert text
|
|
169
|
+
def get_alert_text
|
|
170
|
+
$driver.switch_to.alert.text
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# method to check javascript pop-up alert text
|
|
174
|
+
def check_alert_text(text)
|
|
175
|
+
expect(get_alert_text).to eq text
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
def is_option_from_dropdown_selected(access_type, by, option, access_name, should_be_selected=true)
|
|
179
|
+
dropdown = $driver.find_element(:"#{access_type}" => "#{access_name}")
|
|
180
|
+
select_list = Selenium::WebDriver::Support::Select.new(dropdown)
|
|
181
|
+
|
|
182
|
+
if by == 'text'
|
|
183
|
+
actual_value = select_list.first_selected_option.text
|
|
184
|
+
else
|
|
185
|
+
actual_value = select_list.first_selected_option.attribute('value')
|
|
186
|
+
end
|
|
187
|
+
expect(actual_value).to eq option
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Method to find difference between images
|
|
191
|
+
def does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
|
|
192
|
+
if !compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
|
|
193
|
+
raise TestCaseFailed, 'Actual image is different from expected image'
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# Method to compare two images
|
|
198
|
+
# param 1 : String : Locator type (id, name, class, xpath, css, url)
|
|
199
|
+
# param 2 : String : Locator value
|
|
200
|
+
# param 3 : String : Locator type (id, name, class, xpath, css, url, image_name)
|
|
201
|
+
# param 4 : String : Locator value
|
|
202
|
+
def compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
|
|
203
|
+
if actual_img_access_type == 'url'
|
|
204
|
+
actual_img_url = actual_img_access_name
|
|
205
|
+
else
|
|
206
|
+
actual_img_url = get_element_attribute(actual_img_access_type, actual_img_access_name, 'src')
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
if excp_img_access_type == 'url'
|
|
210
|
+
expected_img_url = excp_img_access_name
|
|
211
|
+
elsif excp_img_access_type == 'image_name'
|
|
212
|
+
expected_img_url = './features/expected_images/' + excp_img_access_name
|
|
213
|
+
else
|
|
214
|
+
expected_img_url = get_element_attribute(excp_img_access_type, excp_img_access_name, 'src')
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# replace 'https' with 'http' from actual image url
|
|
218
|
+
if actual_img_url.include? 'https'
|
|
219
|
+
actual_img_url['https'] = 'http'
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# replace 'https' with 'http' from expected image url
|
|
223
|
+
if expected_img_url.include? 'https'
|
|
224
|
+
expected_img_url['https'] = 'http'
|
|
225
|
+
end
|
|
226
|
+
|
|
227
|
+
if expected_img_url.include? '.png'
|
|
228
|
+
image_type = 'png'
|
|
229
|
+
else
|
|
230
|
+
image_type = 'jpg'
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Storing actual image locally
|
|
234
|
+
open('./features/actual_images/actual_image.' + image_type, 'wb') do |file|
|
|
235
|
+
file << open(actual_img_url).read
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
actual_img_url = './features/actual_images/actual_image.' + image_type
|
|
239
|
+
|
|
240
|
+
# Storing Expected image locally
|
|
241
|
+
if excp_img_access_type != 'image_name'
|
|
242
|
+
open('./features/expected_images/expected_image.' + image_type, 'wb') do |file|
|
|
243
|
+
file << open(expected_img_url).read
|
|
244
|
+
end
|
|
245
|
+
expected_img_url = './features/expected_images/expected_image.' + image_type
|
|
246
|
+
end
|
|
247
|
+
|
|
248
|
+
# Verify image extension and call respective compare function
|
|
249
|
+
if image_type == 'png'
|
|
250
|
+
return compare_png_images(expected_img_url, actual_img_url)
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
compare_jpeg_images(expected_img_url, actual_img_url)
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
# Comparing jpg images
|
|
257
|
+
def compare_jpeg_images(expected_img_url, actual_img_url)
|
|
258
|
+
if open(expected_img_url).read == open(actual_img_url).read
|
|
259
|
+
return true
|
|
260
|
+
else
|
|
261
|
+
puts 'Difference in images'
|
|
262
|
+
return false
|
|
263
|
+
end
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
# Comparing png images
|
|
267
|
+
def compare_png_images(expected_img_url, actual_img_url)
|
|
268
|
+
images = [
|
|
269
|
+
ChunkyPNG::Image.from_file(expected_img_url),
|
|
270
|
+
ChunkyPNG::Image.from_file(actual_img_url)
|
|
271
|
+
]
|
|
272
|
+
|
|
273
|
+
diff = []
|
|
274
|
+
|
|
275
|
+
images.first.height.times do |y|
|
|
276
|
+
images.first.row(y).each_with_index do |pixel, x|
|
|
277
|
+
diff << [x, y] unless pixel == images.last[x, y]
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
if diff.length != 0
|
|
282
|
+
puts "\npixels (total): #{images.first.pixels.length}"
|
|
283
|
+
puts "pixels changed: #{diff.length}"
|
|
284
|
+
puts "pixels changed (%): #{(diff.length.to_f / images.first.pixels.length) * 100}%"
|
|
285
|
+
|
|
286
|
+
x, y = diff.map { |xy| xy[0] }, diff.map { |xy| xy[1] }
|
|
287
|
+
images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0, 255, 0))
|
|
288
|
+
cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
|
|
289
|
+
images.last.save("./features/image_difference/difference_#{cur_time}.png")
|
|
290
|
+
|
|
291
|
+
puts "\nDifference between images saved as : difference_#{cur_time}.png\n"
|
|
292
|
+
return false
|
|
293
|
+
end
|
|
294
|
+
true
|
|
295
|
+
end
|