Skip to main content

Browser

The Test Evolve browser is available if you have configured test_types in config.yml to include browser or selected the test_type browser in Flare.

TestEvolve.browser

In Spark Ruby TestEvolve.browser is an instance of a Watir::Browser, which is a wrapper for Selenium webdriver. Comprehensive guides, docs, FAQs and examples are available from http://watir.com.

Driver

The underlying Selenium driver can be accessed in the following way.

TestEvolve.browser.driver

Comprehensive documentation is available from https://www.selenium.dev/documentation/webdriver.

TestEvolve.browser.goto('http://testevolve.com')
TestEvolve.browser.back
TestEvolve.browser.forward

Refresh

TestEvolve.browser.refresh

Elements

Locating Elements

Spark provides support for all valid html elements as methods on the browser object.

For example a div element can be located using browser.div and then providing an identifier for the element in the DOM. In cases where you do not want to specify the html element type you can simply use browser.element, but this is not recommended.

Some examples are listed below:

div(id: 'unique-identifier')

button('data-test': 'unique-identifier')

a(class: 'unique-identifier')

p(css: '.unique-identifier');

h2(xpath: '//h2['unique-identifier']');

Returns an instance of a subclass of Watir::Element

You can chain element definitions to be more specific with your locators:

div(id: 'unique-identifier').button('data-test': 'unique-identifier')

You can supply multiple identifiers for a single element in the following way:

button(id: 'unique-identifier', 'data-test': 'unique-identifier')

Click

element.click

Double Click

element.double_click

Send Keys

element.send_keys 'value'

Get Standard Attribute

Every standard attribute on an element is represented by a method on the Spark Element object.

element.href

Get Custom Attribute

element.attribute_value('title')

Input - Text

An input with type text should be defined in the following way:

TestEvolve.browser.text_field(id: "text-field-identifier")

Set Text

On a text input you can set the text of the input using set.

element.set 'value'

Clear Text

On a text input you can clear the text in the input using clear.

element.clear

Get Text

On a text input you can get the text in the input using value.

element.value

Input - Radio

An input with type radio should be defined in the following way:

TestEvolve.browser.radio(id: "option1")

Select an option

On radio input you can select the desired option using set.

element.set

Get Radio option status

You can check if a radio option is selected in the following way:

element.set?

This returns true or false depending on if the radio option is selected.

Input - Checkbox

An input with type checkbox should be defined in the following way:

TestEvolve.browser.checkbox(id: "option1")

Check a Checkbox

You can check a checkbox input using check.

element.check

Uncheck a Checkbox

You can uncheck a checkbox input using uncheck.

element.uncheck

Get Checkbox status

You can see if a checkbox is checked in the following way:

element.checked?

This returns true or false depending on if the checkbox is checked.

Select List

TestEvolve.browser.select(id: "select-list-identifier")

Select Option by value

On a Select List you can select a value in the following way:

element.select('option1')

Get Selected Option value

You can retrieve the value of the currently selected option using value:

element.value

Page Object

The Page Object model is commonly used in test automation frameworks because it reduces code duplication and improves test maintenance.

In Spark page object files are generally kept in features/support/pages.

The following is a basic page object template:

module Pages
def login_page
@login_page ||= LoginPage.new
end

class LoginPage < TestEvolve::Core::PageObject
element(:standard_button) { button(data_test: 'standard-button') }

def visit
goto 'https://testevolve.io/login'
end
end

An instance of the PageObject class can be referenced from any Step Definition file using login_page.

For example:

login_page.visit

An argument can be passed into the page object element definition at runtime in the following way:

  element(:standard_button) { |button_number| button(data_test: "button-#{button_number}") }

def click_standard_button
standard_button('one').click
end