Superbara

Superbara consists of two things:

  • Superbara CLI - Command Line Interface for devoloping and running tests with all batteries included and preconfigured
  • Superbara DSL - Domain Specific Language for writing tests

Install

gem install superbara

Getting Started

Start by opening up the superbara CLI shell:

superbara shell

This shell is handy for quickly testing something without creating a test file with superbara init.

alt text

Visiting

Type following in to the console:

visit 'example.com'

You can also specify full URL like https://www.exa.. or just path /about see visit.

Finding elements

find 'h1'
find 'a', text: 'More information'

Click

click 'a'

Language Reference

assert

assert asserts that the block is truthy at the given time. The first parameter is an optional failure message.

assert 'login missing' do
  has_text? 'Login'
end

Examples

Check that example.com still has the same heading.

visit 'example.com'

assert 'somebody changed the text!'
  h1 = find 'h1'
  h1.text == 'Example Domain'
end

Asserts can also be written without the message.

assert do
  has_text? "Something"
end

Negative asserts can also be given.

assert do
  has_no_text? "Login"
end

# or
assert do
  !has_text? "Login"
end

Related

find

To get a single element use find

title = find 'h1'

For multiple results use all

links = all 'h1'

See (results)[./results.md] for complete list of methods available for the returned element or elements.

Advanced finding

title = find 'h1', text: "Example Domain"

wait

wait checks every 0.1s for the block to return true or "anything but false" until max_seconds has elapsed. Quits the script with an error if the wait condition is not satisfied.

wait max_seconds do
  # true or anything but false
end

Examples

Wait maximum of 3 seconds for the text 'Example Domain' to appear on the page.

visit 'example.com'

wait 3 do
  has_text? 'Example Domain'
end

Wait up to 3.3 seconds for a <div id='login'> to appear and assign it to a variable for clicking.

login = wait 3.3 do
  find 'div#login'
end

login.click

Tests

has_text?

Checks if the text is found on the screen.

assert do
  has_text? "Welcome"
end

Examples

if has_text? "Logged in"
  click_link "Log out"

  wait 3 do
    has_text? "You have logged out"
  end
else
  click_link "Next"
end

Dialogs

Alert

Confirm

Prompt