Other Steps

Alerts

import aloe_webdriver

Validate the behaviour of popup alerts.

Step I should see an alert with text “([^”]*)”

Assert an alert is showing with the given text.

Step I should not see an alert

Assert there is no alert.

Step I accept the alert

Accept the alert.

Step I dismiss the alert

Dismiss the alert.

Tooltips

import aloe_webdriver
Step I should see an element with tooltip “([^”]*)”

Assert an element with the given tooltip (title) is visible.

N.B. tooltip may not be visible.

Step I should not see an element with tooltip “([^”]*)”

Assert an element with the given tooltip (title) is not visible.

Step I (?:click|press) the element with tooltip “([^”]*)”

Click on a HTML element with a given tooltip.

This is very useful if you’re clicking on icon buttons, etc.

Checks based on HTML id

import aloe_webdriver

Using the HTML id is generally considered bad BDD, but sometimes it is the only way to unambiguously refer to an element. It is strongly recommended to find a more behavioral mechanism to describe your test. See Writing good BDD steps.

Step The element with id of “([^”]*)” contains “([^”]*)”$

Assert provided content is contained within an element found by id.

Step The element with id of “([^”]*)” does not contain “([^”]*)”$

Assert provided content is not contained within an element found by id.

Step I should see an element with id of “([^”]*)”$

Assert an element with the given id is visible.

Step I should see an element with id of “([^”]*)” within (d+) seconds?$

Assert an element with the given id is visible within n seconds.

Step I should not see an element with id of “([^”]*)”$

Assert an element with the given id is not visible.

Step I submit the form with id “([^”]*)”

Submit the form with given id (used to disambiguate between multiple forms).

Focus

Step Element with id “([^”]*)” should be focused

Assert the element is focused.

Step Element with id “([^”]*)” should not be focused

Assert the element is not focused.

Frames

Use these steps to switch frames if you need to work in a different frame or iframe. It is recommended you wrap these steps up in a more behavioural description. See Writing good BDD steps.

Step I switch back to the main view

Swap Selenium’s context back to the main window.

CSS Selectors

import aloe_webdriver.css

Steps for selecting elements using CSS selectors.

Like with steps based on HTML id, these steps should be used cautiously to avoid creating tests that do not describe the behaviours of your application. See Writing good BDD steps.

Note

Be aware these steps require jQuery. If jQuery is not present it will be added (v1.12).

Step I check $(“(.*?)”)$

Check the checkbox matching the CSS selector.

Step There should be an element matching $(“(.*?)”)$

Assert an element exists matching the given selector.

Step There should not be an element matching $(“(.*?)”)$

Assert an element does not exist matching the given selector.

Step I click $(“(.*?)”)$

Click the element matching the CSS selector.

Step There should be exactly (d+) elements matching $(“(.*?)”)$

Assert n elements exist matching the given selector.

Step I fill in $(“(.*?)”) with “(.*?)”$

Fill in the form element matching the CSS selector.

Step I follow the link $(“(.*?)”)$

Navigate to the href of the element matching the CSS selector.

N.B. this does not click the link, but changes the browser’s URL.

Step $(“(.*?)”) should be selected$

Assert the option matching the CSS selector is selected.

Step I select $(“(.*?)”)$

Select the option matching the CSS selector.

Step I submit $(“(.*?)”)

Submit the form matching the CSS selector.

Step There should be an element matching $(“(.*?)”) within (d+) seconds?$

Assert an element exists matching the given selector within the given time period.

Screenshots

import aloe_webdriver.screenshot_failed

Hooks to save screenshots and HTML source of the pages when tests fail.

Assumes a browser instance is stored in world.browser.

Whenever a step fails, the screen shot and the HTML source of the page displayed in the browser are saved to the current directory. The file names include the feature file name, scenario number and name and, if applicable, the example number.

Consider the following feature:

# features/account.feature
Feature: Account management

    Scenario: Log in
        Given I open the site
        And I enter username and password
        And I press "Log in"
        Then I should see "Logged in"

If there will be no “Logged in” text when expected, screenshot and the page source will be saved to, respectively:

failed_features_account_feature_1_Log_in.png
failed_features_account_feature_1_Log_in.html

To change the directory where the screenshots are saved, override the constant DIRECTORY as follows:

from aloe_webdriver import screenshot_failed

screenshot_failed.DIRECTORY = '/alternative/directory'

Note that the given directory should already exist.