selenium-cucumber 0.1.1 → 1.1.1

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 (65) hide show
  1. checksums.yaml +4 -4
  2. data/bin/generate.rb +20 -20
  3. data/bin/helper.rb +50 -50
  4. data/bin/selenium-cucumber +30 -29
  5. data/doc/canned_steps.md +8 -0
  6. data/doc/installation.md +16 -16
  7. data/doc/selenium-cucumber-help.md +18 -18
  8. data/example/Gemfile +5 -0
  9. data/example/Gemfile.lock +36 -0
  10. data/{Example/image_difference → example/features/actual_images}/test.png +0 -0
  11. data/{Example → example}/features/assertion_steps_Ex.feature +22 -10
  12. data/{Example → example}/features/click_steps_Ex.feature +0 -0
  13. data/{Example → example}/features/configuration_step_Ex.feature +1 -2
  14. data/example/features/expected_images/logo-PNG.png +0 -0
  15. data/example/features/expected_images/original_image.jpg +0 -0
  16. data/{Example/screenshots → example/features/image_difference}/test.png +0 -0
  17. data/{Example → example}/features/input_steps_Ex.feature +0 -0
  18. data/{Example → example}/features/javascript_steps_Ex.feature +0 -0
  19. data/{Example → example}/features/navigation_steps_Ex.feature +3 -3
  20. data/{Example → example}/features/progress_step_Ex.feature +0 -0
  21. data/{Example → example}/features/screenshot_step_Ex.feature +5 -1
  22. data/example/features/screenshots/test.png +0 -0
  23. data/{Example → example}/features/step_definitions/custom_steps.rb +0 -0
  24. data/{Example → example}/features/support/env.rb +0 -1
  25. data/{Example → example}/features/support/hooks.rb +0 -0
  26. data/example/run_features.rb +42 -0
  27. data/example/test_page.html +218 -0
  28. data/features-skeleton/actual_images/test.png +0 -0
  29. data/features-skeleton/my_first.feature +5 -5
  30. data/features-skeleton/step_definitions/custom_steps.rb +4 -4
  31. data/features-skeleton/support/env.rb +38 -38
  32. data/features-skeleton/support/hooks.rb +37 -33
  33. data/lib/selenium-cucumber.rb +2 -2
  34. data/lib/selenium-cucumber/assertion_steps.rb +25 -27
  35. data/lib/selenium-cucumber/click_elements_steps.rb +9 -12
  36. data/lib/selenium-cucumber/configuration_steps.rb +3 -4
  37. data/lib/selenium-cucumber/input_steps.rb +26 -26
  38. data/lib/selenium-cucumber/javascript_handling_steps.rb +3 -3
  39. data/lib/selenium-cucumber/methods/assertion_methods.rb +197 -160
  40. data/lib/selenium-cucumber/methods/click_elements_methods.rb +8 -8
  41. data/lib/selenium-cucumber/methods/configuration_methods.rb +10 -5
  42. data/lib/selenium-cucumber/methods/input_methods.rb +32 -45
  43. data/lib/selenium-cucumber/methods/javascript_handling_methods.rb +7 -7
  44. data/lib/selenium-cucumber/methods/misc_methods.rb +6 -6
  45. data/lib/selenium-cucumber/methods/navigate_methods.rb +37 -41
  46. data/lib/selenium-cucumber/methods/progress_methods.rb +8 -8
  47. data/lib/selenium-cucumber/methods/required_files.rb +1 -1
  48. data/lib/selenium-cucumber/methods/screenshot_methods.rb +3 -3
  49. data/lib/selenium-cucumber/navigation_steps.rb +20 -22
  50. data/lib/selenium-cucumber/progress_steps.rb +5 -8
  51. data/lib/selenium-cucumber/screenshot_steps.rb +2 -2
  52. data/lib/selenium-cucumber/version.rb +1 -1
  53. metadata +23 -27
  54. data/Example/expected_images/flower.png +0 -0
  55. data/Example/expected_images/flower1.png +0 -0
  56. data/Example/features/new.feature +0 -7
  57. data/Example/image_difference/difference_20140814210820942.png +0 -0
  58. data/Example/image_difference/difference_20140815095331224.png +0 -0
  59. data/Example/image_difference/difference_20140815100021133.png +0 -0
  60. data/Example/image_difference/difference_20140815100348774.png +0 -0
  61. data/Example/run_features.rb +0 -42
  62. data/Example/screenshots/screenshot20140815095553337.png +0 -0
  63. data/Example/screenshots/screenshot20140815100120197.png +0 -0
  64. data/Example/screenshots/screenshot20140815100446914.png +0 -0
  65. data/Example/test_page.html +0 -206
