Web Application Plugin

The plugin provides functionality to interact with Web applications.

Installation

Example 1. build.gradle
implementation(group: 'org.vividus', name: 'vividus-plugin-web-app', version: '0.4.8')

Locator

By.<locatorType>(<locatorValue>):<visibility>->filter.<filterType>(<filterValue>)
By. prefix is optional.
  1. locatorType - [mandatory] type of the locator

  2. locatorValue - [mandatory] value of the locator

  3. visibility - [optional] visibility of element (visible by default)

  4. filterType - [optional] type of the filter

  5. filterValue - [required if filter type defined] value of the filter

Reusable locators

Feature allows to define custom reusable locator types via properties. These new locator types should rely on one of the already existing ones.

Example 2. Properties
ui.locator.<locatorName>.pattern
ui.locator.<locatorName>.locator-type
  1. locatorName - The name of the reusable locator.

  2. pattern - The pattern of the reusable locator.

  3. locator-type - The base locator type.

Example 3. Definition of custom locator
ui.locator.anyAttOrText.locator-type=xpath
ui.locator.anyAttOrText.pattern=//*[@*='%s' or text()='%s']
Example 4. Usage of custom locator
Given I am on the main application page
Then number of elements found by `anyAttOrText(attribute, text)` is = `1`
Example 5. Usage of custom locator with comma in parameter
Given I am on the main application page
Then number of elements found by `anyAttOrText(attribute, with comma\, text)` is = `1`
Description Pattern Usage Result

The pattern with a single paramter referenced twice.

//[@='%1$s' or text()='%1$s']

customLocator(text)

//[@='text' or text()='text']

The pattern with a , in value.

//[@='%s' or text()='%s']

customLocator(te\,xt1, text2)

//[@='te,xt1' or text()='text2']

The pattern containing % character

//input[@id="username" and text()="%%%s"]

customLocator(admin)

//input[@id="username" and text()="%admin]

The pattern without parameters

//input[@id="username"]

customLocator()

//input[@id="username"]

Locator Types

Type Description Example

id

id attribute of an element

id(submitForm)

cssSelector

CSS selector to an element

cssSelector(.menu-item)

xPath

Xpath to locate an element

