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.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/bin/generate.rb +19 -20
  3. data/bin/helper.rb +50 -50
  4. data/bin/selenium-cucumber +29 -30
  5. data/doc/canned_steps.md +656 -656
  6. data/doc/installation.md +16 -16
  7. data/doc/selenium-cucumber-API.md +120 -120
  8. data/doc/selenium-cucumber-help.md +18 -18
  9. data/features-skeleton/my_first.feature +5 -5
  10. data/features-skeleton/step_definitions/custom_steps.rb +4 -4
  11. data/features-skeleton/support/env.rb +51 -51
  12. data/features-skeleton/support/hooks.rb +47 -38
  13. data/lib/selenium-cucumber.rb +1 -1
  14. data/lib/selenium-cucumber/assertion_steps.rb +89 -89
  15. data/lib/selenium-cucumber/click_elements_steps.rb +36 -36
  16. data/lib/selenium-cucumber/configuration_steps.rb +6 -6
  17. data/lib/selenium-cucumber/input_steps.rb +69 -69
  18. data/lib/selenium-cucumber/javascript_handling_steps.rb +9 -9
  19. data/lib/selenium-cucumber/methods/assertion_methods.rb +295 -344
  20. data/lib/selenium-cucumber/methods/click_elements_methods.rb +23 -23
  21. data/lib/selenium-cucumber/methods/configuration_methods.rb +35 -35
  22. data/lib/selenium-cucumber/methods/error_handling_methods.rb +86 -86
  23. data/lib/selenium-cucumber/methods/input_methods.rb +67 -67
  24. data/lib/selenium-cucumber/methods/javascript_handling_methods.rb +9 -9
  25. data/lib/selenium-cucumber/methods/misc_methods.rb +34 -34
  26. data/lib/selenium-cucumber/methods/mobile_methods.rb +241 -241
  27. data/lib/selenium-cucumber/methods/navigate_methods.rb +165 -165
  28. data/lib/selenium-cucumber/methods/progress_methods.rb +15 -15
  29. data/lib/selenium-cucumber/methods/required_files.rb +10 -10
  30. data/lib/selenium-cucumber/methods/screenshot_methods.rb +6 -6
  31. data/lib/selenium-cucumber/mobile_steps.rb +99 -99
  32. data/lib/selenium-cucumber/navigation_steps.rb +105 -105
  33. data/lib/selenium-cucumber/progress_steps.rb +18 -18
  34. data/lib/selenium-cucumber/screenshot_steps.rb +5 -5
  35. data/lib/selenium-cucumber/version.rb +5 -5
  36. metadata +69 -91
  37. data/example/android/android_app/HinduCalendar.zip +0 -0
  38. data/example/android/android_app/HinduCalendar/HinduCalendar.apk +0 -0
  39. data/example/android/android_app/HinduCalendar/README.md +0 -19
  40. data/example/android/android_app/HinduCalendar/Results.html +0 -472
  41. data/example/android/android_app/HinduCalendar/features/01_HC_homepage_menu_validation.feature +0 -36
  42. data/example/android/android_app/HinduCalendar/features/02_HC_homepage_menu_navigation.feature +0 -71
  43. data/example/android/android_app/HinduCalendar/features/03_HC_Create_Save_View_Delete_Kundali.feature +0 -63
  44. data/example/android/android_app/HinduCalendar/features/actual_images/test.png +0 -0
  45. data/example/android/android_app/HinduCalendar/features/expected_images/test.png +0 -0
  46. data/example/android/android_app/HinduCalendar/features/image_difference/test.png +0 -0
  47. data/example/android/android_app/HinduCalendar/features/my_first.feature +0 -1
  48. data/example/android/android_app/HinduCalendar/features/screenshots/test.png +0 -0
  49. data/example/android/android_app/HinduCalendar/features/step_definitions/01_HC_homepage_menu_validation.rb +0 -81
  50. data/example/android/android_app/HinduCalendar/features/step_definitions/02_HC_homepage_menu_navigation.rb +0 -132
  51. data/example/android/android_app/HinduCalendar/features/step_definitions/03_HC_Create_Save_View_Delete_Kundali.rb +0 -413
  52. data/example/android/android_app/HinduCalendar/features/step_definitions/custom_steps.rb +0 -5
  53. data/example/android/android_app/HinduCalendar/features/support/env.rb +0 -51
  54. data/example/android/android_app/HinduCalendar/features/support/hooks.rb +0 -38
  55. data/example/android/android_app/android_app_calculator.zip +0 -0
  56. data/example/android/android_app/android_app_calculator/AndroidCalculator.apk +0 -0
  57. data/example/android/android_app/android_app_calculator/features/actual_images/test.png +0 -0
  58. data/example/android/android_app/android_app_calculator/features/calculator.feature +0 -36
  59. data/example/android/android_app/android_app_calculator/features/expected_images/test.png +0 -0
  60. data/example/android/android_app/android_app_calculator/features/image_difference/test.png +0 -0
  61. data/example/android/android_app/android_app_calculator/features/my_first.feature +0 -13
  62. data/example/android/android_app/android_app_calculator/features/screenshots/test.png +0 -0
  63. data/example/android/android_app/android_app_calculator/features/step_definitions/custom_steps.rb +0 -5
  64. data/example/android/android_app/android_app_calculator/features/support/env.rb +0 -51
  65. data/example/android/android_app/android_app_calculator/features/support/hooks.rb +0 -38
  66. data/example/android/android_web/android_web_gmail_login.zip +0 -0
  67. data/example/android/android_web/android_web_gmail_login/features/actual_images/test.png +0 -0
  68. data/example/android/android_web/android_web_gmail_login/features/expected_images/test.png +0 -0
  69. data/example/android/android_web/android_web_gmail_login/features/gmail_login.feature +0 -12
  70. data/example/android/android_web/android_web_gmail_login/features/image_difference/test.png +0 -0
  71. data/example/android/android_web/android_web_gmail_login/features/my_first.feature +0 -1
  72. data/example/android/android_web/android_web_gmail_login/features/screenshots/test.png +0 -0
  73. data/example/android/android_web/android_web_gmail_login/features/step_definitions/custom_steps.rb +0 -5
  74. data/example/android/android_web/android_web_gmail_login/features/support/env.rb +0 -51
  75. data/example/android/android_web/android_web_gmail_login/features/support/hooks.rb +0 -38
  76. data/example/desktop web/desktop_web_gmail_login.zip +0 -0
  77. data/example/desktop web/desktop_web_gmail_login/features/actual_images/test.png +0 -0
  78. data/example/desktop web/desktop_web_gmail_login/features/expected_images/test.png +0 -0
  79. data/example/desktop web/desktop_web_gmail_login/features/gmail_login.feature +0 -10
  80. data/example/desktop web/desktop_web_gmail_login/features/gmail_multi_login.feature +0 -22
  81. data/example/desktop web/desktop_web_gmail_login/features/image_difference/test.png +0 -0
  82. data/example/desktop web/desktop_web_gmail_login/features/my_first.feature +0 -1
  83. 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
  84. data/example/desktop web/desktop_web_gmail_login/features/screenshots/test.png +0 -0
  85. data/example/desktop web/desktop_web_gmail_login/features/step_definitions/custom_steps.rb +0 -5
  86. data/example/desktop web/desktop_web_gmail_login/features/support/env.rb +0 -51
  87. data/example/desktop web/desktop_web_gmail_login/features/support/hooks.rb +0 -38
  88. data/example/desktop web/desktop_web_gmail_login/result.html +0 -478