@@ -1,2 +1,2 @@
1
-
2
- Dir[File.dirname(__FILE__) + '/selenium-cucumber/*.rb'].each {|file| require file }
1
+
2
+ Dir[File.dirname(__FILE__) + '/selenium-cucumber/*.rb'].each { |file| require file }
@@ -1,81 +1,79 @@
1
1
  require_relative 'methods/assertion_methods'
2
2
 
3
-
4
- #Page title checking
3
+ # page title checking
5
4
  Then(/^I should see page title as "(.*?)"$/) do |title|
6
- check_title(title)
5
+ check_title(title)
7
6
  end
8
7
 
9
- #Step to check element text
10
- Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have text as "(.*?)"$/) do |type, access_name,present, value |
8
+ # step to check element text
9
+ Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have text as "(.*?)"$/) do |type, access_name, present, value |
11
10
  validate_locator type
12
11
  check_element_text(type, value, access_name, present.empty?)
13
12
  end
14
13
 
15
- #Step to check attribute value
14
+ # step to check attribute value
16
15
  Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+have attribute "(.*?)" with value "(.*?)"$/) do |type, access_name, present, attrb, value|
17
16
  validate_locator type
18
17
  check_element_attribute(type, attrb, value, access_name, present.empty?)
19
18
  end
20
19
 
21
- #Step to check element enabled or not
20
+ # step to check element enabled or not
22
21
  Then(/^element having (.+) "([^\"]*)" should\s*((?:not)?)\s+be (enabled|disabled)$/) do |type, access_name, present, state|
23
22
  validate_locator type
24
- flag = state == "enabled"
23
+ flag = state == 'enabled'
25
24
  flag = !flag unless present.empty?
26
25
  check_element_enable(type, access_name, flag)
27
26
  end
28
27
 
29
- #Step to check element present or not
28
+ # step to check element present or not
30
29
  Then(/^element having (.+) "(.*?)" should\s*((?:not)?)\s+be present$/) do |type, access_name, present|
31
30
  validate_locator type
32
31
  check_element_presence(type, access_name, present.empty?)
33
32
  end
34
33
 
35
- #Step to assert checkbox is checked or unchecked
34
+ # step to assert checkbox is checked or unchecked
36
35
  Then(/^checkbox having (.+) "(.*?)" should be (checked|unchecked)$/) do |type, access_name, state|
37
36
  validate_locator type
38
- flag = state == "checked"
37
+ flag = state == 'checked'
39
38
  is_checkbox_checked(type, access_name, flag)
40
39
  end
41
40
 
42
- #steps to assert radio button checked or unchecked
41
+ # steps to assert radio button checked or unchecked
43
42
  Then(/^radio button having (.+) "(.*?)" should be (selected|unselected)$/) do |type, access_name, state|
44
43
  validate_locator type
45
- flag = state == "selected"
44
+ flag = state == 'selected'
46
45
  is_radio_button_selected(type, access_name, flag)
47
46
  end
48
47
 
49
- #steps to assert option by text from radio button group selected/unselected
48
+ # steps to assert option by text from radio button group selected/unselected
50
49
  Then(/^option "(.*?)" by (.+) from radio button group having (.+) "(.*?)" should be (selected|unselected)$/) do |option, attrb, type, access_name, state|
51
50
  validate_locator type
52
- flag = state == "selected"
51
+ flag = state == 'selected'
53
52
  is_option_from_radio_button_group_selected(type, attrb, option, access_name, flag)
54
53
  end
55
54
 
