symbiont 0.11.0 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,164 +1,161 @@
1
- module Symbiont
2
- module Page
3
- include Helpers
4
-
5
- def view
6
- no_url_is_provided if asserted_url.nil?
7
- browser.goto(asserted_url)
8
- self
9
- end
10
-
11
- def has_correct_url?
12
- no_url_matches_is_provided if url_match.nil?
13
- !(browser.url =~ url_match).nil?
14
- end
15
-
16
- def has_correct_title?
17
- no_title_is_provided if asserted_title.nil?
18
- !(browser.title.match(asserted_title)).nil?
19
- end
20
-
21
- def verified?
22
- has_correct_url?
23
- has_correct_title?
24
- end
25
-
26
- def asserted_url
27
- self.class.asserted_url
28
- end
29
-
30
- def url_match
31
- self.class.url_match
32
- end
33
-
34
- def asserted_title
35
- self.class.asserted_title
36
- end
37
-
38
- def url
39
- browser.url
40
- end
41
-
42
- def markup
43
- browser.html
44
- end
45
-
46
- def text
47
- browser.text
48
- end
49
-
50
- def title
51
- browser.title
52
- end
53
-
54
- def visit(url)
55
- browser.goto(url)
56
- end
57
-
58
- def screenshot(file)
59
- browser.wd.save_screenshot(file)
60
- end
61
-
62
- def run_script(script, *args)
63
- browser.execute_script(script, *args)
64
- end
65
-
66
- def get_cookie(name)
67
- for cookie in browser.cookies.to_a
68
- if cookie[:name] == name
69
- return cookie[:value]
70
- end
71
- end
72
- nil
73
- end
74
-
75
- def clear_cookies
76
- browser.cookies.clear
77
- end
78
-
79
- def refresh
80
- browser.refresh
81
- end
82
-
83
- # @param block [Proc] the code that generates the alert
84
- # @return [String] the message contained in the alert message box
85
- def will_alert(&block)
86
- yield
87
- value = nil
88
- if browser.alert.exists?
89
- value = browser.alert.text
90
- browser.alert.ok
91
- end
92
- value
93
- end
94
-
95
- # @param response [Boolean] true to accept the confirmation, false to cancel it
96
- # @param block [Proc] the code that generates the confirmation
97
- # @return [String] the message contained in the confirmation message box
98
- def will_confirm(response, &block)
99
- yield
100
- value = nil
101
- if browser.alert.exists?
102
- value = browser.alert.text
103
- response ? browser.alert.ok : browser.alert.close
104
- end
105
- value
106
- end
107
-
108
- # @param response [String] the value to be used in the prompt
109
- # @param block [Proc] the code that generates the prompt
110
- # @return [Hash] :message for the prompt message, :default_value for
111
- # the value that the prompt had before the response was applied
112
- def will_prompt(response, &block)
113
- cmd = "window.prompt = function(text, value) {window.__lastWatirPrompt = {message: text, default_value: value}; return '#{response}';}"
114
- browser.wd.execute_script(cmd)
115
- yield
116
- result = browser.wd.execute_script('return window.__lastWatirPrompt')
117
- result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
118
- result
119
- end
120
-
121
- # Used to identify a web element or action on a web element as existing
122
- # within an enclosing window object. The window can be referenced using
123
- # either the title attribute of the window or a direct URL. The URL does
124
- # not have to be the entire URL; it can just be a page name.
125
- #
126
- # @param locator [Hash] the :title or :url of the window
127
- # @param block [Proc] any code that should be executed as an
128
- # action on or within the window
129
- def within_window(locator, &block)
130
- identifier = {locator.keys.first => /#{Regexp.escape(locator.values.first)}/}
131
- browser.window(identifier).use(&block)
132
- end
133
-
134
- # Used to identify a web element as existing within an enclosing object
135
- # like a modal dialog box. What this does is override the normal call to
136
- # showModalDialog and opens a window instead. In order to use this new
137
- # window, you have to attach to it.
138
- def within_modal(&block)
139
- convert_modal_to_window = %Q{
140
- window.showModalDialog = function(sURL, vArguments, sFeatures) {
141
- window.dialogArguments = vArguments;
142
- modalWin = window.open(sURL, 'modal', sFeatures);
143
- return modalWin;
144
- }
145
- }
146
- browser.execute_script(convert_modal_to_window)
147
- yield if block_given?
148
- end
149
-
150
- alias_method :current_url, :url
151
- alias_method :page_url, :url
152
- alias_method :html, :markup
153
- alias_method :page_text, :text
154
- alias_method :page_title, :title
155
- alias_method :navigate_to, :visit
156
- alias_method :goto, :visit
157
- alias_method :save_screenshot, :screenshot
158
- alias_method :execute_script, :run_script
159
- alias_method :remove_cookies, :clear_cookies
160
- alias_method :refresh_page, :refresh
161
- alias_method :select_window, :within_window
162
- alias_method :attach_to, :within_window
163
- end
164
- end
1
+ module Symbiont
2
+ module Page
3
+ include Helpers
4
+
5
+ def view
6
+ no_url_is_provided if asserted_url.nil?
7
+ browser.goto(asserted_url)
8
+ self
9
+ end
10
+
11
+ def correct_url?
12
+ no_url_matches_is_provided if url_match.nil?
13
+ !(browser.url =~ url_match).nil?
14
+ end
15
+
16
+ def correct_title?
17
+ no_title_is_provided if asserted_title.nil?
18
+ !(browser.title.match(asserted_title)).nil?
19
+ end
20
+
21
+ def verified?
22
+ correct_url?
23
+ correct_title?
24
+ end
25
+
26
+ def asserted_url
27
+ self.class.asserted_url
28
+ end
29
+
30
+ def url_match
31
+ self.class.url_match
32
+ end
33
+
34
+ def asserted_title
35
+ self.class.asserted_title
36
+ end
37
+
38
+ def url
39
+ browser.url
40
+ end
41
+
42
+ def markup
43
+ browser.html
44
+ end
45
+
46
+ def text
47
+ browser.text
48
+ end
49
+
50
+ def title
51
+ browser.title
52
+ end
53
+
54
+ def visit(url)
55
+ browser.goto(url)
56
+ end
57
+
58
+ def screenshot(file)
59
+ browser.wd.save_screenshot(file)
60
+ end
61
+
62
+ def run_script(script, *args)
63
+ browser.execute_script(script, *args)
64
+ end
65
+
66
+ def get_cookie(name)
67
+ browser.cookies.to_a.each do |cookie|
68
+ return cookie[:value] if cookie[:name] == name
69
+ end
70
+ nil
71
+ end
72
+
73
+ def clear_cookies
74
+ browser.cookies.clear
75
+ end
76
+
77
+ def refresh
78
+ browser.refresh
79
+ end
80
+
81
+ # @return [String] the message contained in the alert message box
82
+ def will_alert
83
+ yield
84
+ value = nil
85
+ if browser.alert.exists?
86
+ value = browser.alert.text
87
+ browser.alert.ok
88
+ end
89
+ value
90
+ end
91
+
92
+ # @param response [Boolean] true to accept confirmation, false to cancel it
93
+ # @return [String] the message contained in the confirmation message box
94
+ def will_confirm(response)
95
+ yield
96
+ value = nil
97
+ if browser.alert.exists?
98
+ value = browser.alert.text
99
+ response ? browser.alert.ok : browser.alert.close
100
+ end
101
+ value
102
+ end
103
+
104
+ # @param response [String] the value to be used in the prompt
105
+ # @return [Hash] :message for the prompt message, :default_value for
106
+ # the value that the prompt had before the response was applied
107
+ def will_prompt(response)
108
+ cmd = "window.prompt = function(text, value) \
109
+ {window.__lastWatirPrompt = {message: text, default_value: value}; \
110
+ return '#{response}';}"
111
+ browser.wd.execute_script(cmd)
112
+ yield
113
+ result = browser.wd.execute_script('return window.__lastWatirPrompt')
114
+ result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
115
+ result
116
+ end
117
+
118
+ # Used to identify a web element or action on a web element as existing
119
+ # within an enclosing window object. The window can be referenced using
120
+ # either the title attribute of the window or a direct URL. The URL does
121
+ # not have to be the entire URL; it can just be a page name.
122
+ #
123
+ # @param locator [Hash] the :title or :url of the window
124
+ # @param block [Proc] any code that should be executed as an
125
+ # action on or within the window
126
+ def within_window(locator, &block)
127
+ identifier = { locator.keys.first => /#{Regexp.escape(locator.values.first)}/ }
128
+ browser.window(identifier).use(&block)
129
+ end
130
+
131
+ # Used to identify a web element as existing within an enclosing object
132
+ # like a modal dialog box. What this does is override the normal call to
133
+ # showModalDialog and opens a window instead. In order to use this new
134
+ # window, you have to attach to it.
135
+ def within_modal
136
+ convert_modal_to_window = %{
137
+ window.showModalDialog = function(sURL, vArguments, sFeatures) {
138
+ window.dialogArguments = vArguments;
139
+ modalWin = window.open(sURL, 'modal', sFeatures);
140
+ return modalWin;
141
+ }
142
+ }
143
+ browser.execute_script(convert_modal_to_window)
144
+ yield if block_given?
145
+ end
146
+
147
+ alias_method :current_url, :url
148
+ alias_method :page_url, :url
149
+ alias_method :html, :markup
150
+ alias_method :page_text, :text
151
+ alias_method :page_title, :title
152
+ alias_method :navigate_to, :visit
153
+ alias_method :goto, :visit
154
+ alias_method :save_screenshot, :screenshot
155
+ alias_method :execute_script, :run_script
156
+ alias_method :remove_cookies, :clear_cookies
157
+ alias_method :refresh_page, :refresh
158
+ alias_method :select_window, :within_window
159
+ alias_method :attach_to, :within_window
160
+ end
161
+ end
@@ -14,7 +14,7 @@ module Symbiont
14
14
  end
15
15
 
16
16
  def connected?
17
- not @client.nil?
17
+ !@client.nil?
18
18
  end
19
19
 
20
20
  def operations
@@ -47,7 +47,7 @@ module Symbiont
47
47
  operation = args.shift
48
48
  message = args.shift
49
49
  type = message.is_a?(String) ? :xml : :message
50
- call(operation, { type => message })
50
+ call(operation, type => message)
51
51
  end
52
52
 
53
53
  def call(operation, data)
@@ -58,21 +58,21 @@ module Symbiont
58
58
  def client_properties
59
59
  properties = { log: false, ssl_version: :SSLv3, ssl_verify_mode: :none }
60
60
  [
61
- :has_wsdl,
62
- :has_proxy,
63
- :has_basic_auth,
64
- :has_digest_auth,
65
- :has_encoding,
66
- :has_soap_header,
67
- :has_open_timeout,
68
- :has_read_timeout,
69
- :has_log_level,
70
- :has_ssl_version,
71
- :has_ssl_verification
61
+ :has_wsdl,
62
+ :has_proxy,
63
+ :has_basic_auth,
64
+ :has_digest_auth,
65
+ :has_encoding,
66
+ :has_soap_header,
67
+ :has_open_timeout,
68
+ :has_read_timeout,
69
+ :has_log_level,
70
+ :has_ssl_version,
71
+ :has_ssl_verification,
72
72
  ].each do |sym|
73
- properties = properties.merge(self.send sym) if self.respond_to? sym
73
+ properties = properties.merge(send sym) if self.respond_to? sym
74
74
  end
75
75
  properties
76
76
  end
77
77
  end
78
- end
78
+ end
@@ -1,72 +1,73 @@
1
- module Symbiont::SoapObject
2
- module SoapMethods
3
- def wsdl(url)
4
- define_method(:has_wsdl) do
5
- @wsdl ||= url
6
- { wsdl: @wsdl }
1
+ module Symbiont
2
+ module SoapObject
3
+ module SoapMethods
4
+ def wsdl(url)
5
+ define_method(:has_wsdl) do
6
+ @wsdl ||= url
7
+ { wsdl: @wsdl }
8
+ end
7
9
  end
8
- end
9
10
 
10
- def proxy(url)
11
- define_method(:has_proxy) do
12
- { proxy: url }
11
+ def proxy(url)
12
+ define_method(:has_proxy) do
13
+ { proxy: url }
14
+ end
13
15
  end
14
- end
15
16
 
16
- def basic_auth(*creds)
17
- define_method(:has_basic_auth) do
18
- { basic_auth: creds }
17
+ def basic_auth(*creds)
18
+ define_method(:has_basic_auth) do
19
+ { basic_auth: creds }
20
+ end
19
21
  end
20
- end
21
22
 
22
- def digest_auth(*creds)
23
- define_method(:has_digest_auth) do
24
- { digest_auth: creds }
23
+ def digest_auth(*creds)
24
+ define_method(:has_digest_auth) do
25
+ { digest_auth: creds }
26
+ end
25
27
  end
26
- end
27
28
 
28
- def soap_header(header)
29
- define_method(:has_soap_header) do
30
- { soap_header: header }
29
+ def soap_header(header)
30
+ define_method(:has_soap_header) do
31
+ { soap_header: header }
32
+ end
31
33
  end
32
- end
33
34
 
34
- def encoding(enc)
35
- define_method(:has_encoding) do
36
- { encoding: enc }
35
+ def encoding(enc)
36
+ define_method(:has_encoding) do
37
+ { encoding: enc }
38
+ end
37
39
  end
38
- end
39
40
 
40
- def open_timeout(timeout)
41
- define_method(:has_open_timeout) do
42
- { open_timeout: timeout }
41
+ def open_timeout(timeout)
42
+ define_method(:has_open_timeout) do
43
+ { open_timeout: timeout }
44
+ end
43
45
  end
44
- end
45
46
 
46
- def read_timeout(timeout)
47
- define_method(:has_read_timeout) do
48
- { read_timeout: timeout }
47
+ def read_timeout(timeout)
48
+ define_method(:has_read_timeout) do
49
+ { read_timeout: timeout }
50
+ end
49
51
  end
50
- end
51
52
 
52
- def log_level(level)
53
- define_method(:has_log_level) do
54
- { log: true, log_level: level, pretty_print_xml: true }
53
+ def log_level(level)
54
+ define_method(:has_log_level) do
55
+ { log: true, log_level: level, pretty_print_xml: true }
56
+ end
55
57
  end
56
- end
57
58
 
58
- def ssl_version(version)
59
- define_method(:has_ssl_version) do
60
- { ssl_version: version }
59
+ def ssl_version(version)
60
+ define_method(:has_ssl_version) do
61
+ { ssl_version: version }
62
+ end
61
63
  end
62
- end
63
64
 
64
- def ssl_verification(enable)
65
- if enable
65
+ def ssl_verification(enable)
66
+ return unless enable
66
67
  define_method(:has_ssl_verification) do
67
68
  { ssl_verify_mode: true }
68
69
  end
69
70
  end
70
71
  end
71
72
  end
72
- end
73
+ end
@@ -1,3 +1,3 @@
1
1
  module Symbiont
2
- VERSION = '0.11.0'
2
+ VERSION = '0.12.0'
3
3
  end
data/lib/symbiont.rb CHANGED
@@ -12,7 +12,6 @@ require 'symbiont/assertions'
12
12
  require 'symbiont/pages'
13
13
  require 'symbiont/elements'
14
14
  require 'symbiont/accessor'
15
- require 'symbiont/workflows'
16
15
  require 'symbiont/factory'
17
16
 
18
17
  require 'symbiont/data_reader'
@@ -26,25 +25,22 @@ module Symbiont
26
25
  def self.included(caller)
27
26
  caller.extend Symbiont::Assertion
28
27
  caller.extend Symbiont::Element
29
-
30
28
  caller.send :include, Symbiont::Page
31
29
  caller.send :include, Symbiont::Accessor
32
-
33
30
  caller.send :include, Symbiont::DataSetter
34
31
  caller.send :include, Symbiont::DataBuilder
35
-
36
32
  Symbiont.trace("#{caller.class} #{caller} has attached the Symbiont.")
37
33
  end
38
34
 
39
35
  def self.trace(message, level = 1)
40
36
  puts '*' * level + " #{message}" if ENV['SYMBIONT_TRACE'] == 'on'
41
37
  end
42
-
43
- def self.driver=(browser)
38
+
39
+ def self.browser=(browser)
44
40
  @browser = browser
45
41
  end
46
-
47
- def self.driver
42
+
43
+ def self.browser
48
44
  @browser
49
45
  end
50
46
 
@@ -52,48 +48,50 @@ module Symbiont
52
48
  attr_reader :browser
53
49
 
54
50
  # @param browser [Object] a tool driver instance
55
- def initialize(browser=nil)
51
+ def initialize(browser = nil)
56
52
  Symbiont.trace("Symbiont attached to browser:\n\t#{browser.inspect}")
57
-
58
- @browser = Symbiont.driver unless Symbiont.driver.nil?
59
- @browser = browser if Symbiont.driver.nil?
53
+
54
+ @browser = Symbiont.browser unless Symbiont.browser.nil?
55
+ @browser = browser if Symbiont.browser.nil?
60
56
 
61
57
  initialize_page if respond_to?(:initialize_page)
62
58
  initialize_activity if respond_to?(:initialize_activity)
63
59
  end
64
- end
65
60
 
66
- def attach(mod=Symbiont)
67
- include mod
61
+ def self.set_browser(app = :firefox)
62
+ @browser = Watir::Browser.new(app)
63
+ Symbiont.browser = @browser
64
+ end
68
65
  end
69
66
 
70
- def symbiont_browser(browser=:firefox)
71
- @browser = Watir::Browser.new browser
72
- Symbiont.driver = @browser
67
+ def attach(mod = Symbiont)
68
+ include mod
73
69
  end
74
70
 
75
- alias :symbiont_browser_for :symbiont_browser
76
-
77
71
  class Object
78
- def call_method_chain(method_chain, arg=nil)
72
+ def call_method_chain(method_chain, arg = nil)
79
73
  return self if method_chain.empty?
80
- method_chain.split('.').inject(self) { |o,m|
74
+ method_chain.split('.').inject(self) do |o, m|
81
75
  if arg.nil?
82
76
  o.send(m.intern)
83
77
  else
84
78
  o.send(m.intern, arg)
85
79
  end
86
- }
80
+ end
87
81
  end
88
82
  end
89
83
 
90
- class Watir::CheckBox
91
- alias_method :check, :set
92
- alias_method :uncheck, :clear
93
- alias_method :checked?, :set?
84
+ module Watir
85
+ class CheckBox
86
+ alias_method :check, :set
87
+ alias_method :uncheck, :clear
88
+ alias_method :checked?, :set?
89
+ end
94
90
  end
95
91
 
96
- class Watir::Radio
97
- alias_method :choose, :set
98
- alias_method :chosen?, :set?
92
+ module Watir
93
+ class Radio
94
+ alias_method :choose, :set
95
+ alias_method :chosen?, :set?
96
+ end
99
97
  end
data/symbiont.gemspec CHANGED
@@ -30,17 +30,20 @@ Gem::Specification.new do |spec|
30
30
  spec.bindir = 'exe'
31
31
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ['lib']
33
+ spec.requirements << 'Watir-WebDriver, Savon'
33
34
 
34
35
  spec.required_ruby_version = '>= 2.0'
35
36
  spec.required_rubygems_version = '>= 1.8.29'
36
37
 
37
- spec.add_development_dependency 'bundler', '~> 1.7'
38
+ spec.add_development_dependency 'bundler', '~> 1.10'
38
39
  spec.add_development_dependency 'rake', '~> 10.0'
39
- spec.add_development_dependency 'rspec', '~> 3.1'
40
+ spec.add_development_dependency 'rspec'
40
41
  spec.add_development_dependency 'pry'
42
+ spec.add_development_dependency 'simplecov'
43
+ spec.add_development_dependency 'rubocop'
41
44
 
42
- spec.add_runtime_dependency 'colorize', '~> 0.7'
43
- spec.add_runtime_dependency 'watir-webdriver', '~> 0.6'
45
+ spec.add_runtime_dependency 'colorize'
46
+ spec.add_runtime_dependency 'watir-webdriver'
44
47
  spec.add_runtime_dependency 'watir-dom-wait'
45
48
  spec.add_runtime_dependency 'watir-scroll'
46
49
  spec.add_runtime_dependency 'savon'