class BasicContext implements Context (View source)

BasicContext

Context used to define generic steps like following anchors or pressing buttons. Handles timeouts. Handles redirections. Handles AJAX enabled links, buttons and forms - jQuery is assumed.

Traits

Represents a behat context which is aware of a main {SilverStripeContext} context.

Helpers for working with steps

Properties

protected SilverStripeContext $mainContext from  MainContextAwareTrait
protected string $dateFormat

Date format in date() syntax

protected string $timeFormat

Time format in date() syntax

protected string $datetimeFormat

Date/time format in date() syntax

Methods

public
getMainContext()

Get the main context

public
$this
setMainContext(SilverStripeContext $mainContext)

No description

public
detectMainContext(BeforeScenarioScope $scope)

Helper method to detect the main context

protected
ScenarioInterface
getStepScenario(FeatureNode $feature, NodeInterface $step)

Get scenario from step in a feature node See https://github.com/Behat/Behat/issues/653

protected
mixed
retryThrowable(callable $callback, int $timeout = 3)

Retry until no exceptions are thrown, or until $timeout seconds are reached.

protected
bool
stepHasTag(StepScope $event, string $tag)

Check if a step has a given tag

public
Session
getSession(string $name = null)

Get Mink session from MinkContext

public
appendErrorHandlerBeforeStep(AfterStepScope $event)

No description

public
readErrorHandlerAfterStep(AfterStepScope $event)

No description

public
handleAjaxBeforeStep(BeforeStepScope $event)

Hook into jQuery ajaxStart, ajaxSuccess and ajaxComplete events.

public
handleAjaxAfterStep(AfterStepScope $event)

Wait for the __ajaxStatus()to return anything but 'waiting'.

public
handleAjaxTimeout()

No description

public
takeScreenshotAfterFailedStep(AfterStepScope $event)

Take screenshot when step fails.

public
closeModalDialog(AfterScenarioScope $event)

Close modal dialog if test scenario fails on CMS page

public
cleanAssetsAfterScenario(AfterScenarioScope $event)

Delete any created files and folders from assets directory

public
takeScreenshot(StepScope $event)

Take a nice screenshot

public
stepPageCantBeFound()

No description

public
stepIWaitFor(float $secs)

No description

protected
NodeElement|null
findNamedButton(string $title)

Find visible button with the given text.

public
iShouldSeeAButton(string $negative, string $text)

Example: I should see a "Submit" button Example: I should not see a "Delete" button

public
stepIPressTheButton(string $text)

No description

public
stepIPressTheButtonConfirmingTheDialog(string $button)

Needs to be in single command to avoid "unexpected alert open" errors in Selenium.

public
stepIPressTheButtonDismissingTheDialog(string $button)

Needs to be in single command to avoid "unexpected alert open" errors in Selenium.

public
iClickInTheElement(string $clickType, string $text, string $selector)

No description

public
iClickInTheElementConfirmingTheDialog(string $clickType, string $text, string $selector)

Needs to be in single command to avoid "unexpected alert open" errors in Selenium.

public
iClickInTheElementDismissingTheDialog(string $clickType, string $text, string $selector)

Needs to be in single command to avoid "unexpected alert open" errors in Selenium.

public
iSeeTheDialogText(string $expected)

No description

public
iTypeIntoTheDialog(string $data)

No description

public
iConfirmTheDialog()

No description

public
iDismissTheDialog()

No description

protected
Session
getWebDriverSession()

Get Selenium webdriver session.

public
Given
iAttachTheFileTo(string $field, string $path)

No description

public
iSelectFromInputGroup(string $value, string $labelText)

Select an individual input from within a group, matched by the top-most label.

public
iPutABreakpoint()

Pauses the scenario until the user presses a key. Useful when debugging a scenario.

public
false|string
castRelativeToAbsoluteTime(string $prefix, string $val)

Transforms relative time statements compatible with strtotime().

public
false|string
castRelativeToAbsoluteDatetime(string $prefix, string $val)

Transforms relative date and time statements compatible with strtotime().

public
false|string
castRelativeToAbsoluteDate(string $prefix, string $val)

Transforms relative date statements compatible with strtotime().

public
getDateFormat()

No description

public
setDateFormat($format)

No description

public
getTimeFormat()

No description