56
- #steps to check link presence
57
- Then(/^link having text "(.*?)" should\s*((?:not)?)\s+be present$/) do |present,access_name|
58
- check_element_presence("link", access_name, present.empty?)
55
+ # steps to check link presence
56
+ Then(/^link having text "(.*?)" should\s*((?:not)?)\s+be present$/) do |present, access_name|
57
+ check_element_presence('link', access_name, present.empty?)
59
58
  end
60
59
 
61
- Then(/^link having partial text "(.*?)" should\s*((?:not)?)\s+be present$/) do |present,access_name|
62
- check_element_presence("partial_link_text", access_name, present.empty?)
60
+ Then(/^link having partial text "(.*?)" should\s*((?:not)?)\s+be present$/) do |present, access_name|
61
+ check_element_presence('partial_link_text', access_name, present.empty?)
63
62
  end
64
63
 
65
- #Step to assert javascript pop-up alert text
66
-
64
+ # step to assert javascript pop-up alert text
67
65
  Then(/^I should see alert text as "(.*?)"$/) do |actual_value|
68
- check_alert_text(actual_value)
66
+ check_alert_text(actual_value)
69
67
  end
70
68
 
71
- #Step to assert dropdown list
69
+ # step to assert dropdown list
72
70
  Then(/^option "(.*?)" by (.+) from dropdown having (.+) "(.*?)" should be (selected|unselected)$/) do |option, by, type, access_name, state|
73
71
  validate_locator type
74
- flag = state == "selected"
75
- is_option_from_dropdown_selected(type,by,option,access_name,state)
72
+ flag = state == 'selected'
73
+ is_option_from_dropdown_selected(type, by, option, access_name, state)
76
74
  end
77
75
 
78
- #Step to assert difference in images
76
+ # step to assert difference in images
79
77
  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|
80
78
  does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
81
79
  end
@@ -1,30 +1,27 @@
1
1
  require_relative 'methods/click_elements_methods'
2
2
 
3
3
  # click on web element
4
-
5
4
  When(/^I click on element having (.+) "(.*?)"$/) do |type, access_name|
6
5
  validate_locator type
7
- click(type,access_name)
6
+ click(type, access_name)
8
7
  end
9
8
 
10
9
  Then(/^I forcefully click on element having (.+) "(.*?)"$/) do |type, access_name|
11
- validate_locator type
12
- click_forcefully(type, access_name)
10
+ validate_locator type
11
+ click_forcefully(type, access_name)
13
12
  end
14
13
 
15
14
  # double click on web element
16
-
17
15
  Then(/^I double click on element having (.+) "(.*?)"$/) do |type, access_value|
18
- validate_locator type
19
- double_click(type, access_value)
16
+ validate_locator type
17
+ double_click(type, access_value)
20
18
  end
21
19
 
22
- #steps to click on link
23
-
20
+ # steps to click on link
24
21
  Then(/^I click on link having text "(.*?)"$/) do |access_name|
25
- click("link",access_name)
22
+ click('link', access_name)
26
23
  end
27
24
 
28
25
  Then(/^I click on link having partial text "(.*?)"$/) do |access_name|
29
- click("partial_link_text",access_name)
30
- end
26
+ click('partial_link_text', access_name)
27
+ end
@@ -1,7 +1,6 @@
1
1
  require_relative 'methods/configuration_methods'
2
2
 
3
- # Step to print configuration
4
-
3
+ # step to print configuration
5
4
  Then(/^I print configuration$/) do
6
- print_congifugartion
7
- end
5
+ print_congifugartion
6
+ end
@@ -1,69 +1,69 @@
1
1
  require_relative 'methods/input_methods'
2
2
 
3
- #enter text into input field steps
3
+ # enter text into input field steps
4
4
  Then(/^I enter "([^\"]*)" into input field having (.+) "([^\"]*)"$/) do |text, type, access_name|
5
- validate_locator type
6
- enter_text(type,text,access_name)
5
+ validate_locator type
6
+ enter_text(type, text, access_name)
7
7
  end
8
8
 
9
- #clear input field steps
9
+ # clear input field steps
10
10
  Then(/^I clear input field having (.+) "([^\"]*)"$/) do |type, access_name|
11
11
  validate_locator type
