watir_session 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b40a20b54cfe09649622bafd024804856695b234
4
- data.tar.gz: fcccb9373fefcbc5aa44a4cb8a9dd387ece3daef
3
+ metadata.gz: b8dbe01ed4a189544d75a9dd9442da5de4230658
4
+ data.tar.gz: 58006e6f4a52159e702fe9d0231f72c33e19027d
5
5
  SHA512:
6
- metadata.gz: 3ef12968842c063d13215666b88ff4b5d1463058019b22c13ddf9255e82efb9b99737cd6c3c4f12583261ed046ac733dffeafc9dd6b57d14b6b82b6453bfc877
7
- data.tar.gz: a7de7c9fe2a4a7e2fbf0af84a69d84ee78de403b7c7eb6016de458c6b60deb8a284a5a02fba69bc5bcce7bbbf9b0b95b5a8afdd147c18559f2a11a8f6e1ae707
6
+ metadata.gz: 711eabec5d9b973ded56125c98c010061cc98f6363bd4d85ec5eb41cae7e1cd010717cae92e73b2b25a0030a1e0412c26581535c041c584f6d32831e0081674d
7
+ data.tar.gz: 9c4a2f18ca0a97d6b5ea4e8a342d94495dabc790424e9eb190b2df87295b925be563af312ec915e448e5bde843f469787cde4c21b99b53006c3e3d2e7593a9fa
data/README.md CHANGED
@@ -31,8 +31,8 @@ with your 
test harness (RSpec, Cucumber, etc) for maximum flexibility.
31
31
 
32
32
  ```
ruby
33
33
  WatirSession.start

34
- WatirSession.start_test


35
- WatirSession.end_test


34
+ WatirSession.before_each


35
+ WatirSession.after_each


36
36
  ```
37
37
 
38
38
  ## Example
@@ -50,9 +50,9 @@ class SauceSession
50
50
  end
51
51
  ```
52
52
  ```ruby
53
- require 'model'
53
+ require 'watir_model'
54
54
 
55
- class SauceConfig < Model
55
+ class SauceConfig < WatirModel
56
56
  key(:sauce_username) { ENV['SAUCE_USERNAME'] }
57
57
  key(:sauce_access_key) { ENV['SAUCE_ACCESS_KEY'] }
58
58
  key(:endpoint) {"http://#{sauce_username}:#{sauce_access_key}@ondemand.saucelabs.com:80/wd/hub"}
@@ -64,10 +64,10 @@ RSpec.configure do |config|
64
64
  WatirSession.register_session(SauceSession.new)
65
65
 
66
66
  config.before(:each) do
67
- @browser = WatirSession.start_test
67
+ @browser = WatirSession.before_each
68
68
  end
69
69
  config.after(:each) do
70
- WatirSession.end_test
70
+ WatirSession.after_each
71
71
  end
72
72
  end