public
setTimeFormat($format)

No description

public
getDatetimeFormat()

No description

public
setDatetimeFormat($format)

No description

public
stepFieldShouldBeDisabled(string $name, string $type, string $negate)

Checks that field with specified in|name|label|value is disabled.

public
stepFieldShouldBeEnabled(string $field)

Checks that checkbox with specified in|name|label|value is enabled.

public
iFollowInTheRegion(string $link, string $region)

Clicks a link in a specific region (an element identified by a CSS selector, a "data-title" attribute, or a named region mapped to a CSS selector via Behat configuration).

public
iFillinTheRegion(string $field, string $value, string $region)

Fills in a field in a specfic region similar to (iFollowInTheRegion or iSeeTextInRegion)

public
iSeeTextInRegion(string $negate, string $text, string $region)

Asserts text in a specific region (an element identified by a CSS selector, a "data-title" attribute, or a named region mapped to a CSS selector via Behat configuration).

public
iSelectTheRadioButton(string $radioLabel)

Selects the specified radio button

public
theTableShouldContain(string $selector, string $text)

No description

public
theTableShouldNotContain(string $selector, string $text)

No description

public
iClickOnInTheTable(string $text, string $selector)

No description

protected
NodeElement
getTable(string $selector)

Finds the first visible table by various factors:

  • table[id]
  • table[title]
  • table *[class=title]
  • fieldset[data-name] table
  • table caption

public
theTextBeforeAfter(string $textBefore, string $order, string $textAfter, string $element)

Checks the order of two texts.

public
iWaitXUntilISee(int $wait, string $selector)

Wait until a certain amount of seconds till I see an element identified by a CSS selector.

public
iWaitUntilISee(string $selector)

Wait until a particular element is visible, using a CSS selector. Useful for content loaded via AJAX, or only populated after JS execution.

public
iWaitUntilISeeText(string $text)

Wait until a particular string is found on the page. Useful for content loaded via AJAX, or only populated after JS execution.

public
iScrollToBottom()

No description

public
iScrollToTop()

No description

public
iScrollToField(string $locator, string $type)

Scroll to a certain element by label.

public
iScrollToElement(string $locator)

Scroll to a certain element by CSS selector.

public
bool
spin(callable $lambda, int $wait = 60)