12
- clear_text(type, access_name)
12
+ clear_text(type, access_name)
13
13
  end
14
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
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
18
  validate_option_by option_by
19
- select_option_from_dropdown(type, option_by,option,access_name)
19
+ select_option_from_dropdown(type, option_by, option, access_name)
20
20
  end
21
21
 
22
- #select option by index from dropdown/multiselect
22
+ # select option by index from dropdown/multiselect
23
23
  Then(/^I select (\d+) option by index from\s*((?:multiselect)?)\sdropdown having (.+) "(.*?)"$/) do |option, present, type, access_name|
24
24
  validate_locator type
25
- select_option_from_dropdown(type, "index", (option.to_i)-1, access_name)
25
+ select_option_from_dropdown(type, 'index', (option.to_i) -1, access_name)
26
26
  end
27
27
 
28
- #step to select option from mutliselect dropdown list
28
+ # step to select option from mutliselect dropdown list
29
29
  Then(/^I select all options from multiselect dropdown having (.+) "(.*?)"$/) do |type, access_name|
30
30
  validate_locator type
31
31
  select_all_option_from_multiselect_dropdown(type, access_name)
32
32
  end
33
33
 
34
- #step to unselect option from mutliselect dropdown list
35
- Then(/^I unselect all options from multiselect dropdown having (.+) "(.*?)"$/) do |type,access_name|
34
+ # step to unselect option from mutliselect dropdown list
35
+ Then(/^I unselect all options from multiselect dropdown having (.+) "(.*?)"$/) do |type, access_name|
36
36
  validate_locator type
37
37
  unselect_all_option_from_multiselect_dropdown(type, access_name)
38
38
  end
39
39
 
40
- #check checkbox steps
40
+ # check checkbox steps
41
41
  Then(/^I check the checkbox having (.+) "(.*?)"$/) do |type, access_name|
42
42
  validate_locator type
43
43
  check_checkbox(type, access_name)
44
44
  end
45
45
 
46
- #uncheck checkbox steps
46
+ # uncheck checkbox steps
47
47
  Then(/^I uncheck the checkbox having (.+) "(.*?)"$/) do |type, access_name|
48
48
  validate_locator type
49
- uncheck_checkbox(type,access_name)
49
+ uncheck_checkbox(type, access_name)
50
50
  end
51
51
 
52
- #Steps to toggle checkbox
52
+ # steps to toggle checkbox
53
53
  Then(/^I toggle checkbox having (.+) "(.*?)"$/) do |type, access_name|
54
54
  validate_locator type
55
- toggle_checkbox(type,access_name)
55
+ toggle_checkbox(type, access_name)
56
56
  end
57
57
 
58
- #step to select radio button
59
- Then(/^I select radio button having (.+) "(.*?)"$/) do |type,access_name|
58
+ # step to select radio button
59
+ Then(/^I select radio button having (.+) "(.*?)"$/) do |type, access_name|
60
60
  validate_locator type
61
- select_radio_button(type,access_name)
61
+ select_radio_button(type, access_name)
62
62
  end
63
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|
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
66
  validate_locator type
67
67
  validate_option_by option_by
68
- select_option_from_radio_button_group(type,option_by,option,access_name)
69
- end
68
+ select_option_from_radio_button_group(type, option_by, option, access_name)
69
+ end
@@ -1,9 +1,9 @@
1
1
  require_relative 'methods/javascript_handling_methods'
2
2
 
3
3
  Then(/^I accept alert$/) do
4
- handle_alert("accept")
4
+ handle_alert('accept')
5
5
  end
6
6
 
7
7
  Then(/^I dismiss alert$/) do
8
- handle_alert("dismiss")
9
- end
8
+ handle_alert('dismiss')
9
+ end
@@ -1,222 +1,259 @@
1
+ require 'net/https'
1
2
  require_relative 'required_files'
2
3
 
3
-
4
- #Page title checking
4
+ # Page title checking
5
5
  def get_page_title
6
- return $driver.title
6
+ $driver.title
7
7
  end
8
8
 
9
9
  def check_title(title)
