watir_session 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b40a20b54cfe09649622bafd024804856695b234
4
+ data.tar.gz: fcccb9373fefcbc5aa44a4cb8a9dd387ece3daef
5
+ SHA512:
6
+ metadata.gz: 3ef12968842c063d13215666b88ff4b5d1463058019b22c13ddf9255e82efb9b99737cd6c3c4f12583261ed046ac733dffeafc9dd6b57d14b6b82b6453bfc877
7
+ data.tar.gz: a7de7c9fe2a4a7e2fbf0af84a69d84ee78de403b7c7eb6016de458c6b60deb8a284a5a02fba69bc5bcce7bbbf9b0b95b5a8afdd147c18559f2a11a8f6e1ae707
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in watir_session.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Titus Fortner
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,91 @@
1
+ # WatirSession
2
+
3
+ This gem leverages the Watir test library to allow for easy access
4
+ to configurarion and session data so they do not need to be passed around as
5
+ parameters throughout your tests.
6
+ The intention is to provide a solution that is easy to use and maintain,
7
+ while still providing power and flexibility.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'watir_session'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install watir_session
24
+
25
+ ## Usage
26
+
27
+ The default WatirConfig class uses the recommended settings without needing 

28
+ any modifications. 
The hooks into the WatirSession class are designed to work
29
+ with your 
test harness (RSpec, Cucumber, etc) for maximum flexibility.
30
+ 
At a minimum, you'll need to call:
31
+
32
+ ```
ruby
33
+ WatirSession.start

34
+ WatirSession.start_test


35
+ WatirSession.end_test


36
+ ```
37
+
38
+ ## Example
39
+
40
+ Here's an example for how you can add a session for Saucelabs
41
+
42
+ ```ruby
43
+ class SauceSession
44
+ def initialize
45
+ @sauce_config = SuaceConfig.new
46
+ end
47
+ def create_browser)
48
+ @browser = Watir::Browser.new(:remote, url: @sauce_config.endpoint)
49
+ end
50
+ end
51
+ ```
52
+ ```ruby
53
+ require 'model'
54
+
55
+ class SauceConfig < Model
56
+ key(:sauce_username) { ENV['SAUCE_USERNAME'] }
57
+ key(:sauce_access_key) { ENV['SAUCE_ACCESS_KEY'] }
58
+ key(:endpoint) {"http://#{sauce_username}:#{sauce_access_key}@ondemand.saucelabs.com:80/wd/hub"}
59
+ end
60
+ ```
61
+ ```ruby
62
+ RSpec.configure do |config|
63
+ WatirSession.start
64
+ WatirSession.register_session(SauceSession.new)
65
+
66
+ config.before(:each) do
67
+ @browser = WatirSession.start_test
68
+ end
69
+ config.after(:each) do
70
+ WatirSession.end_test
71
+ end
72
+ end
73
+ ```
74
+
75
+ ## Development
76
+
77
+ Run `rake spec` to run the tests
78
+ To install this gem onto your local machine, run `bundle exec rake install`.
79
+
80
+
81
+ ## Contributing
82
+
83
+ Bug reports and pull requests are welcome on GitHub at
84
+ https://github.com/titusfortner/watir_session.
85
+
86
+
87
+ ## License
88
+
89
+ The gem is available as open source under the terms of the
90
+ [MIT License](http://opensource.org/licenses/MIT).
91
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,5 @@
1
+ require 'model'
2
+
3
+ class CustomConfig < Model
4
+
5
+ end
@@ -0,0 +1,70 @@
1
+ require 'model'
2
+ require 'yaml'
3
+
4
+ class WatirConfig < Model
5
+
6
+ ## --Browser Options-- ##
7
+
8
+ # Supported browsers:
9
+ # chrome, firefox, safari, phantomjs, edge, internet_explorer
10
+ key(:browser) { (ENV['BROWSER'] || 'chrome').to_sym }
11
+
12
+ # Time in seconds to wait to hear back from the browser after sending a command
13
+ key(:http_timeout) { (ENV['HTTP_TIMEOUT'] || '60').to_i }
14
+
15
+
16
+ ## --Watir Options-- ##
17
+
18
+ # Time in seconds to wait to interact with an element
19
+ key(:watir_timeout) { (ENV['WATIR_TIMEOUT'] || '30').to_i }
20
+
21
+ # true means that when an element goes stale it is relocated
22
+ # false means that when an element goes stale, an exception is thrown
23
+ # Note: As currently implemented, this setting would be better named relocate_when_necessary
24
+ key(:always_locate) { ENV['ALWAYS_LOCATE'] != 'true' }
25
+
26
+ # true means elements will be located with CSS instead of XPATH when possible
27
+ # false means that elements will be located by XPATH instead of CSS when possible
28
+ key(:prefer_css) { ENV['PREFER_CSS'] == 'true' }
29
+
30
+
31
+ ## --Test Options-- ##
32
+
33
+ # true means the browser does not automatically close between session start and exit
34
+ # false means the browser quits and restarts after each test
35
+ key(:reuse_browser) { ENV['REUSE_BROWSER'] == 'true' }
36
+
37
+ # 'always' means the test takes a screenshot after the end of each test
38
+ # 'failing' means the test takes a screenshot after the end of each failing test
39
+ # 'never' means the test never takes a screenshot automatically
40
+ key(:take_screenshots) { (ENV['TAKE_SCREENSHOTS'] || 'never').to_sym }
41
+
42
+ # TODO - implement this, look at Watirmark code
43
+ # true means the browser quits as expected at the end of a session
44
+ # false means the browser remains open after teh session has ended
45
+ # Note: reuse_browser must be true for this setting to matter
46
+ key(:close_browser_on_exit) { ENV['CLOSE_BROWSER_ON_EXIT'] != 'true' }
47
+
48
+ # true means the browser is set to maximize after starting
49
+ # false means the size of the browser is not automatically changed after browser is started
50
+ key(:maximize_browser) { ENV['MAXIMIZE_BROWSER'] == 'true' }
51
+
52
+ # TODO - Implement Logs
53
+ # 'UNKNOWN'- An unknown message that should always be logged.
54
+ # 'FATAL' - An unhandleable error that results in a program crash.
55
+ # 'ERROR' - A handleable error condition.
56
+ # 'WARN' - A warning.
57
+ # 'INFO' - Generic (useful) information about system operation.
58
+ # 'DEBUG' - Low-level information for developers.
59
+ key(:log_level) { ENV['LOG_LEVEL'] || 'INFO' }
60
+
61
+ # true means the browser will run in xvfb
62
+ # false means the browser will run in the normal window
63
+ # Note: This setting will be ignored if platform is not Linux, and will raise error if xvfb is not installed
64
+ key(:headless) { ENV['HEADLESS'] == 'true' }
65
+
66
+ ## --Additional Options-- ##
67
+
68
+ key(:custom_config)
69
+
70
+ end
@@ -0,0 +1,144 @@
1
+ module WatirSession
2
+
3
+ extend self
4
+
5
+ attr_reader :browser
6
+ attr_accessor :watir_config
7
+
8
+ def watir_config
9
+ @watir_config ||= WatirConfig.new
10
+ end
11
+
12
+ def registered_sessions
13
+ @registered_sessions ||= []
14
+ end
15
+
16
+ def register_session(session)
17
+ registered_sessions << session
18
+ end
19
+
20
+ def execute_hook(method, *args)
21
+ sessions = registered_sessions.select do |session|
22
+ session.public_methods(false).include? method
23
+ end
24
+
25
+ sessions.each_with_object([]) do |session, array|
26
+ array << session.send(method, *args)
27
+ end
28
+ end
29
+
30
+ def create_browser(*args)
31
+ use_headless_display if @watir_config.headless
32
+
33
+ @browser = execute_hook(:create_browser, *args).compact.first
34
+
35
+ unless @browser
36
+ http_client = Selenium::WebDriver::Remote::Http::Default.new
37
+ http_client.timeout = @watir_config.http_timeout
38
+ @browser = Watir::Browser.new(@watir_config.browser,
39
+ http_client: http_client)
40
+ end
41
+ @browser
42
+ end
43
+
44
+ def before_tests(config = nil, *args)
45
+ @watir_config = config || watir_config
46
+
47
+ configure_watir
48
+
49
+ create_browser if @watir_config.reuse_browser
50
+
51
+ execute_hook :before_tests, *args
52
+ execute_hook :start, *args
53
+ end
54
+ alias_method :start, :before_tests
55
+
56
+ def start_test(*args)
57
+ if @watir_config.reuse_browser && browser.nil
58
+ raise StandardError, "#before_tests method must be set in order to use
59
+ the #reuse_browser configuration setting"
60
+ end
61
+
62
+ before_test(*args)
63
+
64
+ @browser = create_browser(*args) unless @watir_config.reuse_browser
65
+ @browser.window.maximize if @watir_config.maximize_browser
66
+
67
+ execute_hook :start_test, *args
68
+
69
+ @browser
70
+ end
71
+
72
+ def end_test(*args)
73
+ execute_hook :end_test, *args
74
+
75
+ take_screenshot(*args) unless watir_config.take_screenshots == :never
76
+
77
+ quit_browser unless watir_config.reuse_browser
78
+
79
+ after_test(*args)
80
+ end
81
+
82
+ def after_tests(*args)
83
+ quit_browser if @watir_config.reuse_browser
84
+
85
+ execute_hook :after_tests, *args
86
+ execute_hook :end, *args
87
+ end
88
+ alias_method :end, :after_tests
89
+
90
+ def take_screenshot(*args)
91
+ screenshot = execute_hook(:take_screenshot, *args).compact
92
+ browser.screenshot.save("screenshot.png") if screenshot.nil?
93
+ end
94
+
95
+ def before_test(*args)
96
+ execute_hook :before_test, *args
97
+ end
98
+
99
+ def after_test(*args)
100
+ execute_hook :after_test, *args
101
+ end
102
+
103
+ def quit_browser
104
+ if @headless
105
+ @headless.destroy
106
+ @headless = nil
107
+ end
108
+
109
+ return if @browser.nil?
110
+
111
+ @browser.quit
112
+ @browser = nil
113
+ end
114
+
115
+ def restart_browser!
116
+ quit_browser
117
+ create_browser
118
+ end
119
+
120
+ def reset_config!
121
+ @watir_config = nil
122
+ end
123
+
124
+ def reset_registered_sessions!
125
+ @registered_sessions = nil
126
+ end
127
+
128
+ def configure_watir
129
+ Watir.default_timeout = @watir_config.watir_timeout
130
+ Watir.prefer_css = @watir_config.prefer_css
131
+ Watir.always_locate = @watir_config.always_locate
132
+ end
133
+
134
+ def use_headless_display
135
+ unless RbConfig::CONFIG['host_os'].match('linux')
136
+ warn "Headless only supported on Linux"
137
+ return
138
+ end
139
+ require 'headless'
140
+ @headless = Headless.new
141
+ @headless.start
142
+ end
143
+
144
+ end
@@ -0,0 +1,7 @@
1
+ require 'watir-webdriver'
2
+
3
+ require 'watir_session/custom_config'
4
+ require 'watir_session/watir_config'
5
+ require 'watir_session/watir_session'
6
+
7
+ include WatirSession
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'watir_session'
5
+ spec.version = '0.1.0'
6
+ spec.authors = ['Titus Fortner']
7
+ spec.email = ['titusfortner@gmail.com']
8
+
9
+ spec.summary = %q{Allows easy access to configuration and session data for Watir tests.}
10
+ spec.description = %q{This gem leverages the Watir test library to allow for easy access
11
+ to configurarion and session data so they do not need to be passed around as parameters throughout your tests.}
12
+ spec.homepage = 'https://github.com/titusfortner/watir_session'
13
+ spec.license = 'MIT'
14
+
15
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
16
+ # delete this section to allow pushing this gem to any host.
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
19
+ else
20
+ raise 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
21
+ end
22
+
23
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+
27
+ spec.add_development_dependency 'bundler', '~> 1.11'
28
+ spec.add_development_dependency 'rake', '~> 10.0'
29
+ spec.add_development_dependency 'rspec', '~> 3.0'
30
+ spec.add_development_dependency 'headless' # This only gets required when on Linux
31
+ spec.add_development_dependency 'watir-webdriver'
32
+ spec.add_development_dependency 'test-model'
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: watir_session
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Titus Fortner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: headless
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: watir-webdriver
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: test-model
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |-
98
+ This gem leverages the Watir test library to allow for easy access
99
+ to configurarion and session data so they do not need to be passed around as parameters throughout your tests.
100
+ email:
101
+ - titusfortner@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - lib/watir_session.rb
114
+ - lib/watir_session/custom_config.rb
115
+ - lib/watir_session/watir_config.rb
116
+ - lib/watir_session/watir_session.rb
117
+ - watir_session.gemspec
118
+ homepage: https://github.com/titusfortner/watir_session
119
+ licenses:
120
+ - MIT
121
+ metadata:
122
+ allowed_push_host: https://rubygems.org
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.4.5.1
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Allows easy access to configuration and session data for Watir tests.
143
+ test_files: []
144
+ has_rdoc: