Selenium IDE is a standalone 3rd party tool for creating Selenium test cases. These test cases can be imported as script files into ASM and used within Browser Checks to collect performance metrics for the scenario. In some cases, users must make changes to 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 | 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
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”.
Custom ASM Commands
ASM supports several commands which are not utilized in native Selenium IDE: insertPageBreak, takeScreenshot, and getDictionary.
insertPageBreak
ASM scenarios support a custom command called insertPageBreak
. This command creates a new 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, 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 Page break could organize the set of HTML pages into a single group before the next logical page navigation - another Page Break. insertPageBreak
is typically 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.
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. 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.
Encrypting Selenium Variables with the “encryptapica” String
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.
ASM offers the option to encrypt sensitive Scenario data as an alternative to storing and fetching sensitive data from a Dictionary. Any data stored in an encrypted variable is only accessible when the script is being run. To add an encrypted variable to your scenario, add a variable using the Selenium "store" command, and start the name of the sensitive variable with “encryptapica". You can use that stored variable anywhere in the scenario:
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.
| |
Step 4: Enter the original Target value.
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 present 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.
Masking Selenium Variables with the “maskapica” Command
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 |
| |
type |
|
|
type |
|
|
clickAndWait |
|
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 then 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 |
|
|
open |
| |
selectWindow |
| |
type |
|
|
type |
|
|
clickAndWait |
|
The command’s target will be masked on the Check Results page when the check is run:
Command | Target | Value |
---|---|---|
store |
|
|
open |
| |
selectWindow |
| |
type |
|
|
type |
|
|
clickAndWait |
|
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. Instead use keyPress
with 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
.
JavaScript Execution
WebDriver’s JavascriptExecutor
will wrap all JS and evaluate it as an anonymous expression. 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
, and 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. For example: Press enter key and wait for new page load
| | |
Return Required
ASM Scenario commands which execute JavaScript snippets expect a returned value. The following commands result in javascript evaluation/expect a javascript snippet as argument, which must include the 'return' keyword at the start of the expression within the “Target” field:
GotoIf
RunScript
RunScriptAndWait
GetEval
StoreEval
StoreExpression
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 JavaScript snippet. This Selenium IDE code will change the value of $counter
:
Command | Target | Value |
|
|
|
The following command will not change the value of $counter
:
Command | Target | Value |
|
|
|
Knowing how to increment a value is useful when running through a loop in an ASM script!