Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Selenium IDE is a standalone 3rd party tool for creating Selenium test cases. These test cases can be imported as script files into Synthetic Monitoring ASM and used within Browser Checks to collect performance metrics for the scenario. In some cases, you will need to users must make changes to your their Selenium IDE script before it can be used within ASM as a Scenario. This article explains how ASM handles Selenium IDE scripts so you can easily understand how to convert your scripts into Scenarios.

Supported Selenium IDE Commands

Use the following table as a reference when determining whether a certain Selenium IDE command is compatible with your ASM Scenario.

Actions

Keyboard &  Mouse interaction

Verification and Assertion

Waits

Scenario Flow

JS Execution

Stored Variables

Custom (ASM Specific) Commands

open

keyDown

assertElementPresent

waitForVisible

gotoIf

fireEvent

storeTitle

setPageBreak

clickAndWait

keyDownAndWait

assertTitle

waitForText

waitForValue

goto

runScript

storeXpathCount

insertPageBreak

clickAtAndWait

keyUp

assertLocation

waitForValue

waitForAttribute

label

getEval

runScriptAndWait

storeCssCount

takeScreenshot

click

clickAndNotWait

keyUpAndWait

assertVisible

waitForAttribute

waitForNotText

close

runScriptAndWait

executeScript

storeValue

startRecording

clickAt

click

keyPress

assertElementNotPresent

waitForNotText

waitForNotValue

pause

getEval

storeText

clearRecording

type

clickAt

keyPressAndWait

assertNotVisible

waitForNotValue

waitForNotAttribute

setSpeed

storeLocation

stopRecording

sendKeys

doubleClick

mouseOver

assertAttribute

waitForNotAttribute

waitForText

setTimeout

storeExpression

getDictionary

typeKeys

doubleClickAt

assertNotAttribute

waitForTextPresent

echo

storeEval

setLocation

select

doubleClickAndWait

assertValue

waitForTextNotPresent

storeAttribute

selectAndWait

doubleClickAtAndWait

assertNotValue

waitForElementPresent

storeElementPresent

selectFrame

clickInvisible

assertText

waitForEditable

store

selectWindow

clickInvisibleAndWait

assertTextNotPresent

waitForElementNotPresent

setLocation

submit

type

assertTextPresent

waitForNotVisible

sendKeys

assertExpression

waitForTitle

typeKeys

assertNextConfirmation

waitForLocation

select

assertNextAlert

waitForAlert

selectAndWait

assertAlert

waitForConfirmation

selectFrame

assertConfirmation

waitForPageToLoad

selectWindow

assertEval

submit

verifyTitle

createCookie

verifyLocation

deleteCookie

verifyElementPresent

verifyVisible

verifyElementNotPresent

verifyNotVisible

verifyAttribute

verifyNotAttribute

verifyValue

verifyNotValue

verifyText

verifyTextNotPresent

verifyTextPresent

verifyExpression

Usage Assertion Modes

In order to assert a command within Selenium IDE, you can use the assert, verify, or waitFor commands; the assert command will stop the Selenium IDE script if the expected condition is not met, while the verify command will log an error message but not stop the script. ASM scenarios, in contrast, treat the assert and verify commands in the same way - if the expected condition is not met, both commands will result in a failure of the scenario.

By contrast, the behavior of the waitFor command is the same within Selenium IDE and ASM Scenarios. Within both tools, the waitFor command will wait for a specified element and will result in a script failure if the element is not found within the specified timeframe.

Custom ASM Commands

...

Custom ASM Commands

ASM supports several commands which are not utilized in native Selenium IDE: insertPageBreak, takeScreenshot, and getDictionary.

setLocation

The setLocation command may be utilized in order to mimic a certain location from within the browser. To use, specify “setLocation” as the command and specify the desired coordinates as the Target:

...

Accepted syntax for Target coordinates includes:

  • latitude: 59.3259965, longitude: 18.0057939

  • 59.3259965, 18.0057939

insertPageBreak

ASM scenarios support a custom command called “insertPageBreak” insertPageBreak. This command creates a new Page Break page break that separates different pages (which typically consist of multiple URL calls) from each other. The command expects one argument , the name/title of the page break, - a name - which will be shown on the Result Details page in ASM. Page breaks can be entered manually into scripts or automatically generated when recording web sessions.

For example, If the login portion of a web page sequence takes place over two or three HTML pages, the manual Page break Break could define organize the set of HTML pages to be all part of into a single group before the next logical page navigation , - another Page Break, which could be “Check my account.” Typically, insertPageBreak is only necessary if you need to set a custom title or if requests which are triggered as a result of . Manual page breaks are helpful when requests triggered by executing multiple different commands all end up as part of the same step, and you wish there is a need to split these requests into multiple steps.