10
- if(get_page_title!=title)
11
- raise TestCaseFailed ,"Page Title Not Matched"
12
- end
10
+ raise TestCaseFailed, 'Page Title Not Matched' unless get_page_title == title
13
11
  end
14
12
 
15
- #method to get element text
16
- def get_element_text(access_type,access_name)
17
- return WAIT.until {$driver.find_element(:"#{access_type}" => "#{access_name}")}.text
13
+ # Method to get element text
14
+ def get_element_text(access_type, access_name)
15
+ WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }.text
18
16
  end
19
17
 
20
- #Method to check element text
18
+ # Method to check element text
21
19
  def check_element_text(access_type, actual_value, access_name, test_case)
22
- element_text = get_element_text(access_type,access_name)
23
-
24
- if test_case
25
- if(element_text!=actual_value)
26
- raise TestCaseFailed ,"Text Not Matched"
27
- end
28
- else
29
- if(element_text==actual_value)
30
- raise TestCaseFailed ,"Text Matched"
31
- end
32
- end
20
+ element_text = get_element_text(access_type, access_name)
21
+
22
+ if test_case
23
+ if element_text != actual_value
24
+ raise TestCaseFailed, 'Text Not Matched'
25
+ end
26
+ else
27
+ if element_text == actual_value
28
+ raise TestCaseFailed, 'Text Matched'
29
+ end
30
+ end
33
31
  end
34
32
 
35
- #method to return element status - enabled?
36
- def is_element_enabled(access_type,access_name)
37
- return WAIT.until{$driver.find_element(:"#{access_type}" => "#{access_name}")}.enabled?
33
+ # Method to return element status - enabled?
34
+ def is_element_enabled(access_type, access_name)
35
+ WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.enabled?
38
36
  end
39
37
 
40
- #Element enabled checking
38
+ # Element enabled checking
41
39
  def check_element_enable(access_type, access_name, test_case)
40
+ result = is_element_enabled(access_type, access_name)
42
41
 
43
- result=is_element_enabled(access_type,access_name)
44
-
45
- if test_case
46
- if(!result)
47
- raise TestCaseFailed ,"Element Not Enabled"
48
- end
49
- else
50
- if(result)
51
- raise TestCaseFailed ,"Element Enabled"
52
- end
53
- end
42
+ if test_case
43
+ raise TestCaseFailed, 'Element Not Enabled' unless result
44
+ else
45
+ raise TestCaseFailed, 'Element Enabled' unless !result
46
+ end
54
47
  end
55
48
 
56
- #method to get attribute value
57
- def get_element_attribute(access_type,access_name,attribute_name)
58
- return WAIT.until{$driver.find_element(:"#{access_type}" => "#{access_name}")}.attribute("#{attribute_name}")
49
+ # method to get attribute value
50
+ def get_element_attribute(access_type, access_name, attribute_name)
51
+ WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.attribute("#{attribute_name}")
59
52
  end
60
53
 
61
- #method to check attribute value
54
+ # method to check attribute value
62
55
  def check_element_attribute(access_type, attribute_name, attribute_value, access_name, test_case)
63
56
 
64
- attr_val=get_element_attribute(access_type, access_name, attribute_name)
57
+ attr_val = get_element_attribute(access_type, access_name, attribute_name)
65
58
 
66
- if test_case
67
- if(attr_val!=attribute_value)
68
- raise TestCaseFailed ,"Attribute Value Not Matched"
69
- end
70
- else
71
- if(attr_val==attribute_value)
72
- raise TestCaseFailed ,"Attribute Value Matched"
73
- end
74
- end
59
+ if test_case
60
+ if attr_val != attribute_value
61
+ raise TestCaseFailed, 'Attribute Value Not Matched'
62
+ end
63
+ else
64
+ if attr_val == attribute_value
65
+ raise TestCaseFailed, 'Attribute Value Matched'
66
+ end
67
+ end
75
68
  end
76
69
 
77
- #method to get element status - displayed?
78
- def is_element_displayed(access_type,access_name)
79
- WAIT.until{$driver.find_element(:"#{access_type}" => "#{access_name}")}.displayed?
70
+ # method to get element status - displayed?
71
+ def is_element_displayed(access_type, access_name)
72
+ WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }.displayed?
80
73
  end
