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 and used within Browser Checks to collect performance metrics for the scenario.
Step 1: Create a Selenium Script
Create your Selenium script using Selenium IDE. It does not matter which Selenium IDE or Browser version you use; note that in some cases, some manual effort will be needed in order to convert your scenarios into a working ASM Scenario.
Step 2:
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 | goto | runScript | storeXpathCount | insertPageBreak |
clickAtAndWait | keyUp | assertLocation | waitForValue | label | getEval | storeCssCount | takeScreenshot |
click | keyUpAndWait | assertVisible | waitForAttribute | close | runScriptAndWait | storeValue | startRecording |
clickAt | keyPress | assertElementNotPresent | waitForNotText | pause | storeText | clearRecording | |
type | keyPressAndWait | assertNotVisible | waitForNotValue | setSpeed | storeLocation | stopRecording | |
sendKeys | mouseOver | assertAttribute | waitForNotAttribute | setTimeout | storeExpression | getDictionary | |
typeKeys | assertNotAttribute | waitForTextPresent | echo | storeEval | |||
select | assertValue | waitForTextNotPresent | storeAttribute | ||||
selectAndWait | assertNotValue | waitForElementPresent | storeElementPresent | ||||
selectFrame | assertText | waitForEditable | store | ||||
selectWindow | assertTextNotPresent | waitForElementNotPresent | |||||
submit | assertTextPresent | waitForNotVisible | |||||
assertExpression | waitForTitle | ||||||
assertNextConfirmation | waitForLocation | ||||||
assertNextAlert | waitForAlert | ||||||
assertAlert | waitForConfirmation | ||||||
assertConfirmation | |||||||
assertEval | |||||||
verifyTitle | |||||||
verifyLocation | |||||||
verifyElementPresent | |||||||
verifyVisible | |||||||
verifyElementNotPresent | |||||||
verifyNotVisible | |||||||
verifyAttribute | |||||||
verifyNotAttribute | |||||||
verifyValue | |||||||
verifyNotValue | |||||||
verifyText | |||||||
verifyTextNotPresent | |||||||
verifyTextPresent | |||||||
verifyExpression |
Usage Assertion Modes
Assertion Modes
All Selenium Assertions can be used in 3 modes: assert
, verify
, and waitFor
.
Modes In Synthetic Monitoring
Verify = Assert
In Synthetic Monitoring, false
results from both verify
and assert
are treated the same: as a major failure.
For clarity, we recommend you only use Assert
commands in any scripts you want to use with Synthetic Monitoring.
WaitFor
With waitFor
commands, the behavior is the same as in Selenium IDE.
Modes in Selenium IDE
Assert
When an assert
command returns false
, test execution will be aborted. This means that all following test steps after that line of code are skipped.
Verify
When a verify
command returns false
, test execution will continues, and the failure is logged. Usually this behavior is desired when a particular failure does not reflect a vital component.
WaitFor
The waitFor
commands wait for some condition before continuing. If the condition is already true, they return true
immediately. If the condition does not become true within the timeout threshold, the test will fail and execution is aborted.
Usage Types
Selenium commands are generally one of three types: Actions, Accessors, and Assertions.
Actions
Actions are commands that generally manipulate the state of the application. They do things like click this link
and select that option
. If an Action fails, or has an error, the execution of the current test is stopped.
Many Actions can be called with the AndWait
suffix, e.g. clickAndWait
. This suffix tells Selenium that the action will cause the browser to make a call to the server, and that Selenium should wait for a new page to load.
Accessors
Accessors examine the state of the application and store the results in variables, e.g. storeTitle
. They are also used to automatically generate Assertions.
Assertions
Assertions are like Accessors, but they verify that the state of the application conforms to what is expected. Examples include make sure the page title is X
and verify that this checkbox is checked
.
insertPageBreak
The Apica Custom Extension command for Selenium, insertPageBreak,
creates a new Page Break that separates different pages (which typically consist of multiple URL calls) from each other.
insertPageBreak
expects one argument, the name/title of the page break, which will be shown on the Result Details page in ASM.
They provide logical divisions in the page flow, typically by adding a page break before each workflow step that could utilize multiple web pages on a site.
Page breaks can be entered manually into scripts or automatically generated when recording web sessions.
Example
If the login portion of a web page sequence takes place over two or three HTML pages, the Page break could define the set of HTML pages to be all part of a single group before the next logical page navigation, another Page Break, which could be “Check my account.”
When should I use insertPageBreak?
Typically, insertPageBreak
is only necessary if you need to set a custom title or if requests which are triggered as a result of executing multiple different commands all end up as part of the same step, and you wish to split these requests into multiple steps.
ZebraTester and Page Break
insertPageBreak
does not apply to ZebraTester scripts. ZebraTester’s Page Break method inserts a new page break in a recorded session (a prxdat file) and does so with guided fields.
Dictionary Concept
In Synthetic Monitoring, the concept of “Dictionaries” is a repository to store:
User names
Passwords
Internal access URLs
And other sensitive data
Dictionaries can be used for data reuse in multiple environments or to hide access information during monitoring. This lets you use passwords in scenarios without having them displayed in cleartext or reuse a single URL in several different scenarios without manually coding it.
The getDictionary Command
The Apica custom Selenium scripting command getDictionary
allows you to access a user-defined dictionary from inside a check scenario script.
The getDictionary
fetches the whole Dictionary (with all key/value pairs) and stores it locally for when the script executes.
Selenium Example:
When the getDictionary
command fetches pre-defined variables from a dictionary, it expects two arguments:
Target: Your API Token or Authorization Ticket
Value: The dictionary URL
https://api-wpm.apicasystem.com/v3/scenarios/proxysniffer/dictionaries/{dictionary_key}
Here’s a screenshot of a Selenium step with getDictionary
Command | Target | Value |
---|---|---|
|
|
|
Note: API token/Auth Ticket is masked for privileged users
Postman Screenshot example of the API GET command for the DougApicaKey dictionary: | |
Another Postman Screenshot example of the API GET command for the ApicaKey dictionary. You can see how each dictionary has defined different key-value pairs. | |
Selenium Example 1: The Dictionary Key "DougApicaKey" has 3 key values (excluding the sample value) that are used in the scenario. (Click on image for a larger version) | |
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 your dictionary will be used in the Selenium scenario rather than these values being hard-coded in the script. |
takeScreenshot
The command takeScreenshot
takes a screenshot that will be visible in the Details.
Description
This is in addition to the regular Details Result Screenshots feature.
Use the normal takeScreenshot
, which captures just what is visible in Chrome, while Firefox captures the entire "page."
Adding takeScreenshot
anywhere in your script will allow you to get screenshots at this step in the scenario.
Note: remember that you still will only see screenshots according to your settings while the check is running.
Apica Custom Script Extension
The Apica custom extensions can be downloaded from the https://wpm.apicasystem.com/ManageScenarios view in Synthetic Monitoring:
Download
The extension can only be integrated into an older version of Selenium IDE - version 2.9.1, which runs on Firefox v55 or older Firefox versions.
This extension is deprecated and limited documentation exists surrounding the extension.
To download the Apica Extension:
https://wpm.apicasystem.com/Account/Login to Synthetic Monitoring
Open the https://wpm.apicasystem.com/ManageScenarios view
Click the https://wpm.apicasystem.com/ManageScenarios/DownloadScriptExtension link
Install Extension
Install Apica Extension
In order to use the Apica Extension with Selenium IDE, you need to add it as an option and restart Selenium IDE.
Install Extension
To install the Apica extension:
Start in Firefox:
Open Selenium IDE
Open the Options menu
Select Options...
The Selenium IDE options dialog opens:
In the General tab:
Find the Selenium Core Extensions field
Click Browse
Find the downloaded plugin file (
apicaExt.js
)Select the file
Click Open
Click OK
Reopen the IDE window to apply the changes.
Close Selenium IDE
Next time you open Selenium IDE, the plugin will be loaded.
Encrypted Selenium Variables
Please note: This described feature has to be enabled per customer account. If this is a feature that you require, please contact your Technical Account Manager or Support:
Don’t just Mask. Encrypt!
Emulating users clicking through your web application with scenarios is an important aspect of synthetic monitoring. Still, a downside of using these scenarios is that sensitive credentials or other data can be exposed to other Apica Synthetic users. To improve the security and control of important data, we have added the ability to encrypt variables in your scenarios. Any data stored in an encrypted variable is completely inaccessible except when the scenario is actually being run, so you can now safely add scenarios to even your most sensitive applications without the fear of your information getting into the wrong hands.
To add an encrypted variable to your scenarios, add a variable using the Selenium "store" command, and start the name of your variable with "encryptapica." You can then use that variable safely anywhere in your scenario.
Step | Screenshot |
---|---|
| |
In this example, we have a password being passed in the clear each time it is run. We’ll want to encrypt this password with the Apica crypto service that will pass a variable name in its place. In monitoring, Apica recommends using test/dummy logins and passwords to reduce confidential and sensitive information exposure. | |
storing a new variable to hold the encrypted value. a. Near the top of your scenario, Add/Declare a new variable with the 'Store' Command in the dropdown box.
Notice the red triangle to the right of the value. This will remain there until you provide a Target to encrypt in the column to the left. Once you’ve added the target (in the next step), this will be replaced by a green lock. | |
a. Double-click in the target field. b. A new dialog box, “Update Encrypted Value” will appear to enter in your plaintext value. Be sure that you have a version of this plaintext securely stored somewhere because Apica will not retrieve the plaintext value. Click the Update & Encrypt to begin the encryption. | |
| |
| |
|
In the video tutorial below, we will demonstrate this process for a script with a plaintext password replaced using this crypto service.
This service may be used wherever the values are considered sensitive such as username, password, account numbers, etc.
Masking Selenium Values
When command values contain sensitive information, they can be masked by using the apica Prefixes. This will prevent the value from being displayed in results.
Example
Let’s assume you use a scenario with the following commands:
Command | Target | Value |
---|---|---|
open |
| |
selectWindow |
| |
type |
|
|
type |
| \{\{${maskapicaPassword}\}\} |
clickAndWait |
|
If you want to mask the value secretPa$$word
in the Check Result page the following steps are required:
Add the command
Store
to store the password as a variable with the prefixmaskapica
Use this variable with the actual command which uses the password.
Your commands should now look like this:
Command | Target | Value |
---|---|---|
store |
|
|
open |
| |
selectWindow |
| |
type |
|
|
type |
| \{\{${maskapicaPassword}\}\} |
clickAndWait |
|
When Synthetic Monitoring runs a check using this scenario the result will be saved with the executed scenario commands list as the example above. When Synthetic Monitoring shows the check result on the check results page Synthetic Monitoring will recognize that there is a command value which starts with maskapica
.
The command’s target will be masked on the the check results page:
Command | Target | Value |
---|---|---|
store |
|
|
open |
| |
selectWindow |
| |
type |
|
|
type |
| \{\{${maskapicaPassword}\}\} |
clickAndWait |
|
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 |
---|---|---|
|
|
|
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
."
‘maskapica’ hide a value
Maskapica
When the "maskapica" prefix is used in a command value, the web performance monitor will store the command target (the example Target below is '$(ExternalPassword) ') as is in the result but will mask it (as the example Value below, “maskapicaPassword“) on the check result page.
Example
Limitations of Selenium IDE within ASM Scenarios
Key Codes
When using sendKeys in Selenium IDE, certain key codes are not available in Scenario Migration.
Overview
${KEY_ENTER} ${KEY_SHIFT} ${KEY_LEFT}
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
| \{\{${stored_var} > 0\}\} |
|
WebDriver
| \{\{return ${stored_var} > 0\}\} |
|
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
| | |
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:
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
It is currently not possible to change the value of a variable from within a javascript.
##
This Selenium IDE code will change the value of $counter
:
|
|
|
However the following example won't affect the value of $counter
|
|