It is possible to disable automatic insertion of page breaks via the Edit Check settings. See https://apica-kb.atlassian.net/wiki/spaces/ASMDOCS/pages/2134212678/Understanding+Browser+Check+Results#Page-Breaks-in-a-Browser-Check-Result for more information on page breaks.

takeScreenshot

The command takeScreenshot takes a screenshot that will be visible in the Check Details. The command will insert an additional screenshot onto the page in addition to whatever screenshots have been added in the Edit Check settings.

getDictionary

The concept of “Dictionaries” within ASM is a repository to store user names, passwords, internal access URLs, and other sensitive data. Dictionaries can be used to reuse data in multiple environments or to hide access information during monitoring. This allows users to utilize passwords in scenarios without displaying them in cleartext or reuse a single URL in several different scenarios without manually coding it.

The Apica custom Selenium scripting command getDictionary allows users to access a user-defined dictionary from inside a check scenario script. The getDictionary fetches the entire Dictionary (with all key/value pairs) and stores it locally for when the script executes. 

Using the getDictionary Command

Step 1: Create the Dictionary

  1. Create/Add a Dictionary using our API POST command

  2. Name the Dictionary Key that will be used to access this dictionary. Some examples:

    1. "dictionary_key": "ExampleApicaKey","dictionary" {Name:value pairs}

    2. "dictionary_key": "ApicaKey","dictionary" {Name:value pairs}

    3. You will also provide string-pair values in the form of “targetstring1”: “targetvalue1” that will form the Keys that access the values needed.

      • e.g., “firstname”: “Doug”

      • e.g., “lastname”: “Smith”

      • e.g., “cardnumber”: “1234-1234-1234-1234”

      • e.g., “expdate”: “12/25”

  3. You must also provide a Description

    1. e.g. "description": "Test Dictionary"

  4. In this example, the POST command is

    1. POST scenarios/proxysniffer/dictionaries

  5. The POST body for one of the examples above would be

Code Block
{
  "dictionary_key": "DougApicaKey",   
  "dictionary": {
     “firstname”: “Doug”,
     "lastname”: “Smith”,
     "cardnumber”: “1234-1234-1234-1234"
  },
"description": "Test Dictionary"
}

Step 2: Retrieve the Dictionary

Once the above dictionary has been defined, the Selenium scripting command getDictionary allows access to this information from inside a check scenario script. The getDictionary command fetches the entire Dictionary (with all key/value pairs) and stores it locally for when the script executes. It uses the Apica Dictionaries GET API to get these dictionary values. The GET call will be in the form of

https://api-wpm.apicasystem.com/v3/scenarios/proxysniffer/dictionaries/{dictionary_key}?auth_ticket={auth ticket value}

The getDictionary command then turns these key values into ASM variable names for use in the ASM script.

Using the getDictionary Command within a Selenium Scenario

When the getDictionary command fetches pre-defined variables from a dictionary, it expects two arguments:

  1. Target: User’s API Token or Authorization Ticket

  2. Value: The dictionary URL https://api-wpm.apicasystem.com/v3/scenarios/proxysniffer/dictionaries/{dictionary_key}

The following screenshot provides an example of the getDictionary command within a Selenium script:

...

Command

...

Target

...

Value

...

getDictionary

...

63F6E******************

...

{API URL}/DougApicaKey

Info

The API token is masked for privileged users.

...

This screenshot provides an example of the API GET command for the dictionary “DougApicaKey”.

...

This screenshot provides another example of the API GET command for the dictionary “ApicaKey”. Note how each dictionary has different defined key-value pairs.

...

Selenium Example 1: The Dictionary Key "DougApicaKey" has 3 key values (excluding the sample value) that are used in the scenario.

...

Selenium Example 2: The Dictionary Key "Apicakey" has 2 key values (excluding the sampleKey value) that are used in this scenario.

In this case, the username and password values, from the dictionary will be used in the Selenium scenario; these values will not be hard-coded into the script.

...

Encrypting Selenium Variables

Note

This feature must be enabled per customer account. If you are interested in encrypting Selenium variables within your Scenarios, please contact your Technical Account Manager or Support.

...

In addition to storing and fetching sensitive data from a Dictionary, ASM also offers the option to encrypt sensitive Scenario data. Any data stored in an encrypted variable is only accessible when the script is actually being run. To add an encrypted variable to your scenarios, add a variable using the Selenium "store" command, and start the name of the sensitive variable with "encryptapica." It is possible to use that stored variable anywhere in the scenario:

...

Info

It is possible to specify any string in the “Value” field for variable encryption as long as it starts with the string “encryptapica”. This string invokes the crypto service which is responsible for encrypting the provided value.

...

Step

...

Screenshot

