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
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source "http://rubygems.org"
2
+
3
+ unless ENV['TRAVIS']
4
+ gem "simplecov", ">= 0.3.5", platform: :ruby_19
5
+ end
6
+
7
+ if ENV['LOCAL_WEBIDL']
8
+ gem 'webidl', path: File.expand_path('../webidl')
9
+ end
10
+
11
+ # Specify your gem's dependencies in watir.gemspec
12
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ (the MIT License)
2
+
3
+ Copyright (c) 2009-2015 Jari Bakken
4
+ Copyright (c) 2015-2016 Alex Rodionov, Titus Fortner
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,92 @@
1
+ watir
2
+ ===============
3
+
4
+ Watir Powered By Selenium!
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/watir.svg)](http://badge.fury.io/rb/watir)
7
+ [![Build Status](https://travis-ci.org/watir/watir.svg?branch=master)](https://travis-ci.org/watir/watir)
8
+ [![Code Climate](https://codeclimate.com/github/watir/watir.svg)](https://codeclimate.com/github/watir/watir)
9
+ [![Dependency Status](https://gemnasium.com/watir/watir.svg)](https://gemnasium.com/watir/watir)
10
+ [![Coverage Status](https://coveralls.io/repos/watir/watir/badge.svg?branch=master)](https://coveralls.io/r/watir/watir)
11
+
12
+ Example
13
+ -------
14
+
15
+ ```ruby
16
+ require 'watir'
17
+
18
+ browser = Watir::Browser.new
19
+ browser.goto 'google.com'
20
+ browser.text_field(title: 'Search').set 'Hello World!'
21
+ browser.button(type: 'submit').click
22
+
23
+ puts browser.title
24
+ # => 'Hello World! - Google Search'
25
+ browser.close
26
+ ```
27
+
28
+ Description
29
+ -----------
30
+
31
+ The majority of element methods Watir provides with is autogenerated from specifications.
32
+ This is done by extracting the IDL parts from the spec and processing them with the WebIDL gem (link below).
33
+ Currently supported specifications are:
34
+
35
+ * [HTML](https://www.whatwg.org/specs/web-apps/current-work/) (`lib/watir/elements/html_generated.rb`)
36
+ * [SVG](http://www.w3.org/TR/SVG2/single-page.html) (`lib/watir/elements/svg_generated.rb`)
37
+
38
+ Specs
39
+ -----
40
+
41
+ Watir uses [watirspec](http://github.com/watir/watirspec) for testing. After cloning, you should fetch the submodule:
42
+
43
+ ```bash
44
+ git submodule init && git submodule update
45
+ ```
46
+
47
+ Specs specific to Watir are found in `spec/*_spec.rb`, with watirspec in `spec/watirspec/`.
48
+
49
+ Doctests
50
+ --------
51
+
52
+ Watir uses [yard-doctest](https://github.com/p0deje/yard-doctest) for testing documentation examples.
53
+
54
+ ```bash
55
+ rake yard:doctest
56
+ ```
57
+
58
+ API docs
59
+ --------
60
+
61
+ * http://rdoc.info/gems/watir/ (updated on every release)
62
+
63
+ See also
64
+ --------
65
+
66
+ * http://watir.github.io
67
+ * http://github.com/jarib/webidl
68
+ * http://github.com/watir/watirspec
69
+ * https://github.com/seleniumhq/selenium
70
+
71
+ Dependencies
72
+ ------------
73
+
74
+ * selenium-webdriver
75
+
76
+ Note on Patches/Pull Requests
77
+ -----------------------------
78
+
79
+ * Fork the project.
80
+ * Make your feature addition or bug fix.
81
+ * Add tests for it. This is important so I don't break it in a
82
+ future version unintentionally.
83
+ * Commit, do not mess with Rakefile, version, or history.
84
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
85
+ * Send me a pull request. Bonus points for topic branches.
86
+
87
+ Copyright
88
+ ---------
89
+
90
+ Copyright (c) 2009-2015 Jari Bakken
91
+ Copyright (c) 2015-2016 Alex Rodionov, Titus Fortner
92
+ See LICENSE for details
data/Rakefile CHANGED
@@ -1,32 +1,161 @@
1
- $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
-
3
- require 'bundler'
4
- Bundler::GemHelper.install_tasks
5
-
6
- task :default => "build:all"
7
-
8
- namespace :build do
9
- desc "Build for Windows platform."
10
- task :win => :build do
11
- begin
12
- ENV["build_for_windows"] = "true"
13
- Rake::Task["build"].reenable
14
- Rake::Task["build"].invoke
15
- ensure
16
- ENV["build_for_windows"] = nil
17
- end
18
- end
19
-
20
- desc "Build for all platforms."
21
- task :all => [:build, "build:win"]
22
- end
23
-
24
- namespace :release do
25
- desc "Release for Windows platform."
26
- task :win => "build:win" do
27
- sh "gem push #{Dir["pkg/*mingw32.gem"].sort_by{|f| File.mtime(f)}.last}"
28
- end
29
-
30
- desc "Release for all platforms."
31
- task :all => [:release, "release:win"]
32
- end
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+
3
+ require 'bundler'
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ require 'rspec/core/rake_task'
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ spec.ruby_opts = "-I lib:spec"
9
+ spec.rspec_opts = %w[--color --require fuubar --format Fuubar]
10
+ spec.pattern = 'spec/**/*_spec.rb'
11
+ end
12
+
13
+ namespace :spec do
14
+ RSpec::Core::RakeTask.new(:html) do |spec|
15
+ spec.ruby_opts = "-I lib:spec"
16
+ spec.rspec_opts = "--format html --out #{ENV["SPEC_REPORT"] || "specs.html"}"
17
+ spec.pattern = 'spec/**/*_spec.rb'
18
+ end
19
+ end
20
+
21
+ {
22
+ html: 'https://www.whatwg.org/specs/web-apps/current-work/',
23
+ svg: 'http://www.w3.org/TR/SVG2/single-page.html'
24
+ }.each do |type, spec_uri|
25
+ namespace type do
26
+ spec_path = "support/#{type}.html"
27
+
28
+ task generator_lib: :lib do
29
+ require "watir/generator"
30
+ end
31
+
32
+ desc "Download #{type.upcase} spec from #{spec_uri}"
33
+ task :download do
34
+ require "open-uri"
35
+ mv spec_path, "#{spec_path}.old" if File.exist?(spec_path)
36
+ downloaded_bytes = 0
37
+
38
+ File.open(spec_path, "w") do |io|
39
+ io << "<!-- downloaded from #{spec_uri} on #{Time.now} -->\n"
40
+ io << data = open(spec_uri).read
41
+ downloaded_bytes = data.bytesize
42
+ end
43
+
44
+ puts "#{spec_uri} => #{spec_path} (#{downloaded_bytes} bytes)"
45
+ end
46
+
47
+ desc "Print IDL parts from #{spec_uri}"
48
+ task print: :generator_lib do
49
+ extractor = Watir::Generator.const_get("#{type.upcase}::SpecExtractor").new(spec_path)
50
+
51
+ extractor.process.each do |tag_name, interface_definitions|
52
+ puts "#{tag_name.ljust(10)} => #{interface_definitions.map(&:name)}"
53
+ end
54
+
55
+ extractor.print_hierarchy
56
+
57
+ if extractor.errors.any?
58
+ puts "\n\n<======================= ERRORS =======================>\n\n"
59
+ puts extractor.errors.join("\n" + "=" * 80 + "\n")
60
+ end
61
+ end
62
+
63
+ desc 'Re-generate the base Watir element classes from the spec'
64
+ task generate: :generator_lib do
65
+ old_file = "lib/watir/elements/#{type}_elements.rb"
66
+ generator = Watir::Generator.const_get(type.upcase).new
67
+
68
+ File.open("#{old_file}.new", "w") do |file|
69
+ generator.generate(spec_path, file)
70
+ end
71
+
72
+ if File.exist?(old_file)
73
+ system "diff -Naut #{old_file} #{old_file}.new | less"
74
+ end
75
+ end
76
+
77
+ desc "Move #{type}.rb.new to #{type}.rb"
78
+ task :overwrite do
79
+ file = "lib/watir/elements/#{type}_elements.rb"
80
+ mv "#{file}.new", file
81
+ end
82
+
83
+ desc "download spec -> generate -> #{type}.rb"
84
+ task update: [:download, :generate, :overwrite]
85
+ end
86
+ end
87
+
88
+ require 'yard'
89
+ YARD::Rake::YardocTask.new do |task|
90
+ task.options = %w[--debug] # this is pretty slow, so nice with some output
91
+ end
92
+
93
+ require 'yard-doctest'
94
+ YARD::Doctest::RakeTask.new do |task|
95
+ task.doctest_opts = ['-v']
96
+ end
97
+
98
+ namespace :changes do
99
+ task :differ do
100
+ require './support/version_differ'
101
+ end
102
+
103
+ desc 'Update CHANGES.md'
104
+ task update: :differ do
105
+ VersionDiffer.new.update('CHANGES.md')
106
+ end
107
+
108
+ desc 'Generate CHANGES.md from scratch'
109
+ task generate: :differ do
110
+ VersionDiffer.new.generate('CHANGES.md')
111
+ end
112
+
113
+ desc 'Print latest diff'
114
+ task print: :differ do
115
+ VersionDiffer.new.print_latest(STDOUT)
116
+ end
117
+ end
118
+
119
+ load "spec/watirspec/watirspec.rake" if File.exist?("spec/watirspec/watirspec.rake")
120
+
121
+ task default: [:spec, 'yard:doctest']
122
+
123
+ namespace :spec do
124
+ require 'selenium-webdriver'
125
+
126
+ desc 'Run specs in all browsers'
127
+ task all_browsers: [:browsers, :remote_browsers]
128
+
129
+ desc 'Run specs locally for all browsers'
130
+ task browsers: [:chrome,
131
+ :firefox,
132
+ :ff_legacy,
133
+ :phantomjs,
134
+ (:safari if Selenium::WebDriver::Platform.os == :macosx),
135
+ (:ie if Selenium::WebDriver::Platform.os == :windows),
136
+ (:edge if Selenium::WebDriver::Platform.os == :windows)].compact
137
+
138
+ desc 'Run specs remotely for all browsers'
139
+ task remote_browsers: [:remote_chrome,
140
+ :remote_firefox,
141
+ :remote_ff_legacy,
142
+ :remote_phantomjs,
143
+ (:remote_safari if Selenium::WebDriver::Platform.os == :macosx),
144
+ (:remote_ie if Selenium::WebDriver::Platform.os == :windows),
145
+ (:remote_edge if Selenium::WebDriver::Platform.os == :windows)].compact
146
+
147
+ %w(firefox ff_legacy chrome safari phantomjs ie edge).each do |browser|
148
+ desc "Run specs in #{browser}"
149
+ task browser do
150
+ ENV['WATIR_BROWSER'] = browser
151
+ Rake::Task[:spec].execute
152
+ end
153
+
154
+ desc "Run specs in Remote #{browser}"
155
+ task "remote_#{browser}" do
156
+ ENV['WATIR_BROWSER'] = 'remote'
157
+ ENV['REMOTE_BROWSER'] = browser
158
+ Rake::Task[:spec].execute
159
+ end
160
+ end
161
+ end
@@ -1 +1,127 @@
1
- require File.expand_path('watir/loader', File.dirname(__FILE__))
1
+ require 'selenium-webdriver'
2
+
3
+ require 'watir/wait'
4
+ require 'watir/exception'
5
+ require 'watir/xpath_support'
6
+ require 'watir/window'
7
+ require 'watir/has_window'
8
+ require 'watir/alert'
9
+ require 'watir/atoms'
10
+ require 'watir/container'
11
+ require 'watir/cookies'
12
+ require 'watir/browser'
13
+ require 'watir/screenshot'
14
+ require 'watir/after_hooks'
15
+
16
+ module Watir
17
+ @always_locate = true
18
+
19
+ class << self
20
+ def always_locate?
21
+ @always_locate
22
+ end
23
+
24
+ #
25
+ # Whether or not Watir should cache element references or always re-locate an Element on use.
26
+ # Defaults to true.
27
+ #
28
+
29
+ def always_locate=(bool)
30
+ @always_locate = bool
31
+ end
32
+
33
+ def default_timeout
34
+ @default_timeout ||= 30
35
+ end
36
+
37
+ #
38
+ # Default wait time for wait methods.
39
+ #
40
+
41
+ def default_timeout=(value)
42
+ @default_timeout = value
43
+ end
44
+
45
+ def prefer_css?
46
+ @prefer_css
47
+ end
48
+
49
+ #
50
+ # Whether or not Watir should prefer CSS when translating the Watir selectors to Selenium.
51
+ # Defaults to false.
52
+ #
53
+
54
+ def prefer_css=(bool)
55
+ @prefer_css = bool
56
+ end
57
+
58
+ def locator_namespace
59
+ @locator_namespace ||= Watir::Locators
60
+ end
61
+
62
+ #
63
+ # Whether the locators should be used from a different namespace.
64
+ # Defaults to Watir::Locators.
65
+ #
66
+
67
+ def locator_namespace=(mod)
68
+ @locator_namespace = mod
69
+ end
70
+
71
+ #
72
+ # @api private
73
+ #
74
+
75
+ def tag_to_class
76
+ @tag_to_class ||= {}
77
+ end
78
+
79
+ #
80
+ # @api private
81
+ #
82
+
83
+ def element_class_for(tag_name)
84
+ tag_to_class[tag_name.to_sym] || HTMLElement
85
+ end
86
+ end
87
+
88
+ end
89
+
90
+ require 'watir/attribute_helper'
91
+ require 'watir/row_container'
92
+ require 'watir/cell_container'
93
+ require 'watir/user_editable'
94
+ require 'watir/element_collection'
95
+ require 'watir/elements/element'
96
+
97
+ require 'watir/elements/html_elements'
98
+ require 'watir/elements/svg_elements'
99
+
100
+ require 'watir/elements/area'
101
+ require 'watir/elements/button'
102
+ require 'watir/elements/cell'
103
+ require 'watir/elements/checkbox'
104
+ require 'watir/elements/dlist'
105
+ require 'watir/elements/file_field'
106
+ require 'watir/elements/font'
107
+ require 'watir/elements/form'
108
+ require 'watir/elements/iframe'
109
+ require 'watir/elements/hidden'
110
+ require 'watir/elements/image'
111
+ require 'watir/elements/input'
112
+ require 'watir/elements/link'
113
+ require 'watir/elements/option'
114
+ require 'watir/elements/radio'
115
+ require 'watir/elements/row'
116
+ require 'watir/elements/select'
117
+ require 'watir/elements/table'
118
+ require 'watir/elements/table_cell'
119
+ require 'watir/elements/table_row'
120
+ require 'watir/elements/table_section'
121
+ require 'watir/elements/text_area'
122
+ require 'watir/elements/text_field'
123
+
124
+ require 'watir/locators'
125
+ require 'watir/aliases'
126
+
127
+ Watir.tag_to_class.freeze