81
74
 
82
75
  # method to check element presence
83
76
  def check_element_presence(access_type, access_name, test_case)
84
- if test_case
85
- if !is_element_displayed(access_type,access_name)
86
- raise TestCaseFailed ,"Element Not Present"
87
- end
88
- else
89
- begin
90
- if is_element_displayed(access_type,access_name)
91
- raise "Present"
92
- end
93
- rescue Exception => e
94
- if e.message=="present"
95
- raise TestCaseFailed ,"Element Present"
96
- end
97
- end
98
- end
99
- end
100
-
101
- #method to assert checkbox check/uncheck
102
- def is_checkbox_checked(access_type, access_name, should_be_checked=true)
103
- checkbox = WAIT.until{$driver.find_element(:"#{access_type}" => "#{access_name}")}
104
-
105
- if !checkbox.selected? && should_be_checked
106
- raise TestCaseFailed ,"Checkbox is not checked"
107
- elsif checkbox.selected? && !should_be_checked
108
- raise TestCaseFailed ,"Checkbox is checked"
109
- end
77
+ if test_case
78
+ if !is_element_displayed(access_type, access_name)
79
+ raise TestCaseFailed, 'Element Not Present'
80
+ end
81
+ else
82
+ begin
83
+ if is_element_displayed(access_type, access_name)
84
+ raise 'Present'
85
+ end
86
+ rescue Exception => e
87
+ if e.message == 'present'
88
+ raise TestCaseFailed, 'Element Present'
89
+ end
90
+ end
91
+ end
110
92
  end
111
93
 
112
- #method to assert radio button selected/unselected
113
- def is_radio_button_selected(access_type, access_name, should_be_selected=true)
114
- radio_button = WAIT.until{$driver.find_element(:"#{access_type}" => "#{access_name}")}
94
+ # method to assert checkbox check/uncheck
95
+ def is_checkbox_checked(access_type, access_name, should_be_checked = true)
96
+ checkbox = WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }
115
97
 
116
- if !radio_button.selected? && should_be_selected
117
- raise TestCaseFailed ,"Radio Button not selected"
118
- elsif radio_button.selected? && !should_be_selected
119
- raise TestCaseFailed ,"Radio Button is selected"
120
- end
98
+ if !checkbox.selected? && should_be_checked
99
+ raise TestCaseFailed, 'Checkbox is not checked'
100
+ elsif checkbox.selected? && !should_be_checked
101
+ raise TestCaseFailed, 'Checkbox is checked'
102
+ end
121
103
  end
122
104
 
105
+ # method to assert radio button selected/unselected
106
+ def is_radio_button_selected(access_type, access_name, should_be_selected = true)
107
+ radio_button = WAIT.until{ $driver.find_element(:"#{access_type}" => "#{access_name}") }
108
+
109
+ if !radio_button.selected? && should_be_selected
110
+ raise TestCaseFailed, 'Radio Button not selected'
111
+ elsif radio_button.selected? && !should_be_selected
112
+ raise TestCaseFailed, 'Radio Button is selected'
113
+ end
114
+ end
123
115
 
124
- #method to assert option from radio button group is selected/unselected
125
- def is_option_from_radio_button_group_selected(access_type, by, option, access_name, should_be_selected=true)
126
- radio_button_group = WAIT.until{$driver.find_elements(:"#{access_type}" => "#{access_name}")}
116
+ # method to assert option from radio button group is selected/unselected
117
+ def is_option_from_radio_button_group_selected(access_type, by, option, access_name, should_be_selected = true)
118
+ radio_button_group = WAIT.until{ $driver.find_elements(:"#{access_type}" => "#{access_name}") }
127
119
 
128
120
  getter = ->(rb, by) { by == 'value' ? rb.attribute('value') : rb.text }
129
121
 
130
122
  ele = radio_button_group.find { |rb| getter.call(rb, by) == option }
131
123
 
132
124
  if !ele.selected? && should_be_selected
133
- raise TestCaseFailed ,'Radio button is not selected'
125
+ raise TestCaseFailed, 'Radio button is not selected'
134
126
  elsif ele.selected? && !should_be_selected