...

Step 1: Edit a Check which contains a Scenario and click the Debug Scenario icon.

...

Step 2: Identify the sensitive information to be encrypted.

...

...

Step 3: Store the value as an encrypted value by adding a new variable which will hold the encrypted value.

  1. At the top of the scenario, add a new step with the “Store” Command in the dropdown box.

  2. Add a string which begins with “encryptapica” to the “Value” field. In the example, the value is “encryptapicapassword”.

  3. When the “encryptapica” value is added, a warning icon will appear to the right of the step. Once a target is added, the triangle icon will be replaced by a green lock icon.

...

Step 4: Enter the original Target value.

  1. Double-click in the target field.

  2. A new dialog box, “Update Encrypted Value” will appear to enter in your plaintext value.

  3. Click the Update & Encrypt to begin the encryption.

Note

Make sure a backup of the value exists elsewhere; Apica does not have the ability to retrieve this value!

...

Step 5: After the encryption has been completed, the green lock will appear, and the words “[ENCRYPTED BY APICA]” will be in the Target field.

...

Step 6: In the step where the password originally appeared, replace the plaintext password with the stored variable name specified earlier. In this case, in step 25, the variable ‘encryptapicapassword’ will be entered as $(variable_name) or $(encryptapicapassword).

...

Step 7: Test the scenario to ensure it passes the encrypted values to the intended application and click “Save scenario”.

...

The below video tutorial provides a visual demonstration of the process of encrypting and adding a scenario.

Widget Connector
overlayyoutube
_templatecom/atlassian/confluence/extra/widgetconnector/templates/youtube.vm
width400px
urlhttps://www.youtube.com/watch?v=P-tmcAGpcO8
height300px

Masking Selenium Variables

Command values can be masked using an Apica-specific prefix when they contain sensitive information. This prevents the value from being displayed in results. Assume a scenario contains the following commands:

...

Command

...

Target

...

Value

...

open

...

/

...

selectWindow

...

null

...

type

...

id=username

...

user1

...

type

...

id=password

...

secretPa$$word

...

clickAndWait

...

_input@value='Log in'

It is possible to mask the value secretPa$$word in the Check Result page by adding the Store command to store the password as a variable with the prefix maskapica and using that variable in the actual command which uses the password. The scenario will contain the following commands after the value secretPa$$word is masked:

...

Command

...

Target

...

Value

...

store

...

secretPa$$word

...

maskapicaPassword

...

open

...

/

...

selectWindow

...

null

...

type

...

id=username

...

user1

...

type

...

id=password

...

\{\{${maskapicaPassword}\}\}

...

clickAndWait

...

_input@value='Log in'

The command’s target will be masked on the Check Results page when the check is run:

...

Command

...

Target

...

Value

...

store

...

*******

...

maskapicaPassword

...

open

...

/

...

selectWindow

...

null

...

type

...

id=username

...

user1

...

type

...

id=password

...

\{\{${maskapicaPassword}\}\}

...

clickAndWait

...

//input@value='Log in'

Prefixes

Synthetic Monitoring supports custom security prefixes for use in select scenario values where information may need more security.

‘apica’ to store information

Store a result with “apica”

Synthetic Monitoring will store the command result for later display when the "apica" prefix is used in a command value.

Display

The command value is shown in Details in the Details Result Scenario in the Value column.

Example

...

Command

...

Target

...

Value

...

storeCookieByName

...

ServerID

...

apicaServerID

This example will store the ServerID cookie value and show it as apicaServerID Extracted Value.

This prefix will work with any command that starts with “store."

Limitations of Selenium IDE within ASM Scenarios

Key Codes

When using sendKeys in Selenium IDE, the key codes ${KEY_ENTER}, ${KEY_SHIFT}, and ${KEY_LEFT} are not valid commands within Selenium IDE.

JavaScript Execution

WebDriver’s JavascriptExecutor will wrap all JS and evaluate it as an anonymous expression.

Impact on JavaScript execution

This means that you need to use the “return” keyword:

browserbot.getCurrentWindow().document.title

becomes

return document.title;

The same is true when evaluation expressions using storeEval or assertEval:

Selenium IDE

...

assertEval

Code Block
\{\{${stored_var} > 0\}\}

...

true

WebDriver

...

assertEval

Code Block
\{\{return ${stored_var} > 0\}\}

...

true

Note that there are multiple commands that will result in javascript evaluation: gotoIf, assertEval, getEval, storeEval

Key Strokes

If you need to simulate a keypress input event, such as pressing the enter key, you must use keyPress or keyPressAndWait (if the keystroke triggers a new page load), with the ASCII as an argument.

Overview

Example: Press enter key and wait for new page load

...

keyPressAndWait

...

id=gh-ac