73
73
  ```
@@ -1,5 +1,7 @@
1
- require 'model'
1
+ require 'watir_model'
2
2
 
3
- class CustomConfig < Model
3
+ class CustomConfig < WatirModel
4
+
5
+ # Implement this class in your project
4
6
 
5
7
  end
@@ -1,7 +1,6 @@
1
- require 'model'
2
- require 'yaml'
1
+ require 'watir_model'
3
2
 
4
- class WatirConfig < Model
3
+ class WatirConfig < WatirModel
5
4
 
6
5
  ## --Browser Options-- ##
7
6
 
@@ -63,8 +62,4 @@ class WatirConfig < Model
63
62
  # Note: This setting will be ignored if platform is not Linux, and will raise error if xvfb is not installed
64
63
  key(:headless) { ENV['HEADLESS'] == 'true' }
65
64
 
66
- ## --Additional Options-- ##
67
-
68
- key(:custom_config)
69
-
70
65
  end
@@ -3,12 +3,37 @@ module WatirSession
3
3
  extend self
4
4
 
5
5
  attr_reader :browser
6
- attr_accessor :watir_config
6
+ attr_writer :watir_config
7
7
 
8
8
  def watir_config
9
9
  @watir_config ||= WatirConfig.new
10
10
  end
11
11
 
12
+ def custom_config
13
+ @custom_config ||= CustomConfig.new
14
+ end
15
+
16
+ def create_configurations
17
+ spec_path = $LOAD_PATH.select { |path| path =~ /\/spec$/ }.first
18
+ config_path = spec_path.gsub('spec', 'config')
19
+
20
+ return unless Dir.exist?(config_path)
21
+ Dir.entries(config_path).select { |file| file =~ /\.yml$/ }.each do |yaml|
22
+ config_name = yaml.gsub('.yml', '')
23
+ next unless Object.const_defined?("#{config_name.capitalize}Config")
24
+ load_yml(config_path, config_name)
25
+ end
26
+ end
27
+
28
+ def load_yml(config_path, config_name)
29
+ config = YAML.load_file("#{config_path}/#{config_name}.yml")
30
+ if config.values.all? { |v| v.is_a? Hash } && custom_config.respond_to?(config_name.singularize)
31
+ config = config[custom_config.send(config_name.singularize)]
32
+ end
33
+ obj = Object.const_get("#{config_name.capitalize}Config").new(config)
34
+ custom_config.send("#{config_name}=", obj)
35
+ end
36
+
12
37
  def registered_sessions
13
38
  @registered_sessions ||= []
14
39
  end
@@ -27,77 +52,74 @@ module WatirSession
27
52
  end
28
53
  end
29
54
 
55
+ def start
56
+ configure_watir
57
+ create_configurations
58
+ end
59
+
60
+ def before_suite(*args)
61
+ create_browser if watir_config.reuse_browser
62
+
63
+ execute_hook :before_suite, *args
64
+ end
65
+
66
+ def before_browser(*args)
67
+ execute_hook :before_browser, *args
68
+ end
69
+
30
70
  def create_browser(*args)
31
- use_headless_display if @watir_config.headless
71
+ use_headless_display if watir_config.headless
32
72
 
33
73
  @browser = execute_hook(:create_browser, *args).compact.first
34
74
 
35
75
  unless @browser
36
76
  http_client = Selenium::WebDriver::Remote::Http::Default.new
37
- http_client.timeout = @watir_config.http_timeout
38
- @browser = Watir::Browser.new(@watir_config.browser,
77
+ http_client.timeout = watir_config.http_timeout
78
+ @browser = Watir::Browser.new(watir_config.browser,
39
79
  http_client: http_client)
40
80
  end
41
81
  @browser
42
82
  end
43
83
 
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
84
+ def before_each(*args)
85
+ if watir_config.reuse_browser && browser.nil
58
86
  raise StandardError, "#before_tests method must be set in order to use
59
87
  the #reuse_browser configuration setting"
60
88
  end
61
89
 
62
- before_test(*args)
90
+ before_browser(*args)
63
91
 
64
- @browser = create_browser(*args) unless @watir_config.reuse_browser
65
- @browser.window.maximize if @watir_config.maximize_browser
92
+ @browser = create_browser(*args) unless watir_config.reuse_browser
93
+ @browser.window.maximize if watir_config.maximize_browser
66
94
 
67
- execute_hook :start_test, *args
95
+ execute_hook :before_each, *args
68
96
 
69
97
  @browser
70
98
  end
71
99
 
72
- def end_test(*args)
73
- execute_hook :end_test, *args
100
+ def after_each(*args)
101
+ execute_hook :after_each, *args
74
102
 
75
103
  take_screenshot(*args) unless watir_config.take_screenshots == :never
76
104
 
77
105
  quit_browser unless watir_config.reuse_browser
78
106
 
79
- after_test(*args)
107
+ after_browser(*args)
80
108
  end
81
109
 
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
110
+ def after_browser(*args)
111
+ execute_hook :after_browser, *args
87
112
  end
88
- alias_method :end, :after_tests
89
113
 
90
114
  def take_screenshot(*args)
91
115
  screenshot = execute_hook(:take_screenshot, *args).compact
92
116
  browser.screenshot.save("screenshot.png") if screenshot.nil?
93
117
  end
94
118
 
95
- def before_test(*args)
96
- execute_hook :before_test, *args
97
- end
119
+ def after_suite(*args)
120
+ quit_browser if watir_config.reuse_browser
98
121
 
99
- def after_test(*args)
100
- execute_hook :after_test, *args
122
+ execute_hook :after_suite, *args
101
123
  end
102
124
 
103
125
  def quit_browser
@@ -119,6 +141,7 @@ the #reuse_browser configuration setting"
119
141
 
120
142
  def reset_config!
121
143
  @watir_config = nil
144
+ @custom_config = nil
122
145
  end
123
146
 
124
147
  def reset_registered_sessions!
@@ -126,9 +149,9 @@ the #reuse_browser configuration setting"
126
149
  end
127
150
 
128
151
  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
152
+ Watir.default_timeout = watir_config.watir_timeout
153
+ Watir.prefer_css = watir_config.prefer_css
154
+ Watir.always_locate = watir_config.always_locate
132
155
  end
133
156
 
134
157
  def use_headless_display
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'watir_session'
5
- spec.version = '0.1.0'
5
+ spec.version = '0.1.1'
6
6
  spec.authors = ['Titus Fortner']
7
7
  spec.email = ['titusfortner@gmail.com']
8
8
 
@@ -29,6 +29,6 @@ to configurarion and session data so they do not need to be passed around as par
29
29
  spec.add_development_dependency 'rspec', '~> 3.0'
30
30
  spec.add_development_dependency 'headless' # This only gets required when on Linux
31
31
  spec.add_development_dependency 'watir-webdriver'
32
- spec.add_development_dependency 'test-model'
32
+ spec.add_development_dependency 'watir_model'
33
33
 
34
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watir_session
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Titus Fortner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-24 00:00:00.000000000 Z
11
+ date: 2016-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: test-model
84
+ name: watir_model
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="