Skip to content

Latest commit

 

History

History
124 lines (102 loc) · 3.88 KB

plugin-html.adoc

File metadata and controls

124 lines (102 loc) · 3.88 KB

HTML Plugin

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

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`

partial$html-locator.adoc - $html - The HTML document to validate. - $comparisonRule - The comparison rule. - $quantity - The expected number of elements.

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`

partial$html-locator.adoc - $html - The HTML document to validate. - $expectedText - The expected element text.

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. partial$html-locator.adoc

  • $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.

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`
  • $dataType - Either data or text

  • $html - The HTML document to find element. partial$html-locator.adoc

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

    • $variableName - The name of the variable to save the data or text.

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  |