Module: Testable
- Defined in:
- lib/testable.rb,
lib/testable/page.rb,
lib/testable/ready.rb,
lib/testable/errors.rb,
lib/testable/logger.rb,
lib/testable/context.rb,
lib/testable/element.rb,
lib/testable/locator.rb,
lib/testable/version.rb,
lib/testable/attribute.rb,
lib/testable/situation.rb,
lib/testable/deprecator.rb,
lib/testable/capybara/dsl.rb,
lib/testable/capybara/node.rb,
lib/testable/capybara/page.rb,
lib/testable/extensions/data_setter.rb
Defined Under Namespace
Modules: Context, DSL, DataSetter, Element, Errors, Pages, Ready, Situation Classes: Deprecator, Logger, Node, Page
Constant Summary collapse
- NATIVE_QUALIFIERS =
%i[visible].freeze
- VERSION =
"0.8.0".freeze
Class Attribute Summary collapse
-
.browser ⇒ Object
This accessor is needed so that Testable itself can provide a browser reference to indicate connection to WebDriver.
Instance Attribute Summary collapse
-
#browser ⇒ Object
This accessor is needed so that internal API calls, like ‘markup` or `text`, have access to the browser instance.
Class Method Summary collapse
- .api ⇒ Object
-
.configure {|_self| ... } ⇒ Object
Provides a means to allow a configure block on Testable.
- .dependencies ⇒ Object
-
.driver_timeout=(value) ⇒ Object
Watir provides a default timeout of 30 seconds.
- .elements ⇒ Object
- .elements? ⇒ Boolean
- .gem_version(name) ⇒ Object
- .included(caller) ⇒ Object
-
.log_level ⇒ Object
To query what level is being logged, do this:.
-
.log_level=(value) ⇒ Object
To enable logging, do this:.
-
.log_path=(logdev) ⇒ Object
The writer method allows you to configure where you want the output of the Testable logs to go, with the default being standard output.
-
.logger ⇒ Object
The Testable logger object.
- .quit_browser ⇒ Object
- .recognizes?(method) ⇒ Boolean
- .selenium_api ⇒ Object
- .set_browser(app = :chrome, *args) ⇒ Object (also: start_browser)
- .version ⇒ Object
- .watir_api ⇒ Object
- .wire_level_logging ⇒ Object
- .wire_level_logging=(value) ⇒ Object
-
.wire_path=(logdev) ⇒ Object
The wire logger provides logging from Watir, which is very similar to the logging provided by Selenium::WebDriver::Logger.
Instance Method Summary collapse
Class Attribute Details
.browser ⇒ Object
This accessor is needed so that Testable itself can provide a browser reference to indicate connection to WebDriver. This is a class-level access to the browser.
158 159 160 |
# File 'lib/testable.rb', line 158 def browser @browser end |
Instance Attribute Details
#browser ⇒ Object
This accessor is needed so that internal API calls, like ‘markup` or `text`, have access to the browser instance. This is also necessary in order for element handling to be called appropriately on the a valid browser instance. This is an instance-level access to whatever browser Testable is using.
43 44 45 |
# File 'lib/testable.rb', line 43 def browser @browser end |
Class Method Details
.api ⇒ Object
171 172 173 |
# File 'lib/testable.rb', line 171 def api methods - Object.public_methods end |
.configure {|_self| ... } ⇒ Object
Provides a means to allow a configure block on Testable. This allows you to setup Testable, as such:
Testable.configure do |config|
config.driver_timeout = 5
config.wire_level_logging = :info
config.log_level = :debug
end
54 55 56 |
# File 'lib/testable.rb', line 54 def configure yield self end |
.dependencies ⇒ Object
21 22 23 24 |
# File 'lib/testable/version.rb', line 21 def dependencies Gem.loaded_specs.values.map { |spec| "#{spec.name} #{spec.version}\n" } .uniq.sort.join(",").split(",") end |
.driver_timeout=(value) ⇒ Object
66 67 68 |
# File 'lib/testable.rb', line 66 def driver_timeout=(value) Watir.default_timeout = value end |
.elements ⇒ Object
16 17 18 |
# File 'lib/testable/element.rb', line 16 def elements @elements ||= Watir::Container.instance_methods unless @elements end |
.elements? ⇒ Boolean
8 9 10 |
# File 'lib/testable/element.rb', line 8 def elements? @elements end |
.gem_version(name) ⇒ Object
15 16 17 18 19 |
# File 'lib/testable/version.rb', line 15 def gem_version(name) Gem.loaded_specs[name].version rescue NoMethodError puts "No gem loaded for #{name}." end |
.included(caller) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/testable.rb', line 22 def self.included(caller) caller.extend Testable::Pages::Attribute caller.extend Testable::Pages::Element caller.__send__ :include, Testable::Ready caller.__send__ :include, Testable::Pages caller.__send__ :include, Testable::Element::Locator caller.__send__ :include, Testable::DataSetter end |
.log_level ⇒ Object
To query what level is being logged, do this:
Testable.log_level
The logging level will be UNKNOWN by default.
102 103 104 |
# File 'lib/testable.rb', line 102 def log_level %i[DEBUG INFO WARN ERROR FATAL UNKNOWN][logger.level] end |
.log_level=(value) ⇒ Object
93 94 95 |
# File 'lib/testable.rb', line 93 def log_level=(value) logger.level = value end |
.log_path=(logdev) ⇒ Object
The writer method allows you to configure where you want the output of the Testable logs to go, with the default being standard output. Here is how you could change this to a specific file:
Testable.log_path = 'testable.log'
111 112 113 |
# File 'lib/testable.rb', line 111 def log_path=(logdev) logger.reopen(logdev) end |
.logger ⇒ Object
The Testable logger object. To log messages:
Testable.logger.info('Some information.')
Testable.logger.debug('Some diagnostics')
To alter or check the current logging level, you can call ‘.log_level=` or `.log_level`. By default the logger will output all messages to the standard output ($stdout) but it can be altered to log to a file or to another IO location by calling `.log_path=`.
79 80 81 |
# File 'lib/testable.rb', line 79 def logger @logger ||= Testable::Logger.new.create end |
.quit_browser ⇒ Object
167 168 169 |
# File 'lib/testable.rb', line 167 def quit_browser @browser.quit end |
.recognizes?(method) ⇒ Boolean
12 13 14 |
# File 'lib/testable/element.rb', line 12 def recognizes?(method) @elements.include? method.to_sym end |
.selenium_api ⇒ Object
151 152 153 |
# File 'lib/testable.rb', line 151 def selenium_api browser.driver.methods - Object.public_methods end |
.set_browser(app = :chrome, *args) ⇒ Object Also known as: start_browser
160 161 162 163 |
# File 'lib/testable.rb', line 160 def set_browser(app = :chrome, *args) @browser = Watir::Browser.new(app, *args) Testable.browser = @browser end |
.version ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/testable/version.rb', line 6 def version """ Testable v#{Testable::VERSION} watir: #{gem_version('watir')} selenium-webdriver: #{gem_version('selenium-webdriver')} capybara: #{gem_version('capybara')} """ end |
.watir_api ⇒ Object
146 147 148 149 |
# File 'lib/testable.rb', line 146 def watir_api browser.methods - Object.public_methods - Watir::Container.instance_methods end |
.wire_level_logging ⇒ Object
142 143 144 |
# File 'lib/testable.rb', line 142 def wire_level_logging %i[DEBUG INFO WARN ERROR FATAL UNKNOWN][Watir.logger.level] end |
.wire_level_logging=(value) ⇒ Object
138 139 140 |
# File 'lib/testable.rb', line 138 def wire_level_logging=(value) Watir.logger.level = value end |
.wire_path=(logdev) ⇒ Object
The wire logger provides logging from Watir, which is very similar to the logging provided by Selenium::WebDriver::Logger. The default level is set to warn. This means you will see any deprecation notices as well as any warning messages. To see details on each element interaction the level can be set to info. To see details on what Watir is doing when it takes a selector hash and converts it into XPath, the level can be set to debug. If you want to ignore specific warnings that are appearing during test execution:
Watir.logger.ignore :warning_name
If you want to ignore all deprecation warnings in your tests:
Watir.logger.ignore :deprecations
To have the wire logger generate output to a file:
Watir.logger.output = “wire.log”
134 135 136 |
# File 'lib/testable.rb', line 134 def wire_path=(logdev) Watir.logger.reopen(logdev) end |
Instance Method Details
#initialize(browser = nil, &block) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/testable.rb', line 31 def initialize(browser = nil, &block) @browser = Testable.browser unless Testable.browser.nil? @browser = browser if Testable.browser.nil? begin_with if respond_to?(:begin_with) instance_eval(&block) if block end |