lib/bauxite/core/context.rb in bauxite-0.6.9 vs lib/bauxite/core/context.rb in bauxite-0.6.10
- old
+ new
@@ -105,13 +105,10 @@
# whose names are only numbers are reserved for Bauxite and should not be
# used as part of a functional test. The obvious exception is when trying
# to change the test behavior by changing the built-in variables.
#
class Context
- # Test engine driver instance (Selenium WebDriver).
- attr_reader :driver
-
# Logger instance.
attr_reader :logger
# Test options.
attr_reader :options
@@ -176,16 +173,10 @@
# ctx.start(lines)
# # => navigates to www.ruby-lang.org, types ljust in the search box
# # and clicks the "Search" button.
#
def start(actions = [])
- begin
- _load_driver
- rescue StandardError => e
- print_error(e)
- raise
- end
return unless actions.size > 0
begin
actions.each do |action|
begin
exec_action(action)
@@ -205,12 +196,12 @@
# For example:
# ctx.reset_driver
# => closes the browser and opens a new one
#
def reset_driver
- @driver.quit
- _load_driver
+ @driver.quit if @driver
+ @driver = nil
end
# Stops the test engine.
#
# Calling this method at the end of the test is mandatory if #start was
@@ -232,11 +223,11 @@
@logger.finalize(self)
rescue StandardError => e
print_error(e)
raise
ensure
- @driver.quit
+ @driver.quit if @driver
end
end
# Finds an element by +selector+.
#
@@ -262,10 +253,16 @@
with_timeout Selenium::WebDriver::Error::NoSuchElementError do
Selector.new(self, @variables['__SELECTOR__']).find(selector, &block)
end
end
+ # Test engine driver instance (Selenium WebDriver).
+ def driver
+ _load_driver unless @driver
+ @driver
+ end
+
# Breaks into the debug console.
#
# For example:
# ctx.debug
# # => this breaks into the debug console
@@ -404,14 +401,14 @@
# end
# end
#
def with_driver_timeout(timeout)
current = @driver_timeout
- @driver.manage.timeouts.implicit_wait = timeout
+ driver.manage.timeouts.implicit_wait = timeout
yield
ensure
@driver_timeout = current
- @driver.manage.timeouts.implicit_wait = current
+ driver.manage.timeouts.implicit_wait = current
end
# Prompts the user to press ENTER before resuming execution.
#
# For example:
\ No newline at end of file