135
- raise TestCaseFailed ,'Radio button is selected'
127
+ raise TestCaseFailed, 'Radio button is selected'
136
128
  end
137
129
  end
138
130
 
139
- #method to get javascript pop-up alert text
131
+ # method to get javascript pop-up alert text
140
132
  def get_alert_text
141
- $driver.switch_to.alert.text
133
+ $driver.switch_to.alert.text
142
134
  end
143
135
 
144
- #method to check javascript pop-up alert text
145
- def check_alert_text text
146
- if get_alert_text!=text
147
- raise TestCaseFailed , "Text on alert pop up not matched"
148
- end
136
+ # method to check javascript pop-up alert text
137
+ def check_alert_text(text)
138
+ if get_alert_text != text
139
+ raise TestCaseFailed, 'Text on alert pop up not matched'
140
+ end
149
141
  end
150
142
 
151
143
  def is_option_from_dropdown_selected(access_type, by, option, access_name, should_be_selected=true)
152
- dropdown = WAIT.until {$driver.find_element(:"#{access_type}" => "#{access_name}")}
153
- select_list = Selenium::WebDriver::Support::Select.new(dropdown)
144
+ dropdown = WAIT.until { $driver.find_element(:"#{access_type}" => "#{access_name}") }
145
+ select_list = Selenium::WebDriver::Support::Select.new(dropdown)
154
146
 
155
- if by=="text"
156
- actual_value = select_list.first_selected_option.text
157
- else
158
- actual_value = select_list.first_selected_option.attribute("value")
159
- end
147
+ if by == 'text'
148
+ actual_value = select_list.first_selected_option.text
149
+ else
150
+ actual_value = select_list.first_selected_option.attribute('value')
151
+ end
160
152
 
161
- if !actual_value==option && should_be_selected
162
- raise TestCaseFailed , "Option Not Selected From Dropwdown"
163
- elsif actual_value==option && !should_be_selected
164
- raise TestCaseFailed , "Option Selected From Dropwdown"
165
- end
153
+ if !actual_value == option && should_be_selected
154
+ raise TestCaseFailed, 'Option Not Selected From Dropwdown'
155
+ elsif actual_value == option && !should_be_selected
156
+ raise TestCaseFailed, 'Option Selected From Dropwdown'
157
+ end
166
158
  end
167
159
 
