HTML Plugin

The plugin provides the ability to work with HTML documents: data extraction and validation.

Installation

  1. Copy the below line to dependencies section of the project build.gradle file

    Please make sure to use the same version for all VIVIDUS dependencies.
    Example 1. build.gradle
    implementation(group: 'org.vividus', name: 'vividus-plugin-html', version: '0.6.11')
  2. If the project was imported to the IDE before adding new dependency, re-generate the configuration files for the used IDE and then refresh the project in the used IDE.

Steps

Validate elements

Validates the number of elements found by the locator matches the specified rules.

Then number of elements found by $htmlLocatorType `$htmlLocator` in HTML `$html` is $comparisonRule `$number`
  • $htmlLocatorType - The HTML locator type, either CSS selector or XPath.

  • $htmlLocator - The actual locator.

  • $html - The HTML document to validate.

  • $comparisonRule - The comparison rule.

  • $quantity - The expected number of elements.

Example 2. Validate starfield release date
When I execute HTTP GET request for resource with URL `https://bethesda.net/en/game/starfield`
Then number of elements found by XPath `//h3[contains(., '111122')]` in HTML `${response}` is = `1`

Validate element text

Validates whether the element found by the locator contains the expected text.

Then element found by $htmlLocatorType `$htmlLocator` in HTML `$html` contains text `$expectedText`
  • $htmlLocatorType - The HTML locator type, either CSS selector or XPath.

  • $htmlLocator - The actual locator.

  • $html - The HTML document to validate.

  • $expectedText - The expected element text.

Example 3. Validate starfield release date
When I execute HTTP GET request for resource with URL `https://bethesda.net/en/game/starfield`
Then element found by XPath `//h3` in HTML `${response}` contains text `111122`

Save attribute value

Saves the attribute value into the variable.

When I save `$attributeName` attribute value of element found by $htmlLocatorType `$htmlLocator` in HTML `$html` to $scopes variable `$variableName`
  • $attributeName - The name of the attribute.

  • $htmlLocatorType - The HTML locator type, either CSS selector or XPath.

  • $htmlLocator - The actual locator.

  • $html - The HTML document to find element.

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

  • $variableName - The name of the variable to save the attribute value.

Example 4. Validate paragraph title
Given I initialize story variable `html` with value
`
<html>
  <head>
    <title>Page Title</title>
    <script>//<![CDATA[Here comes the data//]]></script>
  </head>
  <body>
    <h1>This is a Heading</h1>
    <p title="paragraph">This is a paragraph.</p>
  </body>
</html>
`
When I save `title` attribute value of element found by CSS selector `p` in HTML `${html}` to scenario variable `title`
Then `${title}` is = `paragraph`

Save data/text of element

Saves the data or the text of element. Where the data is characters between the start-tag and end-tag of the element and the text is the textual content of the element without any inner element.

When I save $dataType of element found by $htmlLocatorType `$htmlLocator` in HTML `$html` to $scopes variable `variableName`
Example 5. Validate data/text
Given I initialize story variable `html` with value
`
<html>
  <head>
    <title>Page Title</title>
    <script>//<![CDATA[Here comes the data//]]></script>
  </head>
  <body>
    <h1>This is a Heading</h1>
    <p title="paragraph">This is a paragraph.</p>
  </body>
</html>
`
When I save data of element found by <locatorType> `<script>` in HTML `${html}` to scenario variable `data`
When I save text of element found by <locatorType> `<header>` in HTML `${html}` to scenario variable `text`
Then `${data}` is equal to `//<![CDATA[Here comes the data//]]>`
Then `${text}` is equal to `This is a Heading`
Examples:
|locatorType |script  |header|
|CSS selector|script  |h1    |
|XPath       |//script|//h1  |

Save number of elements

Saves the number of elements contained in HTML document.

When I save number of elements found by $htmlLocatorType `$htmlLocator` in HTML `$html` to $scopes variable `$variableName`
Example 6. Validate number of Heading 1 elements
Given I initialize story variable `html` with value
`
<html>
  <body>
    <h1>This is a Heading</h1>
    <p title="paragraph">This is a paragraph.</p>
  </body>
</html>
`
When I save number of elements found by XPath `//h1` in HTML `${html}` to scenario variable `heading1`
Then `${heading1}` is equal to `1`