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 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

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

select

setLocation

doubleClickAndWait

assertValue

waitForTextNotPresent

storeAttribute

selectAndWait

doubleClickAtAndWait

assertNotValue

waitForElementPresent

storeElementPresent

selectFrame

clickInvisible

assertText

waitForEditable

store

selectWindow

clickInvisibleAndWait

assertTextNotPresent

waitForElementNotPresent

submit

setLocation

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, 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

...

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. 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 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 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. 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. Instead use keyPress with 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 JS JavaScript and evaluate it as an anonymous expression. This means that you need to use Therefore, 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

...

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}

...

>

...

true

WebDriver

...

assertEval

...

0 is true, use the following code:

Command

Target

Value

assertEval

return ${stored_var}

>

0

\}\}

true

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

...

keyPressAndWait

...

id=gh-ac

...

\13

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

StoreExpressionThe 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 JavaScript snippet. This Selenium IDE code will change the value of $counter:

Command

Target

Value

 storeEval

return (storedVars'counter' + 1)

counter

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”.