@@ -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
- if test_case
17
- if page_title != "#{title}"
18
- raise TestCaseFailed, "Page Title Not Matched, Actual Page Title : #{page_title}, Expected Page Title : #{title}"
19
- end
20
- else
21
- if page_title == "#{title}"
22
- raise TestCaseFailed, "Page Title Matched, Actual Page Title: #{page_title}"
23
- end
24
- end
25
- end
26
-
27
- # Method to verify partial title
28
- # param 1 : String : partial title string
29
- # param 2 : Boolean : test case [true or flase]
30
- def check_partial_title(partial_text_title, test_case)
31
- page_title = get_page_title
32
- if test_case
33
- if not page_title.include? "#{partial_text_title}"
34
- raise TestCaseFailed, 'Partial Page Title Not Present'
35
- end
36
- else
37
- if page_title.include? "#{partial_text_title}"
38
- raise TestCaseFailed, 'Page Title Matched'
39
- end
40
- end
41
- end
42
-
43
- # Method to get element text
44
- # param 1 : String : Locator type (id, name, class, xpath, css)
45
- # param 2 : String : Locator value
46
- def get_element_text(access_type, access_name)
47
- WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.text
48
- end
49
-
50
- # Method to check element text
51
- # param 1 : String : Locator type (id, name, class, xpath, css)
52
- # param 2 : String : Expected element text
53
- # param 3 : String : Locator value
54
- # param 4 : Boolean : test case [true or flase]
55
- def check_element_text(access_type, expected_value, access_name, test_case)
56
- element_text = get_element_text(access_type, access_name)
57
-
58
- if test_case
59
- if element_text != expected_value
60
- raise TestCaseFailed, "Text Not Matched, Actual Text : #{element_text}, Expected Text : #{expected_value}"
61
- end
62
- else
63
- if element_text == expected_value
64
- raise TestCaseFailed, "Text Matched, Actual Text : #{element_text}"
65
- end
66
- end
67
- end
68
-
69
- # Method to check partial element text
70
- # param 1 : String : Locator type (id, name, class, xpath, css)
71
- # param 2 : String : Expected element partial text
72
- # param 3 : String : Locator value
73
- # param 4 : Boolean : test case [true or flase]
74
- def check_element_partial_text(access_type, expected_value, access_name, test_case)
75
- element_text = get_element_text(access_type, access_name)
76
-
77
- if test_case
78
- if not element_text.include? "#{expected_value}"
79
- raise TestCaseFailed, "Element text : #{element_text}, does not contains partial text as : #{expected_value}"
80
- end
81
- else
82
- if element_text.include? "#{expected_value}"
83
- raise TestCaseFailed, "Element text : #{element_text}, contains partial text as : #{expected_value}"
84
- end
85
- end
86
- end
87
-
88
- # Method to return element status - enabled?
89
- # param 1 : String : Locator type (id, name, class, xpath, css)
90
- # param 2 : String : Locator value
91
- def is_element_enabled(access_type, access_name)
92
- WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.enabled?
93
- end
94
-
95
- # Element enabled checking
96
- # param 1 : String : Locator type (id, name, class, xpath, css)
97
- # param 2 : String : Expected element text
98
- # param 4 : Boolean : test case [true or flase]
99
- def check_element_enable(access_type, access_name, test_case)
100
- result = is_element_enabled(access_type, access_name)
101
-
102
- if test_case
103
- raise TestCaseFailed, 'Element Not Enabled' unless result
104
- else
105
- raise TestCaseFailed, 'Element Enabled' unless !result
106
- end
107
- end
108
-
109
- # method to get attribute value
110
- # param 1 : String : Locator type (id, name, class, xpath, css)
111
- # param 2 : String : Expected element text
112
- # param 3 : String : atrribute name
113
- def get_element_attribute(access_type, access_name, attribute_name)
114
- WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.attribute("#{attribute_name}")
115
- end
116
-
117
- # method to check attribute value
118
- # param 1 : String : Locator type (id, name, class, xpath, css)
119
- # param 2 : String : atrribute name
120
- # param 3 : String : atrribute value
121
- # param 4 : String : Locator value
122
- # param 5 : Boolean : test case [true or flase]
123
- def check_element_attribute(access_type, attribute_name, attribute_value, access_name, test_case)
124
-
125
- attr_val = get_element_attribute(access_type, access_name, attribute_name)
126
-
127
- if test_case
128
- if attr_val != attribute_value
129
- raise TestCaseFailed, "Attribute Value Not Matched, Actual Value : #{attr_val}, Expected Value : #{attribute_value}"
130
- end
131
- else
132
- if attr_val == attribute_value
133
- raise TestCaseFailed, "Attribute Value Matched, Actual Value : #{attr_val}"
134
- end
135
- end
136
- end
137
-
138
- # method to get element status - displayed?
139
- # param 1 : String : Locator type (id, name, class, xpath, css)
140
- # param 2 : String : Locator value
141
- def is_element_displayed(access_type, access_name)
142
- WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.displayed?
143
- end
144
-
145
- # method to check element presence
146
- # param 1 : String : Locator type (id, name, class, xpath, css)
147
- # param 2 : String : Locator value
148
- # param 3 : Boolean : test case [true or flase]
149
- def check_element_presence(access_type, access_name, test_case)
150
- if test_case
151
- if !is_element_displayed(access_type, access_name)
152
- raise TestCaseFailed, 'Element Not Present'
153
- end
154
- else
155
- begin
156
- if is_element_displayed(access_type, access_name)
157
- raise 'Present' # since it is negative test and we found element
158
- end
159
- rescue Exception => e
160
- if e.message == 'Present' # only raise if it present
161
- raise TestCaseFailed, 'Element Present'
162
- end
163
- end
164
- end
165
- end
166
-
167
- # method to assert checkbox check/uncheck
168
- # param 1 : String : Locator type (id, name, class, xpath, css)
169
- # param 2 : String : Locator value
170
- # param 3 : Boolean : test case [true or flase]
171
- def is_checkbox_checked(access_type, access_name, should_be_checked = true)
172
- checkbox = WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }
173
-
174
- if !checkbox.selected? && should_be_checked
175
- raise TestCaseFailed, 'Checkbox is not checked'
176
- elsif checkbox.selected? && !should_be_checked
177
- raise TestCaseFailed, 'Checkbox is checked'
178
- end
179
- end
180
-
181
- # method to assert radio button selected/unselected
182
- # param 1 : String : Locator type (id, name, class, xpath, css)
183
- # param 2 : String : Locator value
184
- # param 3 : Boolean : test case [true or flase]
185
- def is_radio_button_selected(access_type, access_name, should_be_selected = true)
186
- radio_button = WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }
187
-
188
- if !radio_button.selected? && should_be_selected
189
- raise TestCaseFailed, 'Radio Button not selected'
190
- elsif radio_button.selected? && !should_be_selected
191
- raise TestCaseFailed, 'Radio Button is selected'
192
- end
193
- end
194
-
195
- # method to assert option from radio button group is selected/unselected
196
- def is_option_from_radio_button_group_selected(access_type, by, option, access_name, should_be_selected = true)
197
- radio_button_group = WAIT.until{ $driver.find_elements(:"#{access_type}" => "#{access_name}") }
198
-
199
- getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text }
200
-
201
- ele = radio_button_group.find { |rb| getter.call(rb, by) == option }
202
-
203
- if !ele.selected? && should_be_selected
204
- raise TestCaseFailed, 'Radio button is not selected'
205
- elsif ele.selected? && !should_be_selected
206
- raise TestCaseFailed, 'Radio button is selected'
207
- end
208
- end
209
-
210
- # method to get javascript pop-up alert text
211
- def get_alert_text
212
- $driver.switch_to.alert.text
213
- end
214
-
215
- # method to check javascript pop-up alert text
216
- def check_alert_text(text)
217
- if get_alert_text != text
218
- raise TestCaseFailed, "Text on alert pop up not matched, Actual Text : #{get_alert_text}, Expected Text : #{text}"
219
- end
220
- end
221
-
222
- def is_option_from_dropdown_selected(access_type, by, option, access_name, should_be_selected=true)
223
- dropdown = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
224
- select_list = Selenium::WebDriver::Support::Select.new(dropdown)
225
-
226
- if by == 'text'
227
- actual_value = select_list.first_selected_option.text
228
- else
229
- actual_value = select_list.first_selected_option.attribute('value')
230
- end
231
-
232
- if !actual_value == option && should_be_selected
233
- raise TestCaseFailed, 'Option Not Selected From Dropwdown'
234
- elsif actual_value == option && !should_be_selected
235
- raise TestCaseFailed, 'Option Selected From Dropwdown'
236
- end
237
- end
238
-
239
- # Method to find difference between images
240
- def does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
241
- if !compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
242
- raise TestCaseFailed, 'Actual image is different from expected image'
243
- end
244
- end
245
-
246
- # Method to compare two images
247
- # param 1 : String : Locator type (id, name, class, xpath, css, url)
248
- # param 2 : String : Locator value
249
- # param 3 : String : Locator type (id, name, class, xpath, css, url, image_name)
250
- # param 4 : String : Locator value
251
- def compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
252
- if actual_img_access_type == 'url'
253
- actual_img_url = actual_img_access_name
254
- else
255
- actual_img_url = get_element_attribute(actual_img_access_type, actual_img_access_name, 'src')
256
- end
257
-
258
- if excp_img_access_type == 'url'
259
- expected_img_url = excp_img_access_name
260
- elsif excp_img_access_type == 'image_name'
261
- expected_img_url = './features/expected_images/' + excp_img_access_name
262
- else
263
- expected_img_url = get_element_attribute(excp_img_access_type, excp_img_access_name, 'src')
264
- end
265
-
266
- # replace 'https' with 'http' from actual image url
267
- if actual_img_url.include? 'https'
268
- actual_img_url['https'] = 'http'
269
- end
270
-
271
- # replace 'https' with 'http' from expected image url
272
- if expected_img_url.include? 'https'
273
- expected_img_url['https'] = 'http'
274
- end
275
-
276
- if expected_img_url.include? '.png'
277
- image_type = 'png'
278
- else
279
- image_type = 'jpg'
280
- end
281
-
282
- # Storing actual image locally
283
- open('./features/actual_images/actual_image.' + image_type, 'wb') do |file|
284
- file << open(actual_img_url).read
285
- end
286
-
287
- actual_img_url = './features/actual_images/actual_image.' + image_type
288
-
289
- # Storing Expected image locally
290
- if excp_img_access_type != 'image_name'
291
- open('./features/expected_images/expected_image.' + image_type, 'wb') do |file|
292
- file << open(expected_img_url).read
293
- end
294
- expected_img_url = './features/expected_images/expected_image.' + image_type
295
- end
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