Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space FUNCTDEV and version SOAVIRT_9.10.6_CTP_3.1.2

This topic explains how to extract a value so you can store it for use in another scenario step or tool.

Sections include:

Table of Contents
maxLevel1

Understanding Extractions

A Browser Contents Viewer tool is automatically added to each scenario step recorded from the browser. You can "extract" and store data from those elements, then use those extracted values in additional tools (for instance to populate form fields or to validate data). 

Storing a Value

To store a value represented in the rendered page, complete the following from the Browser Contents Viewer’s tool configuration panel (accessible by double-clicking the tool’s node) or the Post-Action Browser Contents tab (for extraction only):

  1. Right-click the page element whose value you want to validate or store (for example, right-click a link), and choose Extract Value from <element> Element… from the shortcut menu.
  2. In the wizard that opens, ensure that  the desired element is selected in the Property name box.
  3. If you want to "zoom in" on the value to extract, complete the isolate partial value wizard page. If you want to validate or store the entire string, you can ignore this.
    • Sometimes you may only want to validate or send a portion of a property value to a data source. If this is the case, you can isolate the part of the property value to use by selecting the Isolate Partial Value using Text Boundaries check box. You then enter Left-hand and Right-hand text that serve as boundaries for the value that you enter. The preview pane shows you what value will be used based on the boundary values that you have entered. For example, assume that the property value is "Click here to log in”:
      • To isolate the value “Click”, leave the left boundary blank and enter “ here” (including the space) in the right boundary.
      • To isolate the value “here”, enter “Click “ in the left boundary and “to” in the right boundary (again including spaces).
      • To isolate the value “in”, enter “log “ (including the space) as the left boundary and leave the right boundary blank.

    4.  To send the value of the selected property to a data source (so that the value can be used later in another scenario or in another tool):

    1. Select Extract the value to a data bank.
    2. Enter a Column Name by which you will reference this value later (e.g., in later scenario steps or in another tool).
      When the scenario step is executed, the property value will be extracted from the page and placed into a temporary data source within a column with the specified name. When later parts of the scenario reference the column name, the value stored in the temporary data source will be used for those scenario steps. You can both validate and send a property value to a data source at the same time if desired.

     5.  Click Finish.

The value will be validated or stored when the scenario is executed.

Info
iconfalse

What if I don’t see the value I want to validate or extract? 

If the Browser Contents Viewer tool does not display the value you want to extract or validate—for example, because the related scenario step failed or because the item is not visible in the rendered page  (e.g., it is a title), you can manually add a Browser Validation tool or Browser Data Bank tool. 

Info
iconfalse

Want to access the HTML content as a string?

If you want to access the HTML content as a string (e.g., if you are working with a text document and you want to avoid having to predict what HTML markup the browser will add), you can add an Extension tool to the browser contents of the Browser Playback tool. To do this, you would (right-click your Browser Playback tool, then choose Add Output> Browser Contents (rendered HTML)> Extension Tool. Next, you configure the Extension tool to use an appropriate script

You can retrieve the HTML for a browser window or frame using input.getHTML(). See the Javadoc for com.parasoft.api.BrowserContentsInput. The Javadocs can be accessed by choosing Parasoft> Help> Extensibility API.

For example, here is a JavaScript that searches for an RFC title.

Code Block
// input: com.parasoft.api.BrowserContentsInput. 
// context: com.parasoft.api.ExtensionToolContext. 
function validateRfcText(input, context) {
  var html = input.getHTML();
  var rfc = context.getValue("ds", "rfc");
  // Extract the numeric part of the RFC.
  // From "RFC5280" extract "5280".
  // From search("\\d") returns the index of the first digit in rfc.   
  // See a reference on JavaScript regular expressions.
  // Alternatively hard-code rfc.substring(3),
  var rfcNumber = rfc.substring(rfc.search("\\d"));
  var title = "Request for Comments: " + rfcNumber;
  if (html.indexOf(title) < 0) {
    context.report("HTML does not contain title: " + title);
  }
}

A Browser Data Bank tool will be chained to the Browser Playback tool. This tool will store the extracted value. The extracted value can be used wherever parameterized values are allowed, such as the value to type into an input in a subsequent scenario step or another tool. If you later want to modify the stored value, you can do so by modifying this tool’s settings.

The element that is the source of an extraction will be highlighted with a solid gray border in the Browser Contents viewer, and in the Post-Action Browser Contents tab of the Browser Data Bank tool. 

Extracting Text

To extract text to a browser data bank, complete the following:

  1. Select the text you want to extract.

  2. Right-click the selection, then choose Extract Selected Text into Data Bank

  3. Ensure that the desired extraction settings appear in the dialog that opens.

  4. Click Finish.