Module: Kookaburra

Defined in:
lib/kookaburra.rb,
lib/kookaburra/test_data.rb,
lib/kookaburra/ui_driver.rb,
lib/kookaburra/api_driver.rb,
lib/kookaburra/given_driver.rb,
lib/kookaburra/ui_driver/ui_component.rb,
lib/kookaburra/ui_driver/mixins/has_browser.rb,
lib/kookaburra/ui_driver/mixins/has_strategies.rb,
lib/kookaburra/ui_driver/mixins/has_ui_component.rb,
lib/kookaburra/ui_driver/mixins/has_subcomponents.rb

Overview

Kookaburra is a framework for implementing the Window Driver pattern in order to keep acceptance tests maintainable.

For RSpec integration tests, just add the following to ‘spec/support/kookaburra.rb`:

RSpec.configure do |c|
  c.include(Kookaburra, :type => :request)
end

That will make #given, #api and #ui entry-points available to your examples, e.g.:

describe "Widget Management" do
  describe "viewing a list of widgets" do
    example "when there are no widgets" do
      given.there_is_a_user(:bob)
      given.user_has_no_widgets(:bob)

      ui.(:bob)
      ui.navigate_to(:list_of_widgets)

      ui.list_of_widgets.should be_visible
      ui.list_of_widgets.should be_empty
    end
  end
end

For Cucumber, add the following to ‘features/support/kookaburra_setup.rb`:

Kookaburra.adapter = Capybara
World(Kookaburra)

Before do
  kookaburra_reset!
end

After doing to, the #api, #given and #ui methods will be available in your Cucumber step definitions.

(Obviously, the specific methods on #given and #ui are something that will be unique to your application’s domain.)

1

martinfowler.com/eaaDev/WindowDriver.html

Defined Under Namespace

Classes: APIDriver, GivenDriver, TestData, UIDriver

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.adapterObject

Provides the default adapter for the Kookaburra library. In most cases, this will probably be the ‘Capybara` class:

Kookaburra.adapter = Capybara

We allow this to be passed in, so that we can avoid a hard-coded dependency on Capybara in this gem.



59
60
61
# File 'lib/kookaburra.rb', line 59

def adapter
  @adapter
end

.api_driverObject

The API Driver that will be used by Kookaburra, typically a subclass of Kookaburra::APIDriver containing the testing DSL for your app. The default is an instance of Kookaburra::APIDriver.



64
65
66
# File 'lib/kookaburra.rb', line 64

def api_driver
  @api_driver
end

.given_driverObject

The Given Driver that will be used by Kookaburra, typically a subclass of Kookaburra::GivenDriver containing the testing DSL for your app. The default is an instance of Kookaburra::GivenDriver.



73
74
75
# File 'lib/kookaburra.rb', line 73

def given_driver
  @given_driver
end

.ui_driverObject

The UI Driver that will be used by Kookaburra, typically a subclass of Kookaburra::UIDriver containing the testing DSL for your app. The default is an instance of Kookaburra::UIDriver.



82
83
84
# File 'lib/kookaburra.rb', line 82

def ui_driver
  @ui_driver
end

Instance Attribute Details

#kookaburra_adapterObject

Whatever was set in ‘Kookaburra.adapter can be overriden in the mixin context. For example, in an RSpec example:

describe "Something" do
  it "does something" do
    self.kookaburra_adapter = CapybaraLikeThing
    ...
  end
end


103
104
105
# File 'lib/kookaburra.rb', line 103

def kookaburra_adapter
  @kookaburra_adapter
end

Class Method Details

.test_data_setup(&blk) ⇒ Object



88
89
90
# File 'lib/kookaburra.rb', line 88

def test_data_setup(&blk)
  Kookaburra::TestData.class_eval(&blk)
end

Instance Method Details

#apiObject

Returns a configured instance of the ‘Kookaburra::APIDriver`



110
111
112
113
114
# File 'lib/kookaburra.rb', line 110

def api
  kookaburra_drivers[:api] ||= Kookaburra.api_driver.new(
    :app => kookaburra_adapter.app,
    :test_data => kookaburra_test_data)
end

#givenObject

Returns a configured instance of the ‘Kookaburra::GivenDriver`



117
118
119
120
# File 'lib/kookaburra.rb', line 117

def given
  kookaburra_drivers[:given] ||= \
    Kookaburra.given_driver.new(:api_driver => api, :test_data => kookaburra_test_data)
end

#kookaburra_reset!Object

This method causes new instances of all the Kookaburra drivers to be created the next time they are used, and, in particular, resets the state of any test data that is shared between the various drivers. This is necessary when Kookaburra is mixed in to Cucumber’s World, because World does not get a new instance for each scenario. Instead, just be sure to call this method from a ‘Before` block in your cucumber setup, i.e.:

Before do
  kookaburra_reset!
end


139
140
141
# File 'lib/kookaburra.rb', line 139

def kookaburra_reset!
  @kookaburra_drivers = {}
end

#uiObject

Returns a configured instance of the ‘Kookaburra::UIDriver`



123
124
125
126
127
# File 'lib/kookaburra.rb', line 123

def ui
  kookaburra_drivers[:ui] ||= Kookaburra.ui_driver.new(
    :browser => kookaburra_adapter.current_session,
    :test_data => kookaburra_test_data)
end