...

\13

Response Times

Agents running Microsoft Windows may handle very short report times incorrectly.

Waterfall graph

Agents running Microsoft Windows sometimes report 0ms for URL calls with very quick response times (0-20ms).

Return Required

For Selenium commmands that execute javascript snippets, the command expects a returned value

Return Command In Scripts

The following commands result in javascript evaluation/expects a javascript snippet as argument, which must include the 'return' keyword:

GotoIf

RunScript

RunScriptAndWait

GetEval

StoreEval

StoreExpression

Type & sendKeys

Even though the "type" command should work in most cases, we strongly recommend that you use "sendKeys" instead.

Key Strokes

If you need to simulate a key press input event, such as pressing the enter key, you must use keyPress or keyPressAndWait (if the key stroke triggers a new page load), with
the ascii code as argument:

Example: Press enter key and wait for new page load
keyPressAndWait | id=gh-ac | \13

Script Variables

This command is helpful when troubleshooting scripts as it gives a snapshot of what exactly happens at a particular step.

getDictionary

See Storing and Retrieving Information Using the ASM Dictionary.

Limitations of Selenium IDE within ASM Scenarios

Key Codes

When using sendKeys in Selenium IDE, the key codes ${KEY_ENTER}, ${KEY_SHIFT}, and ${KEY_LEFT} are not valid commands within Selenium IDE. Use keyPress or keyPressAndWait (if the keystroke triggers a new page load) instead. When entering a keystroke, use the respective ASCII values for the key you want to be pressed. For example, if you want to press Enter within an application, use the command keyPress and the value \13.

Command

Target

Value

keyPressAndWait

id=gh-ac

\13

The “value” of the command corresponds to the ASCII “Oct” value of the key you are trying to press; see https://www.asciitable.com/ for a full list. Some examples of values which correspond to keys include the following:

\10 corresponds to “backspace”

\9 corresponds to “tab”

JavaScript Execution

Selenium WebDriver’s JavascriptExecutor will wrap all JavaScript and evaluate it as an anonymous expression. Therefore, the “return” keyword must be used when executing JavaScript within the “Target” field for the following commands:

GotoIf

GetEval

StoreEval

StoreExpression

The following commands do not require the use of “return”:

RunScript

RunScriptAndWait

For example, if you are trying to determine whether the result of the expression ${stored_var} > 0 is true, use the following code:

Command

Target

Value

assertEval

return ${stored_var} > 0

true

The following screenshot (supplemental text provided) shows an example in which JavaScript is being used to execute another check upon completion of the current scenario. Basically, the check kicks off another check when it’s finished.

Within the scenario:

...

Run execution log:

...

Javascript snippet:

Code Block
var xhr = new XMLHttpRequest();

xhr.open('POST', 'https://api-asm.apica.io/v3/checks/3393731/job?auth_ticket=${auth_ticket}', true);

xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');

xhr.onreadystatechange = function () {
    if (xhr.readyState === 4) { 
        if (xhr.status === 200) { 
            var response = JSON.parse(xhr.responseText);
            console.log('Success:', response); 
        } else {
            console.error('Error:', xhr.statusText);
        }
    }
};

xhr.send();

return "check ID 3393731 has been executed!"

The “runScript” or “runScriptAndWait” commands could also be used with the above Javascript if the “return” statement is omitted.

Note

Javascript comments are NOT allowed in the body of a Javascript snippet!

Type & sendKeys

Even though the type command works in most cases, Apica strongly recommends using sendKeys instead of type. The type command edits the HTML format of the code, while the sendKeys command attempts to simulate actual typing and is therefore able to trigger javascript code in fields.

Incrementing a Stored Numeric Value

It is currently not possible to change the value of a variable from within a javascriptJavaScript snippet.

##

This Selenium IDE code will change the value of $counter:

Command

Target

Value

 storeEval

return (storedVars'counter' + 1)

counter

However the following example won't affect The following command will not change the value of $counter:

Command

Target

Value

 runScript

storedVars'counter' += 1;

counterTwo

...

Info

Knowing how to increment a value is useful when running through a loop in an ASM script!

Usage Assertion Modes

In order to assert a command within Selenium IDE, you can use the assert, verify, or waitFor commands; the assert command will stop the Selenium IDE script if the expected condition is not met, while the verify command will log an error message but not stop the script. ASM scenarios, by contrast, treat the assert and verify commands the same way - if the expected condition is not met, both commands will result in a failure of the scenario.

By contrast, the behavior of the waitFor command is the same within Selenium IDE and ASM Scenarios. Within both tools, the waitFor command will wait for a specified element and will result in a script failure if the element is not found within the specified timeframe. The default timeframe is 30 seconds and can be changed with “setTimeout”.