Continuously poll the dom until callback returns true, code copied from (@link http://docs.behat.org/cookbook/using_spin_functions.html) If not found within a given wait period, timeout and throw error

protected
logException(Exception $exception)

We have to catch exceptions and log somehow else otherwise behat falls over

Details

SilverStripeContext getMainContext()

Get the main context

Return Value

SilverStripeContext

$this setMainContext(SilverStripeContext $mainContext)

No description

Parameters

SilverStripeContext $mainContext

Return Value

$this

detectMainContext(BeforeScenarioScope $scope)

Helper method to detect the main context

Parameters

BeforeScenarioScope $scope

protected ScenarioInterface getStepScenario(FeatureNode $feature, NodeInterface $step)

Get scenario from step in a feature node See https://github.com/Behat/Behat/issues/653

Parameters

FeatureNode $feature
NodeInterface $step

Return Value

ScenarioInterface

protected mixed retryThrowable(callable $callback, int $timeout = 3)

Retry until no exceptions are thrown, or until $timeout seconds are reached.

If timeout reached, re-throws the first exception.

Parameters

callable $callback
int $timeout

Return Value

mixed

Exceptions

Exception

protected bool stepHasTag(StepScope $event, string $tag)

Check if a step has a given tag

Parameters

StepScope $event
string $tag

Return Value

bool

Session getSession(string $name = null)

Get Mink session from MinkContext

Parameters

string $name

Return Value

Session

appendErrorHandlerBeforeStep(AfterStepScope $event)

No description

Parameters

AfterStepScope $event

readErrorHandlerAfterStep(AfterStepScope $event)

No description

Parameters

AfterStepScope $event

handleAjaxBeforeStep(BeforeStepScope $event)

Hook into jQuery ajaxStart, ajaxSuccess and ajaxComplete events.

Prepare __ajaxStatus() functions and attach them to these handlers. Event handlers are removed after one run.

Parameters

BeforeStepScope $event

handleAjaxAfterStep(AfterStepScope $event)

Wait for the __ajaxStatus()to return anything but 'waiting'.

Don't wait longer than 5 seconds.

Don't unregister handler if we're dealing with modal windows

Parameters

AfterStepScope $event

handleAjaxTimeout()

No description

takeScreenshotAfterFailedStep(AfterStepScope $event)

Take screenshot when step fails.

Works only with Selenium2Driver.

Parameters

AfterStepScope $event

closeModalDialog(AfterScenarioScope $event)

Close modal dialog if test scenario fails on CMS page

Parameters

AfterScenarioScope $event

cleanAssetsAfterScenario(AfterScenarioScope $event)

Delete any created files and folders from assets directory

Parameters

AfterScenarioScope $event

takeScreenshot(StepScope $event)

Take a nice screenshot

Parameters

StepScope $event

stepPageCantBeFound()

No description

stepIWaitFor(float $secs)

No description

Parameters

float $secs

protected NodeElement|null findNamedButton(string $title)

Find visible button with the given text.

Supports data-text-alternate property.

Parameters

string $title

Return Value

NodeElement|null

iShouldSeeAButton(string $negative, string $text)

Example: I should see a "Submit" button Example: I should not see a "Delete" button

Parameters

string $negative
string $text

stepIPressTheButton(string $text)

No description

Parameters

string $text

stepIPressTheButtonConfirmingTheDialog(string $button)

Needs to be in single command to avoid "unexpected alert open" errors in Selenium.

Example1: I press the "Remove current combo" button, confirming the dialog Example2: I follow the "Remove current combo" link, confirming the dialog

Parameters

string $button

stepIPressTheButtonDismissingTheDialog(string $button)

Needs to be in single command to avoid "unexpected alert open" errors in Selenium.

Example: I follow the "Remove current combo" link, dismissing the dialog

Parameters

string $button

iClickInTheElement(string $clickType, string $text, string $selector)

No description

Parameters

string $clickType
string $text
string $selector

iClickInTheElementConfirmingTheDialog(string $clickType, string $text, string $selector)

Needs to be in single command to avoid "unexpected alert open" errors in Selenium.

Example: I click "Delete" in the ".actions" element, confirming the dialog

Parameters

string $clickType
string $text
string $selector

iClickInTheElementDismissingTheDialog(string $clickType, string $text, string $selector)

Needs to be in single command to avoid "unexpected alert open" errors in Selenium.

Example: I click "Delete" in the ".actions" element, dismissing the dialog

Parameters

string $clickType
string $text
string $selector

iSeeTheDialogText(string $expected)

No description

Parameters

string $expected

iTypeIntoTheDialog(string $data)

No description

Parameters

string $data

iConfirmTheDialog()

No description

iDismissTheDialog()

No description

protected Session getWebDriverSession()

Get Selenium webdriver session.

Note: Will fail if current driver isn't Selenium2Driver

Return Value

Session

Given iAttachTheFileTo(string $field, string $path)

No description

Parameters

string $field
string $path

Return Value

Given

iSelectFromInputGroup(string $value, string $labelText)

Select an individual input from within a group, matched by the top-most label.

Parameters

string $value
string $labelText

iPutABreakpoint()

Pauses the scenario until the user presses a key. Useful when debugging a scenario.

false|string castRelativeToAbsoluteTime(string $prefix, string $val)

Transforms relative time statements compatible with strtotime().

Example: "time of 1 hour ago" might return "22:00:00" if its currently "23:00:00". Customize through setTimeFormat().

Parameters

string $prefix
string $val

Return Value

false|string

false|string castRelativeToAbsoluteDatetime(string $prefix, string $val)

Transforms relative date and time statements compatible with strtotime().

Example: "datetime of 2 days ago" might return "2013-10-10 22:00:00" if its currently the 12th of October 2013. Customize through setDatetimeFormat().

Parameters

string $prefix
string $val

Return Value

false|string

false|string castRelativeToAbsoluteDate(string $prefix, string $val)

Transforms relative date statements compatible with strtotime().

Example: "date 2 days ago" might return "2013-10-10" if its currently the 12th of October 2013. Customize through setDateFormat().

Parameters

string $prefix
string $val

Return Value

false|string

getDateFormat()

No description

setDateFormat($format)

No description

Parameters

$format

getTimeFormat()

No description

setTimeFormat($format)

No description

Parameters

$format

getDatetimeFormat()

No description

setDatetimeFormat($format)

No description

Parameters

$format

stepFieldShouldBeDisabled(string $name, string $type, string $negate)

Checks that field with specified in|name|label|value is disabled.

Example: Then the field "Email" should be disabled Example: Then the "Email" field should be disabled

Parameters

string $name
string $type
string $negate

stepFieldShouldBeEnabled(string $field)

Checks that checkbox with specified in|name|label|value is enabled.

Example: Then the field "Email" should be enabled Example: Then the "Email" field should be enabled

Parameters

string $field

iFollowInTheRegion(string $link, string $region)

Clicks a link in a specific region (an element identified by a CSS selector, a "data-title" attribute, or a named region mapped to a CSS selector via Behat configuration).

Example: Given I follow "Select" in the "header .login-form" region Example: Given I follow "Select" in the "My Login Form" region

Parameters

string $link
string $region

Exceptions

Exception

iFillinTheRegion(string $field, string $value, string $region)

Fills in a field in a specfic region similar to (iFollowInTheRegion or iSeeTextInRegion)

Example: Given I fill in "Hello" with "World"

Parameters

string $field
string $value
string $region

Exceptions

Exception

iSeeTextInRegion(string $negate, string $text, string $region)

Asserts text in a specific region (an element identified by a CSS selector, a "data-title" attribute, or a named region mapped to a CSS selector via Behat configuration).

Supports regular expressions in text value.

Example: Given I should see "My Text" in the "header .login-form" region Example: Given I should not see "My Text" in the "My Login Form" region

Parameters

string $negate
string $text
string $region

Exceptions

Exception

iSelectTheRadioButton(string $radioLabel)

Selects the specified radio button

Parameters

string $radioLabel

theTableShouldContain(string $selector, string $text)

No description

Parameters

string $selector
string $text

theTableShouldNotContain(string $selector, string $text)

No description

Parameters

string $selector
string $text

iClickOnInTheTable(string $text, string $selector)

No description

Parameters

string $text
string $selector

protected NodeElement getTable(string $selector)

Finds the first visible table by various factors:

  • table[id]
  • table[title]
  • table *[class=title]
  • fieldset[data-name] table
  • table caption

Parameters

string $selector

Return Value

NodeElement

theTextBeforeAfter(string $textBefore, string $order, string $textAfter, string $element)

Checks the order of two texts.

Assumptions: the two texts appear in their conjunct parent element once

Parameters

string $textBefore
string $order
string $textAfter
string $element

iWaitXUntilISee(int $wait, string $selector)

Wait until a certain amount of seconds till I see an element identified by a CSS selector.

Example: Given I wait for 10 seconds until I see the ".css_element" element

Parameters

int $wait
string $selector

iWaitUntilISee(string $selector)

Wait until a particular element is visible, using a CSS selector. Useful for content loaded via AJAX, or only populated after JS execution.

Example: Given I wait until I see the "header .login-form" element

Parameters

string $selector

iWaitUntilISeeText(string $text)

Wait until a particular string is found on the page. Useful for content loaded via AJAX, or only populated after JS execution.

Example: Given I wait until I see the text "Welcome back, John!"

Parameters

string $text

iScrollToBottom()

No description

iScrollToTop()

No description

iScrollToField(string $locator, string $type)

Scroll to a certain element by label.

Requires an "id" attribute to uniquely identify the element in the document.

Example: Given I scroll to the "Submit" button Example: Given I scroll to the "My Date" field

Parameters

string $locator
string $type

iScrollToElement(string $locator)

Scroll to a certain element by CSS selector.

Requires an "id" attribute to uniquely identify the element in the document.

Example: Given I scroll to the ".css_element" element

Parameters

string $locator

bool spin(callable $lambda, int $wait = 60)

Continuously poll the dom until callback returns true, code copied from (@link http://docs.behat.org/cookbook/using_spin_functions.html) If not found within a given wait period, timeout and throw error

Parameters

callable $lambda

The function to run continuously

int $wait

Timeout in seconds

Return Value

bool

Returns true if the lambda returns successfully

Exceptions

Exception

protected logException(Exception $exception)

We have to catch exceptions and log somehow else otherwise behat falls over

Parameters

Exception $exception