168
- #Method to find difference between images
160
+ # Method to find difference between images
169
161
  def does_images_similar?(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
170
- if !compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
171
- raise TestCaseFailed , "Actual image is different from expected image"
172
- end
162
+ if !compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
163
+ raise TestCaseFailed, 'Actual image is different from expected image'
164
+ end
173
165
  end
174
166
 
175
- #Method to compare two images
167
+ # Method to compare two images
176
168
  def compare_image(actual_img_access_type, actual_img_access_name, excp_img_access_type, excp_img_access_name)
169
+ if actual_img_access_type == 'url'
170
+ actual_img_url = actual_img_access_name
171
+ else
172
+ actual_img_url = get_element_attribute(actual_img_access_type, actual_img_access_name, 'src')
173
+ end
174
+
175
+ if excp_img_access_type == 'url'
176
+ expected_img_url = excp_img_access_name
177
+ elsif excp_img_access_type == 'image_name'
178
+ expected_img_url = './features/expected_images/' + excp_img_access_name
179
+ else
180
+ expected_img_url = get_element_attribute(excp_img_access_type, excp_img_access_name, 'src')
181
+ end
182
+
183
+ if actual_img_url.include? 'https'
184
+ actual_img_url['https'] = 'http'
185
+ end
177
186
 
178
- if actual_img_access_type == "url"
179
- actual_img_url = actual_img_access_name
180
- else
181
- actual_img_url = get_element_attribute(actual_img_access_type, actual_img_access_name, "src")
182
- end
183
-
184
- if excp_img_access_type == "url"
185
- expected_img_url = excp_img_access_name
186
- elsif excp_img_access_type == "image_name"
187
- expected_img_url = File.absolute_path("expected_images/"+excp_img_access_name)
188
- else
189
- expected_img_url = get_element_attribute(excp_img_access_type, excp_img_access_name, "src")
190
- end
191
-
192
- puts "\nActual image url : #{actual_img_url}"
193
-
194
- images = [
195
- ChunkyPNG::Image.from_file(open(actual_img_url)),
196
- ChunkyPNG::Image.from_file(open(expected_img_url))
197
- ]
198
-
199
- diff = []
200
-
201
- images.first.height.times do |y|
202
- images.first.row(y).each_with_index do |pixel, x|
203
- diff << [x,y] unless pixel == images.last[x,y]
204
- end
205
- end
206
-
207
- if diff.length != 0
208
- puts "\npixels (total): #{images.first.pixels.length}"
209
- puts "pixels changed: #{diff.length}"
210
- puts "pixels changed (%): #{(diff.length.to_f / images.first.pixels.length) * 100}%"
211
-
212
- x, y = diff.map{ |xy| xy[0] }, diff.map{ |xy| xy[1] }
213
- images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0,255,0))
214
- curTime = Time.now.strftime('%Y%m%d%H%M%S%L')
215
- images.last.save("image_difference/difference_#{curTime}.png")
216
-
217
- puts "\nDifference between images saved as : difference_#{curTime}.png\n"
218
- return false
219
- else
220
- return true
221
- end
187
+ if expected_img_url.include? 'https'
188
+ expected_img_url['https'] = 'http'
189
+ end
190
+
191
+ if expected_img_url.include? '.png'
192
+ image_type = 'png'
193
+ else
194
+ image_type = 'jpg'
195
+ end
196
+
197
+ # Storing actual image locally
198
+ open('./features/actual_images/actual_image.' + image_type, 'wb') do |file|
199
+ file << open(actual_img_url).read
200
+ end
201
+
202
+ actual_img_url = './features/actual_images/actual_image.' + image_type
203
+
204
+ # Storing Expected image locally
205
+ if excp_img_access_type != 'image_name'
206
+ open('./features/expected_images/expected_image.' + image_type, 'wb') do |file|
207
+ file << open(expected_img_url).read
208
+ end
209
+ expected_img_url = './features/expected_images/expected_image.' + image_type
210
+ end
211
+
212
+ # Verify image extension and call respective compare function
213
+ if image_type == 'png'
214
+ return compare_png_images(expected_img_url, actual_img_url)
215
+ end
216
+
217
+ compare_jpeg_images(expected_img_url, actual_img_url)
218
+ end
219
+
220
+ # Comparing jpg images
221
+ def compare_jpeg_images(expected_img_url, actual_img_url)
222
+ if open(expected_img_url).read == open(actual_img_url).read
223
+ return true
224
+ else
225
+ puts 'Difference in images'
226
+ return false
227
+ end
228
+ end
229
+
230
+ # Comparing png images
231
+ def compare_png_images(expected_img_url, actual_img_url)
232
+ images = [
233
+ ChunkyPNG::Image.from_file(expected_img_url),
234
+ ChunkyPNG::Image.from_file(actual_img_url)
235
+ ]
236
+
237
+ diff = []
238
+
239
+ images.first.height.times do |y|
240
+ images.first.row(y).each_with_index do |pixel, x|
241
+ diff << [x, y] unless pixel == images.last[x, y]
242
+ end
243
+ end
244
+
245
+ if diff.length != 0
246
+ puts "\npixels (total): #{images.first.pixels.length}"
247
+ puts "pixels changed: #{diff.length}"
248
+ puts "pixels changed (%): #{(diff.length.to_f / images.first.pixels.length) * 100}%"
249
+
250
+ x, y = diff.map { |xy| xy[0] }, diff.map { |xy| xy[1] }
251
+ images.last.rect(x.min, y.min, x.max, y.max, ChunkyPNG::Color.rgb(0, 255, 0))
252
+ cur_time = Time.now.strftime('%Y%m%d%H%M%S%L')
253
+ images.last.save("./features/image_difference/difference_#{cur_time}.png")
254
+
255
+ puts "\nDifference between images saved as : difference_#{cur_time}.png\n"
256
+ return false
257
+ end
258
+ true
222
259
  end