xpath(//a)

tagName

name of an element tagName

tagName(a)

className

CSS class name

className(bold)

linkText

text of the link

linkText(Google)

linkUrl

href attribute of the link element

linkUrl(/faq)

linkUrlPart

part of a href attribute of the link element

linkUrlPart(faq)

caseSensitiveText

case sensitive text of an element

caseSensitiveText(Description)

caseInsensitiveText

case insensitive text of an element

caseInsensitiveText(description)

imageSrc

shortcut to a .//img[@src='<value>>']

imgSrc(/images/kote.png)

imageSrcPart

shortcut to a .//img[contains(@src,'<value>>')]']

imgSrcPart(kote.png)

buttonName

elements of type button or input with text or any attribute value

buttonName(submit)

fieldName

input or textarea with text or any attribute value

fieldName(editor)

checkboxName

input element with @type="checkbox" and text value

checkboxName(allow)

elementName

any attribute or text value

elementName(OK)

shadowCssSelector

chain of css selectors, separated by ;, where first value - selector for upper shadow host, last value - target element selector

shadowCssSelector(.upperHost; #innerHost1; #innerHost2; .targetValue)

Visibility types

Visibility type Usage example Description

VISIBLE

xpath(//a)

Default visibility option. Only visible elements will be found

INVISIBLE

xpath(//a):i

Only invisible elements will be found

all

xpath(//a):a

Either visible and invisible elements will be found

Filter types

The filters are applied after elements search using one of the locators specified above. The elements not matching the filter condition are sorted out without any notice.

Filter type Description Example

index

Get an element by the specified index from a collection of elements found by a locator. Indexes start from 1.

tagName(div)→filter.index(2)

textPart

Filter elements by their text parts.

tagName(h3)→filter.textPart(Welcome)

state

element State

id(v1)→filter.state(VISIBLE)

caseSensitiveText

element text should match case sensitively

id(v1)→filter.caseSensitiveText(text)

classAttributePart

class attribute should contain part

id(v1)→filter.classAttributePart(clazz)

linkUrl

href attribute of the link element

id(v1)→filter.linkUrl(/url)

linkUrlPart

part of href attribute of the link element

id(v1)→filter.linkUrlPart(/url)

tooltip

title attribute value

id(v1)→filter.tooltip(title)

imageSrcPart

src attribute should contain value

id(v1)→filter.imageSrcPart(part)

placeholder

Placeholder attribute should be equal to a value

id(v1)→filter.placeholder(placeholder-value)

validationIconSource

CSS property background-image should match

id(v1)→filter.validationIconSource(src)

fieldText

field text should match expected value

id(v1)→filter.fieldText(value)

fieldTextPart

field text should contain expected value

id(v1)→filter.fieldTextPart(value)

dropDownText

any of select options should be equal to a value

id(v1)→filter.dropDownText(value)

Properties

The properties marked with bold are mandatory.
Property Name Acceptable values Default Description

web-application.session-scope

story

scenario

story

The test lifecycle of the browser:

  • the browser opens at the first step requiring browser interaction

  • the browser closes after story or scenario depending on the property value

  • each scenario-level examples table iteration is treated as a separate scenario

An empty property value will lead to the error: "Application session scope is not set".

ui.publish-source-on-failure

true false

true

Whether to publish the application source code on failure or not

ui.context.self-healing

true false

false

Incubating feature.

If the value is set to true, an attempt to reset context will be performed when it becomes stale.

selenium.grid.host

hostname

<empty>

Remote grid host to be used to create a new session

selenium.grid.username

username

<empty>

Remote grid username to be used to create a new session

selenium.grid.password

password

<empty>

Password to be used to create a new session

proxy.enabled

true false

false

Enable proxy for the whole test run

proxy.host

any host name resolving on the machine

<empty>

Overrides the host which will be used by proxy

proxy.ports

ports range (e.g., 10000-10005)

<empty>

Ports range which could be occupied for proxy

proxy.connectable-host

host.docker.internal

<empty>

Overrides the proxy host which will be passed to browser

screenshot.on-failure.debug-modes

proxy

<empty>

Provides possibility to attach screenshot for failed proxy steps

web.driver.<browser-name>.command-line-arguments

string with arguments

<empty>

The command line (CLI) arguments to use when starting browser.

<browser-name> is one of the browsers supporting CLI arguments:

web-application.sticky-header-size-percentage

header size as a viewport size percent

25

Before the click VIVIDUS scrolls element into the viewport, the property defines top edge indent in viewport percent for the scroll

Meta Tags

@proxy - some steps require proxy to be turned on: it can be done by setting the corresponding properties or by switching on this meta tag at story level.

Dynamic variables

Context element rectangle

The set of dynamic variables provides ability to access context element coordinates, width and height.

The variables rely on the contextual approach: it is necessary to switch context to the target element.
In case of missing search context the error will be logged and -1 will be returned as a result

Variable name

Variable name Description

context-height

the height of the context element

context-width

the width of the context element

context-x-coordinate

the absolute X coordinate of the context element

context-y-coordinate

the absolute Y coordinate of the context element

Example 6. Check the size and the location of the image
When I change context to element located `id(userpic)`
Then `${context-height}` is > `0`
Then `${context-width}` is > `0`
Then `${context-x-coordinate}` is > `0`
Then `${context-y-coordinate}` is > `0`

Source code

Variable provides source code of the UI of the application under test.

Variable name

${source-code}
Example 7. Check if element exists on UI
Then `${source-code}` matches `.+Home.+`

Steps

Open URL in a new tab

Opens a new tab, switches to the opened tab and loads the given URL

When I open URL `$URL` in new window
  • $URL - The URL to open

Example 8. Open docs in a new tab.story
When I open URL `https://docs.vividus.dev` in new window

Close current window

Closes the current window and switches to the previous window.

When I close the current window
Handling alerts displayed with 'onbeforeunload' events is not implied by the WebDriver specification to close window. For handling alerts use step based on JavaScript 'Close current window with possibility to handle alert'.
This step can only be applied to a session with multiple windows open.
Example 9. Open URL in new tab, close it and switch to the previous page
Given I am on a page with the URL 'https://example.com/'
When I open URL `https://example.com/contact-us` in new window
When I close the current window

Close current window with possibility to handle alert

Trying to close the current window with 'onbeforeunload' events handling.

  • If an alert window is opened via 'onbeforeunload' event, it must be checked and handled in the subsequent steps.

  • If an alert window is not opened, the step closes the current window and switches to the previous window.

When I attempt to close current window with possibility to handle alert
This step can only be used if the current window was opened via the step When I open URL `$pageUrl` in new window.
If you confirm window close in alert, the window will be closed, and you will need to switch to current window using the following step: When I switch to window with title that $stringComparisonRule `$windowName`.
Example 10. Checking for an alert when trying to close a window with form
Given I am on a page with the URL 'https://example.com/'
When I open URL `https://example.com/form` in new window
When I click on element located `By.xpath(//*[@id='form-edit'])`
When I execute sequence of actions:
|type      |argument    |
|ENTER_TEXT|changed text|
When I attempt to close current window with possibility to handle alert
Then an alert is present
When I accept alert with message which matches `.*`

Stop page loading

Stops page loading

When I stop page loading
Could be useful in combination with Selenium’s page load strategy
Example 11. Stop page loading.story
When I open URL `https://delayed.vividus.dev` in new window
When I stop page loading

Configure page load timeout

Sets a custom page load timeout for a part of the story

When I set page load timeout to `$duration`
  • $duration - total duration to wait for page load completion in ISO-8601 format

Example 12. Before loading a heavy page set an increased timeout
Given I am on a page with the URL 'https://example.com/'
When I set page load timeout to `PT20S`
When I open URL `https://example.com/super-heavy-page` in new window
When I set page load timeout to `PT10S`

Scroll context

Scrolls the context to an edge

When I scroll context to $scrollDirection edge
  • $scrollDirection - the direction of the scroll. One of:

    • LEFT - start of a page/element horizontally

    • RIGHT - end of a page/element horizontally

    • TOP - start of a page/element vertically

    • BOTTOM - end of a page/element vertically

If the context is not set, the whole page will be scrolled
Example 13. Scroll login to a bottom
When I change context to element located `id(login)`
When I scroll context to BOTTOM edge

Scroll element into view

Scrolls an element into the view.

When I scroll element located `$locator` into view
Example 14. Scroll button into view
When I scroll element located `id(way_down_button)` into view

Performance metrics

Checks web performance metrics.

Then metric $webPerformanceMetric is $comparisonRule `$duration`
Example 15. Check page load
Given I am on a page with the URL 'https://example.com'
Then metric PAGE_LOAD_TIME is less than `PT5S`

Execute sequence of actions

Executes the sequence of web actions

When I execute sequence of actions: $actions
  • $actions - table of actions to execute

Possible actions

Type Argument Example

DOUBLE_CLICK

Search attribute or empty value

By.linkUrl(http://httpbin.org)

CLICK_AND_HOLD

Search attribute or empty value

By.linkText(Click me)

MOVE_BY_OFFSET

Point

(10, 15) where x is 10 and y is 15

RELEASE

Search attribute or empty value

By.tagName(div)

ENTER_TEXT

Text

Minsk City

CLICK

Search attribute or empty value

By.caseSensitiveText(Done)

PRESS_KEYS

Press Keys

BACK_SPACE

KEY_DOWN

Press Keys SHIFT, ALT or CONTROL simultaneously

CONTROL,SHIFT,ALT

KEY_UP

Release Keys SHIFT, ALT or CONTROL simultaneously

CONTROL,SHIFT,ALT

MOVE_TO

Search attribute

By.id(username)

Example 16. ActionSteps.story
When I execute sequence of actions:
|type          |argument                                |
|DOUBLE_CLICK  |By.fieldText(Hello World)               |
|DOUBLE_CLICK  |                                        |
|CLICK_AND_HOLD|By.xpath(//signature-pad-control/canvas)|
|CLICK_AND_HOLD|                                        |
|MOVE_BY_OFFSET|(-300, 0)                               |
|RELEASE       |By.xpath(//signature-pad-control/canvas)|
|RELEASE       |                                        |
|ENTER_TEXT    |Text                                    |
|CLICK         |By.placeholder(Enter your password)     |
|CLICK         |                                        |
|PRESS_KEYS    |BACK_SPACE                              |
|KEY_DOWN      |CONTROL,SHIFT                           |
|KEY_UP        |CONTROL,SHIFT                           |
|MOVE_TO       |By.id(name)                             |

Verify elements number

Verifies if the number of elements located by locator matches the desired number.

Then number of elements found by `$locator` is $comparisonRule `$quantity`
Example 17. Verify the number of elements
Then number of elements found by `tagName(img)` is equal to `5`

Verify elements state

Verifies if the number of elements located by locator matches the number condition and all of them are in the desired state.

If you describe number condition as equal to 5 in case if there are 10 elements by this locator and only 5 of them in the desired state. You will get two failed assertions. The first one about number condition violation. The second one about state check failure.
In case when locator’s visibility and checked state are equal (For an example ':i' and 'NOT_VISIBLE') exception will be thrown. In such cases please use step: Verify elements number. Contradictory visibility parameters (locator - ':i' and checked state - 'VISIBLE') are also not allowed.
Then number of $state elements found by `$locator` is $comparisonRule `$quantity`
Example 18. Verify the number of elements in the state
Then number of VISIBLE elements found by `tagName(img)` is = `1`

Wait for element appearance

Waits for appearance of an element by the locator.

When I wait until element located `$locator` appears
Example 19. Wait for element appearance
When I wait until element located `name(welcome-image)` appears

Wait for element disappearance

Waits for disappearance of an element by the locator.

When I wait until element located `$locator` disappears
Example 20. Wait for element disappearance
When I wait until element located `name(welcome-image)` disappears

Save the text of the context

Saves the text of the context element into a variable.

Step will throw an error if the context element is not set.
When I save text of context element to $scopes variable `$variableName`
Example 21. Save the text of the context element
When I change context to element located `By.id(username)`
When I save text of context element to SCENARIO variable `username`

Saves the attribute value of the context

Saves the attribute value of the context element into a variable.

Step will throw an error if the context element is not set.
When I save `$attributeName` attribute value of context element to $scopes variable `$variableName`
Example 22. Save the attribute value of the context element
When I change context to element located `By.id(username)`
When I save `innerText` attribute value of context element to SCENARIO variable `username`

Save the attribute value of the element

Saves the attribute value of the element located by locator into a variable.

When I save `$attributeName` attribute value of element located `$locator` to $scopes variable `$variableName`

Save the attribute value of the element

When I save `innerText` attribute value of element located `By.id(username)` to SCENARIO variable `username`

Save number of elements

Saves number of elements located by locator into a variable.

When I save number of elements located `$locator` to $scopes variable `$variableName`
Example 23. Save number of elements
When I save number of elements located `tagName(a)` to scenario variable `numberOfLinks`
Then `${numberOfLinks}` is equal to `1`

Change context

Changes the context to an element located by locator for limiting area of subsequent UI interactions.

When I change context to element located `$locator` in scope of current context
Example 24. Change context
Then number of elements found by `By.xpath(html)` is equal to `1`
When I change context to element located `By.xpath(//body)` in scope of current context
Then number of elements found by `By.xpath(html)` is equal to `0`

Reset and change context

Resets current context and changes the context to an element located by locator for limiting area of subsequent UI interactions.

When I change context to element located `$locator`
Example 25. Change context
Then number of elements found by `By.xpath(html)` is equal to `1`
When I change context to element located `By.xpath(//body)`
Then number of elements found by `By.xpath(html)` is equal to `0`

Reset context

Resets the context.

When I reset context
Example 26. Reset context
Then number of elements found by `By.xpath(html)` is equal to `1`
When I change context to element located `By.xpath(//body)`
Then number of elements found by `By.xpath(html)` is equal to `0`
When I reset context
Then number of elements found by `By.xpath(html)` is equal to `1`

Element exists for duration

Verifies that an element located by locator exists for given duration.

Then element located `$locator` exists for `$duration` duration
Example 27. Element should exists for 5 second
Then element located `id(banner)` exists for `PT5S` duration

Navigate back

Navigates back to the previous view.

When I navigate back
Example 28. Navigate back
Then number of elements found by `xpath(//*[@*='Welcome'])` is equal to `1`
When I navigate back
Then number of elements found by `xpath(//*[@*='Welcome'])` is equal to `0`

Verify elements order

Gets a collection of elements by locator and checks that they are sorted by their text in the specified order. The collection should have more than 1 element with not empty text, otherwise the step fails.

Then elements located `$locator` are sorted by text in $sortingOrder order
  • $locator - Locator.

  • $sortingOrder

Plain Readable Description

ASCENDING

ascending

Verify that elements are sorted in ascending order

DESCENDING

descending

Verify that elements are sorted in descending order

CASE_INSENSITIVE_ASCENDING

case-insensitive ascending

Verify that elements are sorted in case-insensitive ascending order

CASE_INSENSITIVE_DESCENDING

case-insensitive descending

Verify that elements are sorted in case-insensitive descending order

Example 29. Check items are sorted
Given I am on a page with the URL 'https://grocery.by'
When I click on element located `By.id(a-z)`
Then elements located `By.xpath(//span[@id='item-to-purchase'])` are sorted by text in ascending order

Take a screenshot

Takes a screenshot and publish it to the report.

When I take screenshot

Take a screenshot and save it to the folder

Takes a screenshot and saves it to the default folder defined by user.

The full path to a screenshot will be posted to logs and allure
When I take screenshot and save it to folder `$path`
  • $path - The absolute or relative path to the folder to save taken screenshot.

Example 30. Take a screenshot to a path
When I take screenshot and save it to folder `${screenshot-directory}/#{generate(Ancient.god)}.png`

Scan barcode

Scan a barcode and save its value to the variable with the specified name. Only the first founded barcode will be scanned.

Supported Code Formats

1D product 1D industrial 2D
  • UPC-A

  • UPC-E

  • EAN-8

  • EAN-13

  • UPC/EAN Extension 2/5

  • RSS-14

  • RSS-Expanded

  • Code 39

  • Code 93

  • Code 128

  • Codabar

  • ITF

  • QR Code

  • Data Matrix

  • Aztec

  • PDF 417

  • MaxiCode

Actions performed at this step:

  • Takes a viewport screenshot

  • Scans a barcode from the screenshot and save its value to the variable

When I scan barcode from screen and save result to $scopes variable `$variableName`
Example 31. Scan a barcode
When I scan barcode from screen and save result to scenario variable `qrCodeLink`
Then `${qrCodeLink}` is equal to `https://www.example.com`

Perform steps while elements exist

Executes the steps while the found elements exist.

To avoid infinite loops the iterationLimit parameter is used. If iteration’s limit reached the step will fail.
When I find $comparisonRule `$number` elements `$locator` and while they exist do up to $iterationLimit iteration of$stepsToExecute

Alias:

When I find $comparisonRule '$number' elements $locator and while they exist do up to $iterationLimit iteration of$stepsToExecute
  • $comparisonRule - The comparison rule.

  • $number - The number of elements to find.

  • $locator - Locator.

  • $iterationLimit - The maximum number of iterations to perform.

  • $stepsToExecute - The ExamplesTable with a single column containing the steps to execute.

Example 32. Disable menus
When I find >= `0` elements `xpath(//*[@class='menu enabled'])` and while they exist do up to 10 iteration of
|step                                         |
|When I click on element located `id(disable)`|

Dropdown Steps

Validate available options

Validates whether the dropdown located by locator exists and contains the list of the expected options.

Then dropdown located `$locator` contains options: $option
  • $locator - Locator

  • $options - examples table describing expected options

Example 33. Validate dropdown contains a set of colors
Then a drop down with the name 'colors' contains the items:
|state|item |
|false|Red  |
|false|Green|
|true |Blue |
The item is an option. The state (true or false) specifies whether the item is selected.

Validate the first selected option

Verifies if dropdown located by locator exists and first selected option.

Then dropdown located `$locator` exists and selected option is `$option`
  • $locator - Locator

  • $option - first selected option

Example 34. Dropdown.story
Then dropdown located `id(colors)` exists and selected option is `Blue`

Add an option to the mutli-select dropdown

Selects option in multi-select dropdown

Step will fail if target dropdown is not multi-select
When I add `$option` to selection in dropdown located `$locator`
  • $option - option to select

  • $locator - Locator

Example 35. Dropdown.story
When I add `Two` to selection in dropdown located `id(numbers)`

Select the option

Selects option in dropdown

Does not support multi-selection
When I select `$option` in dropdown located `$locator``
  • $option - option to select

  • $locator - Locator

Example 36. Dropdown.story
When I select `Red` in dropdown located `id(colors)`

Validates whether the certain cookie is set.

Then cookie with name `$cookieName` is set
  • $cookieName - The name of the cookie to check presence.

Example 37. Check the session cookie is present
Then cookie with name `JSESSIONID` is set

Validates whether the certain cookie is not set.

Then cookie with name `$cookieName` is not set
  • $cookieName - The name of the cookie to check absence.

Example 38. Check the session cookie is not present
Then cookie with name `JSESSIONID` is not set

Set cookies

Adds the cookies provided in the input ExamplesTable. It’s allowed to add the cookies for the current domain only: make sure the web browser is opened at the expected domain. The actions performed by the step:

  • add the cookies;

  • refresh the current page (this action is required to apply the changes in cookies).

When I set all cookies for current domain:$parameters
  • $parameters - The parameters of the cookies to set as ExamplesTable:

    Column Name Description

    cookieName

    the name of the cookie to set

    cookieValue

    the value of the cookie to set

    path

    the path of the cookie to set

Example 39. Set the cookie for the current domain
When I set all cookies for current domain:
|cookieName   |cookieValue |path |
|cookieAgreed |2           |/    |

Finds the cookie by the name and saves its value to a variable.

When I save value of cookie with name `$cookieName` to $scopes variable `$variableName`
Example 40. Get the value of the session cookie
When I save value of cookie with name `JSESSIONID` to scenario variable `session-id`

Finds the cookie by the name and saves all its parameters as JSON to a variable.

When I save cookie with name `$cookieName` as JSON to $scopes variable `$variableName`
Example 41. Get the session cookie
When I save cookie with name `JSESSIONID` as JSON to scenario variable `session-id`

Removes the certain cookie from the current domain. The actions performed by the step:

  • remove the certain cookie the from current domain;

  • refresh the current page (this action is required to apply the changes in cookies).

When I remove cookie with name `$cookieName` from current domain
  • $cookieName - The name of the cookie to remove.

Example 42. Remove the session cookie
When I remove cookie with name `JSESSIONID` from current domain

Removes the certain cookie from the current domain, but does not apply the changes in cookies. The current page must be refreshed or the navigation must be performed to apply the cookie changes.

When I remove cookie with name `$cookieName` from current domain without applying changes
  • $cookieName - The name of the cookie to remove.

Example 43. Remove the session cookie
When I remove cookie with name `JSESSIONID` from current domain without applying changes
When I refresh the page

Remove all cookies

Removes all cookies from the current domain. The actions performed by the step:

  • remove all cookies from the current domain;

  • refresh the current page (this action is required to apply the changes in cookies).

When I remove all cookies from current domain

Remove all cookies without apply

Removes all cookies from the current domain, but does not apply the changes in cookies. The current page must be refreshed or the navigation must be performed to apply the cookie changes.

When I remove all cookies from current domain without applying changes

Web Storage steps

Get web storage item

Finds the web storage item by the key and saves its value to the variable.

When I save $storageType storage item with key `$key` to $scopes variable `$variableName`
  • $storageType - One of the web storage mechanisms: either local or session.

  • $key - The name of the key to retrieve the value of.

  • $scopes - The comma-separated set of the variables scopes.

  • $variableName - The name of the variable to store the value of the web storage item.

Example 44. Get the value of the local storage item
When I save local storage item with key `token` to scenario variable `application-token`

Set web storage item

Adds the item with the specified key-value pair to the web storage, or updates that key’s value if it already exists.

When I set $storageType storage item with key `$key` and value `$value`
  • $storageType - One of the web storage mechanisms: either local or session.

  • $key - The name of the key to create/update.

  • $value - The value to give the key that is creating/updating.

Example 45. Set the session storage item
When I set session storage item with key `token` and value `session-token`

Validate web storage item presence

Validates the web storage item with the specified key exists.

Then $storageType storage item with key `$key` exists
  • $storageType - One of the web storage mechanisms: either local or session.

  • $key - The name of the key to check presence.

Example 46. Check the session storage item is present
Then session storage item with `token` exists

Validate web storage item absence

Validates the web storage item with the specified key does not exist.

Then $storageType storage item with key `$key` does not exist
  • $storageType - One of the web storage mechanisms: either local or session.

  • $key - The key of the local storage item to check absence.

Example 47. Check the local storage item is not present
Then local storage item with key `token` does not exist

Proxy Steps

Check the number of HTTP requests

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level.

The actions preformed by the step:

  • extract HTTP messages from the recorded proxy archive

  • filter out the HTTP messages with the response status code 302 Moved Temporarily

  • find HTTP requests matching the provided HTTP methods and the URL regular expression

  • check that the total number of the found HTTP messages satisfies the desired condition

In case of failure the full HTTP archive (HAR) is attached to the report.

Then number of HTTP $httpMethods requests with URL pattern `$urlPattern` is $comparisonRule `$number`
  • $httpMethods - The comma-separated HTTP methods to filter by

  • $urlPattern - The regular expression to match HTTP request URL

  • $comparisonRule - Comparison Rule

  • $number - The number to compare with

Example 48. Check the number of HTTP GET and POST requests matching URL regurlar expression is equal to 1
Then number of HTTP GET, POST requests with URL pattern `http://httpbin\.org/get` is equal to `1`

Capture HTTP message

Save the HTTP message part from the HTTP request with given URL-pattern into the variable with specified name and the scopes.

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level.

The actions preformed by the step:

  • extract HTTP messages from the recorded proxy archive

  • filter out the HTTP messages with the response status code 302 Moved Temporarily

  • find HTTP requests matching the provided HTTP methods and the URL regular expression

  • check that total number of the found HTTP messages is equal to 1

  • save the HTTP message part to the specified variable

In case of failure the full HTTP archive (HAR) is attached to the report.

When I capture HTTP $httpMethods request with URL pattern `$urlPattern` and save $httpMessagePart to $scopes variable `$variableName`
  • $httpMethods - The "or"-separated set of HTTP methods to filter by, e.g. GET or POST or PUT.

  • $urlPattern - The regular expression to match HTTP request URL.

  • $httpMessagePart - The HTTP message part to save. One of:

    • URL - The request URL.

    • URL query - The request URL query parameters.

    • request data - The request data includes the following keys:

      • query - The URL query is stored as a collection of key and value pairs, where key is the name of the query parameter and value is the list of query parameter values. The query parameter values are accessible via zero-based index.

      • requestBody.mimeType - The MIME type of posted data, the variable will not be saved if MIME type is not present.

      • requestBody.text - The posted data as plain text, the variable will not be saved if the request body is not present.

      • requestBodyParameters - The form data parameters are stored as a collection of key and value pairs, where key is the name of the form parameter and value is the list of form parameter values. The form parameter values are accessible via zero-based index.

      • responseStatus - The response status, the variable will not be saved if the response is not present.

    • response data - The response data includes the following keys:

      • responseBody.mimeType - The MIME type of response data, the variable will not be saved if MIME type is not present.

      • responseBody.text - The response data as plain text, the variable will not be saved if the response body is not present.

  • $scopes - The comma-separated set of the variables scopes.

  • $variableName - The variable name to save the HTTP message part.

Example 49. Validate the URL of the matching HTTP request
Given I am on a page with the URL 'https://www.google.com/search?q=vividus'
When I capture HTTP GET or POST request with URL pattern `.*/search.*=vividus` and save URL to scenario variable `URL`
Then `${URL}` is equal to `https://www.google.com/search?q=vividus`
Example 50. Validate the URL query of the matching HTTP request
Given I am on a page with the URL 'https://www.google.com/search?q=vividus'
When I capture HTTP GET request with URL pattern `.*/search.*=vividus` and save URL query to scenario variable `query`
Then `${query.q[0]}` is equal to `vividus`
Then `${query.q}` is equal to `[vividus]`
Then `${query}` is equal to `{q=[vividus]}`
Example 51. Validate the request data from the matching HTTP message
Given I am on a page with the URL 'https://www.google.com/search?q=vividus'
When I capture HTTP GET request with URL pattern `https://www.google.com/search?q=vividus` and save request data to scenario variable `data`
Then `${data.query}` is equal to `{}`
Then `${data.requestBodyParameters}` is equal to `{delivery=, custtel=, comments=, custemail=, custname=}`
Then `${data.requestBody}` is not equal to `null`
Then `${data.responseStatus}` is equal to `200`
Example 52. Validate the response data from the matching HTTP message
Given I am on a page with the URL 'https://www.google.com/search?q=vividus'
When I capture HTTP GET request with URL pattern `https://www.google.com/search?q=vividus` and save request data to scenario variable `data`
Then `${data.responseBody.text}` is equal to `{"status": "ok"}`
Then `${data.responseBody.mimeType}` is equal to `application/json`

Wait for the HTTP request

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level. Waits for the HTTP requests matching the provided HTTP methods and URL regular expression. If no HTTP request is sent and wait timeout is reached, then the step will fail.

When I wait until HTTP $httpMethods request with URL pattern `$urlPattern` exists in proxy log
  • $httpMethods - the "or"-separated HTTP methods to filter by, e.g. 'GET or POST or PUT'

  • $urlPattern - the regular expression to match HTTP request URL

Example 53. Wait for the HTTP request
Given I am on a page with the URL 'https://www.google.com/search?q=vividus'
When I wait until HTTP GET or POST request with URL pattern `https://www.google.com/search?q=vividus` exists in proxy log
Then number of HTTP GET or POST requests with URL pattern `https://www.google.com/search?q=vividus` is equal to `1`

Add headers to the HTTP request

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level. Add headers to the proxied HTTP request satisfying the desired condition

When I add headers to proxied requests with URL pattern which $comparisonRule `$url`:$headers
  • $comparisonRule - String comparison rule

  • $url - The input value of URL to filter by

  • $headers - ExamplesTable representing the list of the headers with columns "name" and "value" specifying HTTP header names and values respectively

Example 54. Add headers to the proxied HTTP request
When I add headers to proxied requests with URL pattern which is equal to `https://www.google.com/search?q=vividus`:
|name     |value     |
|testName1|testValue1|
|testName2|testValue2|
Given I am on a page with the URL 'https://www.google.com/search?q=vividus'
Then a JSON element from '${response}' by the JSON path '$.headers' is equal to '
{
    "Testname1": "testValue1",
    "Testname2": "testValue2"
}
'ignoring extra fields

Clear the recordings

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level. The step clears the HTTP requests and responses recorded by the proxy

When I clear proxy log
Example 55. Clear the data recorded by the proxy
Given I am on a page with the URL 'https://www.google.com/search?q=vividus'
When I clear proxy log
Then number of HTTP GET requests with URL pattern 'https://www.google.com/search?q=vividus' is equal to `0`

Clear the mocks

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level. The step clears previously created mocks

When I clear proxy mocks
Example 56. Clear the proxy mocks
When I mock HTTP responses with request URL which CONTAINS `vividus` using response code `200`, content `#{loadResource(page.html)}` and headers:
|name        |value    |
|Content-Type|text/html|
When I clear proxy mocks
Given I am on a page with the URL 'https://www.google.com/search?q=vividus'
Then number of elements found by `id(sw)` is = `0`

Mock the HTTP response by methods with content

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level. Mocks HTTP response by methods with a provided content

No actual request will be executed. Short-circuited response will be returned.
When I mock HTTP $httpMethods responses with request URL which $comparisonRule `$url` using response code `$responseCode`, content `$payload` and headers:$headers
  • $httpMethods - The "or"-separated set of HTTP methods to filter by, e.g. GET or POST or PUT.

  • $rule - String comparison rule

  • $url - The input value of URL to filter by

  • $code - The response status code

  • $content - The content to send within a response

  • $headers - ExamplesTable representing the list of the headers with columns "name" and "value" specifying HTTP header names and values respectively

Example 57. Hijack a page
When I mock HTTP POST responses with request URL which CONTAINS `example` using response code `202`, content `#{loadResource(mocked-example.json)}` and headers:
|name        |value           |
|Content-Type|application/json|

Mock the HTTP response with content

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level. Mocks HTTP response with a provided content

No actual request will be executed. Short-circuited response will be returned.
When I mock HTTP responses with request URL which $comparisonRule `$url` using response code `$responseCode`, content `$payload` and headers:$headers
  • $rule - String comparison rule

  • $url - The input value of URL to filter by

  • $code - The response status code

  • $content - The content to send within a response

  • $headers - ExamplesTable representing the list of the headers with columns "name" and "value" specifying HTTP header names and values respectively

Example 58. Hijack a page
When I mock HTTP responses with request URL which CONTAINS `example.com` using response code `200`, content `#{loadResourceAsByteArray(page.html)}` and headers:
|name        |value    |
|Content-Type|text/html|

Mock the HTTP response without content

This step requires proxy to be turned on. It can be done in properties or by switching on @proxy meta tag at the story level. Mocks HTTP response

No actual request will be executed. Short-circuited response will be returned.
When I mock HTTP responses with request URL which $comparisonRule `$url` using response code `$responseCode` and headers:$headers
  • $rule - String comparison rule

  • $url - The input value of URL to filter by

  • $code - The response status code

  • $headers - ExamplesTable representing the list of the headers with columns "name" and "value" specifying HTTP header names and values respectively

Example 59. 404 page
When I mock HTTP responses with request URL which CONTAINS `example.com` using response code `404` and headers:
|name          |value|
|Content-Length|0    |

Window Steps

Resize the current browser window

Changes the current browser window size to the specified one.

The specified browser window size should be smaller than the current screen resolution.
When I change window size to `$targetSize`
  • $targetSize - The desired browser window size in pixels, e.g. 800x600, where the first measure is window width, the last one is window height.

Example 60. Resize the browser window
Given I am on a page with the URL 'https://example.com/'
When I change window size to `640x320`

Video steps

Steps allow to interact with video elements.

Play Video

Starts video playback.

When I play video in video player located `$locator`

Pause Video

Pauses video playback.

When I pause video in video player located `$locator`

Rewind Video

Rewinds video to the desired mark in seconds.

When I rewind time to `$number` seconds in video player located `$locator`
  • $number - time mark in seconds

  • $locator - Locator

Get info

Saves video player info: duration, currentTime, src, networkState. For more information about the properties see HTML Audio/Video Properties

When I save info from video player located `$locator` to $scopes variable `$variableName`
  • $locator - Locator

  • $scopes - The comma-separated set of the variables scopes.

  • $variableName - The variable name to save the info. If the variable name is info, the following variables will be created:

    • ${info.src}- The the current source of the audio/video element

    • ${info.duration} - The length of the current audio/video (in seconds)

    • ${info.currentTime} - The current playback position in the audio/video(in seconds)

    • ${info.networkState} - The the current network state of the audio/video. For more information see: Network State

Example 61. Video player verifications
Given I am on a page with the URL 'https://www.youtube.com/watch?v=pYqyVpCV-3c'
When I pause video in video player located `cssSelector(video)`
When I rewind time to `777` seconds in video player located `cssSelector(video)`
When I play video in video player located `cssSelector(video)`
When I save info from video player located `cssSelector(video)` to SCENARIO variable `info`
Then `${info.currentTime}` is > `0`
Then `${info.duration}` is > `1000`
Then `${info.networkState}` is = `2`
Then `${info.src}` matches `.+youtube.+`

Perform steps for each found element

Executes the steps against all elements found by locator. After a required number of elements is found, search context switches in order for each found element and performs all steps on it.

If comparison rule mismatch steps will not be performed even if elements are found.
When I find $comparisonRule `$number` elements by `$locator` and for each element do$stepsToExecute

Alias:

When I find $comparisonRule '$number' elements by $locator and for each element do$stepsToExecute
  • $comparisonRule - The comparison rule.

  • $number - The number of elements to find.

  • $locator - Locator.

  • $stepsToExecute - The ExamplesTable with a single column containing the steps to execute.

Example 62. Script type check
When I find = `5` elements by `By.xpath(//script):a` and for each element do
|step                                                                                      |
|When I set 'type' attribute value of the context element to the 'scenario' variable 'type'|
|Then `${type}` is equal to `text/javascript`                                              |

Browser Configuration Steps

Set the browser command line arguments

Allows to set command line arguments for browsers. This step works similar to the property

web.driver.<browser-name>.command-line-arguments

In case both property and step are used - arguments from property will be ignored. Step will take effect for all new browser sessions created in the current story. It will not affect the current sessions.

List of supported command line arguments for popular browsers: . Chrome . Firefox . Internet Explorer

Not supported browsers: . Safari . Edge

When I set browser command line arguments to `$argsString`
  • $argsString - Sequence of command line arguments, separated by space.

Example 63. Set the browser to use the mocked camera stream
When I set browser command line arguments to `--use-fake-ui-for-media-stream --use-file-for-fake-video-capture=${videoStorage}/${video1}.y4m --use-fake-device-for-media-stream`
Given I am on the main application page