watir 5.0.0 → 6.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.document +5 -0
  3. data/.gitignore +21 -0
  4. data/.gitmodules +3 -0
  5. data/.travis.yml +35 -0
  6. data/CHANGES.md +1756 -0
  7. data/Gemfile +12 -0
  8. data/LICENSE +23 -0
  9. data/README.md +92 -0
  10. data/Rakefile +161 -32
  11. data/lib/watir.rb +127 -1
  12. data/lib/watir/after_hooks.rb +132 -0
  13. data/lib/watir/alert.rb +104 -0
  14. data/lib/watir/aliases.rb +6 -0
  15. data/lib/watir/atoms.rb +24 -0
  16. data/lib/watir/atoms/README +3 -0
  17. data/lib/watir/atoms/fireEvent.js +29 -0
  18. data/lib/watir/atoms/getAttribute.js +18 -0
  19. data/lib/watir/atoms/getInnerHtml.js +18 -0
  20. data/lib/watir/atoms/getOuterHtml.js +18 -0
  21. data/lib/watir/atoms/getParentElement.js +17 -0
  22. data/lib/watir/atoms/selectText.js +61 -0
  23. data/lib/watir/attribute_helper.rb +98 -0
  24. data/lib/watir/browser.rb +346 -0
  25. data/lib/watir/cell_container.rb +25 -0
  26. data/lib/watir/container.rb +51 -0
  27. data/lib/watir/cookies.rb +132 -0
  28. data/lib/watir/element_collection.rb +126 -0
  29. data/lib/watir/elements/area.rb +12 -0
  30. data/lib/watir/elements/button.rb +37 -0
  31. data/lib/watir/elements/cell.rb +17 -0
  32. data/lib/watir/elements/checkbox.rb +54 -0
  33. data/lib/watir/elements/dlist.rb +12 -0
  34. data/lib/watir/elements/element.rb +646 -0
  35. data/lib/watir/elements/file_field.rb +41 -0
  36. data/lib/watir/elements/font.rb +11 -0
  37. data/lib/watir/elements/form.rb +17 -0
  38. data/lib/watir/elements/hidden.rb +20 -0
  39. data/lib/watir/elements/html_elements.rb +2063 -0
  40. data/lib/watir/elements/iframe.rb +163 -0
  41. data/lib/watir/elements/image.rb +62 -0
  42. data/lib/watir/elements/input.rb +7 -0
  43. data/lib/watir/elements/link.rb +18 -0
  44. data/lib/watir/elements/option.rb +74 -0
  45. data/lib/watir/elements/radio.rb +42 -0
  46. data/lib/watir/elements/row.rb +17 -0
  47. data/lib/watir/elements/select.rb +238 -0
  48. data/lib/watir/elements/svg_elements.rb +667 -0
  49. data/lib/watir/elements/table.rb +42 -0
  50. data/lib/watir/elements/table_cell.rb +6 -0
  51. data/lib/watir/elements/table_row.rb +15 -0
  52. data/lib/watir/elements/table_section.rb +15 -0
  53. data/lib/watir/elements/text_area.rb +5 -0
  54. data/lib/watir/elements/text_field.rb +37 -0
  55. data/lib/watir/exception.rb +17 -0
  56. data/lib/watir/extensions/nokogiri.rb +14 -0
  57. data/lib/watir/extensions/select_text.rb +10 -0
  58. data/lib/watir/generator.rb +3 -0
  59. data/lib/watir/generator/base.rb +11 -0
  60. data/lib/watir/generator/base/generator.rb +115 -0
  61. data/lib/watir/generator/base/idl_sorter.rb +47 -0
  62. data/lib/watir/generator/base/spec_extractor.rb +138 -0
  63. data/lib/watir/generator/base/util.rb +21 -0
  64. data/lib/watir/generator/base/visitor.rb +157 -0
  65. data/lib/watir/generator/html.rb +15 -0
  66. data/lib/watir/generator/html/generator.rb +36 -0
  67. data/lib/watir/generator/html/spec_extractor.rb +50 -0
  68. data/lib/watir/generator/html/visitor.rb +21 -0
  69. data/lib/watir/generator/svg.rb +7 -0
  70. data/lib/watir/generator/svg/generator.rb +38 -0
  71. data/lib/watir/generator/svg/spec_extractor.rb +46 -0
  72. data/lib/watir/generator/svg/visitor.rb +21 -0
  73. data/lib/watir/has_window.rb +53 -0
  74. data/lib/watir/locators.rb +22 -0
  75. data/lib/watir/locators/button/locator.rb +38 -0
  76. data/lib/watir/locators/button/selector_builder.rb +27 -0
  77. data/lib/watir/locators/button/selector_builder/xpath.rb +29 -0
  78. data/lib/watir/locators/button/validator.rb +15 -0
  79. data/lib/watir/locators/cell/locator.rb +17 -0
  80. data/lib/watir/locators/cell/selector_builder.rb +24 -0
  81. data/lib/watir/locators/element/locator.rb +249 -0
  82. data/lib/watir/locators/element/selector_builder.rb +147 -0
  83. data/lib/watir/locators/element/selector_builder/css.rb +65 -0
  84. data/lib/watir/locators/element/selector_builder/xpath.rb +72 -0
  85. data/lib/watir/locators/element/validator.rb +23 -0
  86. data/lib/watir/locators/row/locator.rb +17 -0
  87. data/lib/watir/locators/row/selector_builder.rb +29 -0
  88. data/lib/watir/locators/text_area/locator.rb +13 -0
  89. data/lib/watir/locators/text_area/selector_builder.rb +22 -0
  90. data/lib/watir/locators/text_field/locator.rb +44 -0
  91. data/lib/watir/locators/text_field/selector_builder.rb +34 -0
  92. data/lib/watir/locators/text_field/selector_builder/xpath.rb +19 -0
  93. data/lib/watir/locators/text_field/validator.rb +20 -0
  94. data/lib/watir/row_container.rb +36 -0
  95. data/lib/watir/screenshot.rb +50 -0
  96. data/lib/watir/user_editable.rb +38 -0
  97. data/lib/watir/version.rb +3 -3
  98. data/lib/watir/wait.rb +250 -0
  99. data/lib/watir/wait/timer.rb +19 -0
  100. data/lib/watir/window.rb +244 -0
  101. data/lib/watir/xpath_support.rb +20 -0
  102. data/spec/always_locate_spec.rb +43 -0
  103. data/spec/browser_spec.rb +130 -0
  104. data/spec/click_spec.rb +19 -0
  105. data/spec/container_spec.rb +34 -0
  106. data/spec/element_locator_spec.rb +532 -0
  107. data/spec/element_spec.rb +136 -0
  108. data/spec/implementation.rb +216 -0
  109. data/spec/input_spec.rb +14 -0
  110. data/spec/locator_spec_helper.rb +57 -0
  111. data/spec/spec_helper.rb +35 -0
  112. data/spec/special_chars_spec.rb +13 -0
  113. data/support/doctest_helper.rb +78 -0
  114. data/support/travis.sh +44 -0
  115. data/support/version_differ.rb +59 -0
  116. data/watir.gemspec +37 -25
  117. metadata +288 -23
  118. data/lib/watir/loader.rb +0 -64
@@ -0,0 +1,136 @@
1
+ require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Watir::Element do
4
+
5
+ describe '#present?' do
6
+ before do
7
+ browser.goto(WatirSpec.url_for("wait.html"))
8
+ end
9
+
10
+ it 'returns true if the element exists and is visible' do
11
+ expect(browser.div(:id, 'foo')).to be_present
12
+ end
13
+
14
+ it 'returns false if the element exists but is not visible' do
15
+ expect(browser.div(:id, 'bar')).to_not be_present
16
+ end
17
+
18
+ it 'returns false if the element does not exist' do
19
+ expect(browser.div(:id, 'should-not-exist')).to_not be_present
20
+ end
21
+
22
+ it "returns false if the element is stale" do
23
+ wd_element = browser.div(id: "foo").wd
24
+
25
+ # simulate element going stale during lookup
26
+ allow(browser.driver).to receive(:find_element).with(:id, 'foo') { wd_element }
27
+ browser.refresh
28
+
29
+ expect(browser.div(:id, 'foo')).to_not be_present
30
+ end
31
+
32
+ end
33
+
34
+ describe "#enabled?" do
35
+ before do
36
+ browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
37
+ end
38
+
39
+ it "returns true if the element is enabled" do
40
+ expect(browser.element(name: 'new_user_submit')).to be_enabled
41
+ end
42
+
43
+ it "returns false if the element is disabled" do
44
+ expect(browser.element(name: 'new_user_submit_disabled')).to_not be_enabled
45
+ end
46
+
47
+ it "raises UnknownObjectException if the element doesn't exist" do
48
+ expect { browser.element(name: "no_such_name").enabled? }.to raise_error(Watir::Exception::UnknownObjectException)
49
+ end
50
+ end
51
+
52
+ describe "#reset!" do
53
+ it "successfully relocates collection elements after a reset!" do
54
+ browser.goto(WatirSpec.url_for("wait.html"))
55
+ element = browser.div(id: 'foo')
56
+ expect(element).to exist
57
+ browser.refresh
58
+ browser.div(id: 'foo').wait_until_present
59
+
60
+ expect(element.exist?).to be false unless Watir.always_locate?
61
+ element.send :reset!
62
+ expect(element).to exist
63
+ end
64
+ end
65
+
66
+ describe "#exists?" do
67
+ before do
68
+ browser.goto WatirSpec.url_for('removed_element.html')
69
+ end
70
+
71
+ it "returns false when an element from a collection becomes stale" do
72
+ watir_element = browser.divs(id: "text").first
73
+ expect(watir_element).to exist
74
+
75
+ browser.refresh
76
+
77
+ expect(watir_element).to_not exist
78
+ end
79
+
80
+ end
81
+
82
+ describe "#element_call" do
83
+
84
+ it 'handles exceptions when taking an action on an element that goes stale during execution' do
85
+ browser.goto WatirSpec.url_for('removed_element.html')
86
+
87
+ watir_element = browser.div(id: "text")
88
+
89
+ # simulate element going stale after assert_exists and before action taken
90
+ allow(watir_element).to receive(:text) do
91
+ watir_element.send :assert_exists
92
+ browser.refresh
93
+ watir_element.send(:element_call) { watir_element.instance_variable_get('@element').text }
94
+ end
95
+
96
+ if Watir.always_locate?
97
+ expect { watir_element.text }.to_not raise_error
98
+ else
99
+ expect { watir_element.text }.to raise_error Watir::Exception::UnknownObjectException
100
+ end
101
+ end
102
+
103
+ end
104
+
105
+ bug "Actions Endpoint Not Yet Implemented", :firefox do
106
+ describe "#hover" do
107
+ not_compliant_on :internet_explorer, :safari do
108
+ it "should hover over the element" do
109
+ browser.goto WatirSpec.url_for('hover.html')
110
+ link = browser.a
111
+
112
+ expect(link.style("font-size")).to eq "10px"
113
+ link.hover
114
+ expect(link.style("font-size")).to eq "20px"
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ # TODO - Can remove when decide issue #295
121
+ describe "warnings" do
122
+ it "does not return a warning if using text_field for an unspecified text input" do
123
+ browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
124
+ expect do
125
+ browser.text_field(id: "new_user_first_name").exists?
126
+ end.to_not output.to_stderr
127
+ end
128
+
129
+ it "returns a warning if using text_field for textarea" do
130
+ browser.goto(WatirSpec.url_for("forms_with_input_elements.html"))
131
+ expect do
132
+ browser.text_field(id: "create_user_comment").exists?
133
+ end.to output.to_stderr
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,216 @@
1
+ require File.expand_path("../spec_helper", __FILE__)
2
+
3
+ class ImplementationConfig
4
+ def initialize(imp)
5
+ @imp = imp
6
+ end
7
+
8
+ def browser
9
+ @browser ||= (ENV['WATIR_BROWSER'] || :chrome).to_sym
10
+ end
11
+
12
+ def remote_browser
13
+ @remote_browser ||= (ENV['REMOTE_BROWSER'] || :chrome).to_sym
14
+ end
15
+
16
+ def configure
17
+ set_webdriver
18
+ start_remote_server if remote? && !ENV["REMOTE_SERVER_URL"]
19
+ set_browser_args
20
+ set_guard_proc
21
+ add_html_routes
22
+
23
+ WatirSpec.always_use_server = ie? || safari? || phantomjs? || remote?
24
+ end
25
+
26
+ private
27
+
28
+ def start_remote_server
29
+ require 'selenium/server'
30
+
31
+ @server ||= Selenium::Server.new(remote_server_jar,
32
+ port: Selenium::WebDriver::PortProber.above(4444),
33
+ log: !!$DEBUG,
34
+ background: true,
35
+ timeout: 60)
36
+
37
+ @server.start
38
+ at_exit { @server.stop }
39
+ end
40
+
41
+ def remote_server_jar
42
+ if File.exist?(ENV['REMOTE_SERVER_BINARY'] || '')
43
+ ENV['REMOTE_SERVER_BINARY']
44
+ elsif !Dir.glob('selenium-server-standalone*.jar').empty?
45
+ Dir.glob('selenium-server-standalone*.jar').first
46
+ else
47
+ Selenium::Server.download :latest
48
+ end
49
+ rescue SocketError
50
+ # not connected to internet
51
+ raise Watir::Exception::Error, "unable to find or download selenium-server-standalone jar"
52
+ end
53
+
54
+ def set_webdriver
55
+ @imp.name = :webdriver
56
+ @imp.browser_class = Watir::Browser
57
+ end
58
+
59
+ def set_browser_args
60
+ args = case browser
61
+ when :firefox
62
+ firefox_args
63
+ when :ff_legacy
64
+ ff_legacy_args
65
+ when :chrome
66
+ chrome_args
67
+ when :remote
68
+ remote_args
69
+ else
70
+ {desired_capabilities: Selenium::WebDriver::Remote::Capabilities.send(browser)}
71
+ end
72
+
73
+ if ENV['SELECTOR_STATS']
74
+ listener = SelectorListener.new
75
+ args.merge!(listener: listener)
76
+ at_exit { listener.report }
77
+ end
78
+
79
+ @imp.browser_args = [browser, args]
80
+ end
81
+
82
+ def ie?
83
+ [:internet_explorer].include? browser
84
+ end
85
+
86
+ def safari?
87
+ browser == :safari
88
+ end
89
+
90
+ def phantomjs?
91
+ browser == :phantomjs
92
+ end
93
+
94
+ def remote?
95
+ browser == :remote
96
+ end
97
+
98
+ def set_guard_proc
99
+ matching_guards = [:webdriver]
100
+
101
+ if remote?
102
+ matching_browser = remote_browser
103
+ matching_guards << :remote
104
+ matching_guards << [:remote, matching_browser]
105
+ matching_guards << [:remote, :ff_legacy] if @ff_legacy
106
+ else
107
+ matching_browser = browser
108
+ end
109
+
110
+ matching_guards << :ff_legacy if @ff_legacy
111
+
112
+ browser_instance = WatirSpec.new_browser
113
+ browser_version = browser_instance.driver.capabilities.version
114
+
115
+ matching_browser_with_version = "#{browser}#{browser_version}".to_sym
116
+ matching_guards << matching_browser_with_version if browser_version
117
+
118
+ matching_guards << matching_browser
119
+ matching_guards << [matching_browser, Selenium::WebDriver::Platform.os]
120
+
121
+ if !Selenium::WebDriver::Platform.linux? || ENV['DESKTOP_SESSION']
122
+ # some specs (i.e. Window#maximize) needs a window manager on linux
123
+ matching_guards << :window_manager
124
+ end
125
+
126
+ @imp.guard_proc = lambda { |args|
127
+ args.any? { |arg| matching_guards.include?(arg) }
128
+ }
129
+ ensure
130
+ browser_instance.close if browser_instance
131
+ end
132
+
133
+ def firefox_args
134
+ path = ENV['FIREFOX_BINARY']
135
+ Selenium::WebDriver::Firefox::Binary.path = path if path
136
+ {desired_capabilities: Selenium::WebDriver::Remote::Capabilities.firefox}
137
+ end
138
+
139
+ def ff_legacy_args
140
+ @browser = :firefox
141
+ @ff_legacy = true
142
+ caps = Selenium::WebDriver::Remote::Capabilities.firefox(marionette: false)
143
+ path = ENV['FF_LEGACY_BINARY']
144
+ Selenium::WebDriver::Firefox::Binary.path = path if path
145
+ {desired_capabilities: caps}
146
+ end
147
+
148
+ def chrome_args
149
+ opts = {args: ["--disable-translate"],
150
+ desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome}
151
+
152
+ if url = ENV['WATIR_CHROME_SERVER']
153
+ opts[:url] = url
154
+ end
155
+
156
+ if driver = ENV['WATIR_CHROME_DRIVER']
157
+ Selenium::WebDriver::Chrome.driver_path = driver
158
+ end
159
+
160
+ if path = ENV['WATIR_CHROME_BINARY']
161
+ Selenium::WebDriver::Chrome.path = path
162
+ end
163
+
164
+ if ENV['TRAVIS']
165
+ opts[:args] << "--no-sandbox" # https://github.com/travis-ci/travis-ci/issues/938
166
+ end
167
+
168
+ opts
169
+ end
170
+
171
+ def remote_args
172
+ url = ENV["REMOTE_SERVER_URL"] || "http://127.0.0.1:#{@server.port}/wd/hub"
173
+ opts = {}
174
+ if remote_browser == :ff_legacy
175
+ path = ENV['FF_LEGACY_BINARY']
176
+ opts[:firefox_binary] = path if path
177
+ @remote_browser = :firefox
178
+ @ff_legacy = true
179
+ opts[:marionette] = false
180
+ elsif remote_browser == :firefox
181
+ path = ENV['FIREFOX_BINARY']
182
+ opts[:firefox_binary] = path if path
183
+ end
184
+
185
+ caps = Selenium::WebDriver::Remote::Capabilities.send(remote_browser, opts)
186
+ {url: url, desired_capabilities: caps}
187
+ end
188
+
189
+ def add_html_routes
190
+ glob = File.expand_path("../html/*.html", __FILE__)
191
+ Dir[glob].each do |path|
192
+ WatirSpec::Server.get("/#{File.basename path}") { File.read(path) }
193
+ end
194
+ end
195
+
196
+ class SelectorListener < Selenium::WebDriver::Support::AbstractEventListener
197
+ def initialize
198
+ @counts = Hash.new(0)
199
+ end
200
+
201
+ def before_find(how, what, driver)
202
+ @counts[how] += 1
203
+ end
204
+
205
+ def report
206
+ total = @counts.values.inject(0) { |mem, var| mem + var }
207
+ puts "\nSelenium selector stats: "
208
+ @counts.each do |how, count|
209
+ puts "\t#{how.to_s.ljust(20)}: #{count * 100 / total} (#{count})"
210
+ end
211
+ end
212
+
213
+ end
214
+ end
215
+
216
+ ImplementationConfig.new(WatirSpec.implementation).configure
@@ -0,0 +1,14 @@
1
+ require File.expand_path('watirspec/spec_helper', File.dirname(__FILE__))
2
+
3
+ describe Watir::Input do
4
+
5
+ before do
6
+ browser.goto WatirSpec.url_for("forms_with_input_elements.html")
7
+ end
8
+
9
+ describe "#type" do
10
+ it "returns an email type" do
11
+ expect(browser.input(name: "html5_email").type).to eq 'email'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ require 'active_support/ordered_hash'
2
+
3
+ module LocatorSpecHelper
4
+ def browser
5
+ @browser ||= double(Watir::Browser, wd: driver)
6
+ end
7
+
8
+ def driver
9
+ @driver ||= double(Selenium::WebDriver::Driver)
10
+ end
11
+
12
+ def locator(selector, attrs)
13
+ attrs ||= Watir::HTMLElement.attributes
14
+ element_validator = Watir::Locators::Element::Validator.new
15
+ selector_builder = Watir::Locators::Element::SelectorBuilder.new(driver, selector, attrs)
16
+ Watir::Locators::Element::Locator.new(browser, selector, selector_builder, element_validator)
17
+ end
18
+
19
+ def expect_one(*args)
20
+ expect(driver).to receive(:find_element).with(*args)
21
+ end
22
+
23
+ def expect_all(*args)
24
+ expect(driver).to receive(:find_elements).with(*args)
25
+ end
26
+
27
+ def locate_one(selector, attrs = nil)
28
+ locator(ordered_hash(selector), attrs).locate
29
+ end
30
+
31
+ def locate_all(selector, attrs = nil)
32
+ locator(ordered_hash(selector), attrs).locate_all
33
+ end
34
+
35
+ def element(opts = {})
36
+ attrs = opts.delete(:attributes)
37
+ el = double(Watir::Element, opts)
38
+
39
+ attrs.each do |key, value|
40
+ allow(el).to receive(:attribute).with(key).and_return(value)
41
+ end if attrs
42
+
43
+ el
44
+ end
45
+
46
+ def ordered_hash(selector)
47
+ case selector
48
+ when Hash
49
+ selector
50
+ when Array
51
+ ActiveSupport::OrderedHash[*selector]
52
+ else
53
+ raise ArgumentError, "couldn't create hash for #{selector.inspect}"
54
+ end
55
+ end
56
+ end
57
+
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
6
+
7
+ require 'watir'
8
+ require 'locator_spec_helper'
9
+ require 'rubygems'
10
+ require 'rspec'
11
+
12
+ include Watir
13
+
14
+ if ENV['ALWAYS_LOCATE'] == "false"
15
+ Watir.always_locate = false
16
+ end
17
+
18
+ if ENV['PREFER_CSS']
19
+ Watir.prefer_css = true
20
+ end
21
+
22
+ SELENIUM_SELECTORS = %i(class class_name css id tag_name xpath)
23
+
24
+ if ENV['TRAVIS']
25
+ ENV['DISPLAY'] = ":99.0"
26
+
27
+ if ENV['WATIR_BROWSER'] == "chrome"
28
+ ENV['WATIR_CHROME_BINARY'] = File.expand_path "chrome-linux/chrome"
29
+ ENV['WATIR_CHROME_DRIVER'] = File.expand_path "chrome-linux/chromedriver"
30
+ end
31
+ end
32
+
33
+ if Selenium::WebDriver::Platform.linux? && ENV['DISPLAY'].nil?
34
+ raise "DISPLAY not set"
35
+ end