Browser testing with Selenium IDE scripts
Use a Selenium IDE script (also called side script) to simulate user interactions with your web applications.
Selenium IDE script test is one type of Instana Synthetic browser script tests.
You are recommended to begin with a simple Selenium IDE script as described in the Recording a Selenium IDE script section.
Then, you can use the advanced capabilities that are provided by Instana Synthetic as described in the Expanding testing capabilities in Selenium IDE scripts section.
Recording a Selenium IDE script
-
Download and install the Selenium IDE Firefox addon or Chrome extension in Firefox or Chrome browser. Then, restart the browser.
-
Open Selenium IDE from the menu bar. Click
Record a new test in a new project
link, and record a script by following the instructions.When Selenium IDE is recording, it generates a command for each user action in a script.
-
After recording, save the script into a
.side
file. -
You can add commands like
assert title
or test your script with the run button.
For more information, see Selenium IDE Get Started.
You can also use the Selenium IDE Firefox addon or Chrome extension to test or debug the recorded script.
Note:
-
You can customize the timeout values in Selenium IDE. If no timeout values are provided, the default values are used:
-
Instana supports only serialized tests, and thus the following properties in the Selenium IDE scripts are overwritten by the Instana browser playback engine:
- "persistSession": false
- "parallel": false
Example
In the following example, the Selenium IDE script is used to search for Instana keywords in a search engine:
{
"id": "9ed7eb47-bf16-42aa-a486-0c7d99182726",
"version": "2.0",
"name": "Search-Instana",
"url": "https://www.google.com",
"tests": [{
"id": "d968da10-6c9f-467f-ba5c-dbe5135dab17",
"name": "search instana",
"commands": [{
"id": "c6ccc11f-aab7-49b4-af71-6315647370da",
"comment": "",
"command": "open",
"target": "/",
"targets": [],
"value": ""
}, {
"id": "99075bf4-411e-4351-804d-e78f5d83824e",
"comment": "",
"command": "type",
"target": "name=q",
"targets": [
["name=q", "name"],
["css=.gLFyf", "css:finder"],
["xpath=//input[@name='q']", "xpath:attributes"],
["xpath=//input", "xpath:position"]
],
"value": "instana"
}, {
"id": "9f1b06f4-1cfb-4381-9566-2399742a46c2",
"comment": "",
"command": "sendKeys",
"target": "name=q",
"targets": [
["name=q", "name"],
["css=.gLFyf", "css:finder"],
["xpath=//input[@name='q']", "xpath:attributes"],
["xpath=//input", "xpath:position"]
],
"value": "${KEY_ENTER}"
}, {
"id": "d13e50bd-f698-4a04-9420-701a21dcde8d",
"comment": "",
"command": "waitForElementVisible",
"target": "id=result-stats",
"targets": [
["id=result-stats", "id"],
["css=#result-stats", "css:finder"],
["xpath=//div[@id='result-stats']", "xpath:attributes"],
["xpath=//div[@id='slim_appbar']/div/div", "xpath:idRelative"],
["xpath=//div[7]/div/div/div/div/div", "xpath:position"]
],
"value": "5000"
}]
}],
"suites": [{
"id": "76395644-9101-473c-ad42-bda5c37e8de2",
"name": "Search Instana",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["d968da10-6c9f-467f-ba5c-dbe5135dab17"]
}],
"urls": ["https://www.google.com/"],
"plugins": []
}
Expanding testing capabilities in Selenium IDE scripts
Instana Synthetic browser testing provides more capabilities than Selenium IDE:
-
Instana Synthetic provides rich test results, which include HTTP Archive format (HAR) files, screenshots, recordings, browser logs, and console logs.
-
Instana Synthetic provides more advanced browser testing APIs and global variables.
If you want to modify your Selenium IDE scripts with advanced browser testing APIs and global variables that are provided by Instana Synthetic, refer to the following examples:
-
Use global environment variables in your test.
You can use
$synthetic.xxxx
,$secure.xxx
, or$env.xxx
to access global variables as in the following example.To use variables in template strings such as the
echo
command, use standard Node.js syntax, and put the variables in${}
.{ "id": "da853ea2-7253-4938-ad2d-9272f4c6d3e2", "comment": "", "command": "echo", "target": "tag1's value is ${$synthetic.tag1}", "targets": [], "value": "" }, { "id": "9540edee-f041-42b1-aeb3-e2142a7fcbd7", "comment": "", "command": "assert", "target": "$synthetic.tag1", "targets": [], "value": "value1" }
-
Use the Selenium commands
runScript
andexecuteScript
to invoke advanced browser testing APIs.You can use the Selenium commands
runScript
andexecuteScript
to invoke predefined browser testing APIs and global variables in Instana Browser Testing.The difference between
executeScript
andrunScript
is thatexecuteScript
supports storing the returned value in a variable. You can thenassert
orecho
the variable with${xxx}
. To store the returned value, use thereturn
keyword, and provide a variable name in the value input field.{ "id": "9cd35362-8d78-4bd2-a32b-f81d40362af2", "comment": "browser_script_api_authentication_executeScript", "command": "executeScript", "target": "return $browser.setAuthentication(\"user1\", \"pass1\")", "targets": [], "value": "authentication_result" }, { "id": "1401608a-3892-4be0-9b4c-63c0fb0a1b87", "comment": "echo authentication result", "command": "echo", "target": "This is my authentication result: ${authentication_result}", "targets": [], "value": "" }
-
Define an environment variable, and use it in the browser testing APIs.
{ "id": "10d09a25-d101-43b0-84df-f22265b7cec6", "comment": "proxy_store_json", "command": "storeJson", "target": "{\"proxy\": \"<proxy_server>:8080\", \"noproxy\": \"localhost,google.com,192.168.1.0/24\"}", "targets": [], "value": "proxyConfig" }, { "id": "237bd334-d963-4a73-b9bb-4c31f1dce051", "comment": "browser_script_api_proxy_runScript", "command": "runScript", "target": "await $browser.clearProxy(); await $browser.setProxy(${proxyConfig.proxy}, ${proxyConfig.noproxy});", "targets": [], "value": "" }
-
Use the
$network
API to set a proxy.{ "id": "a418460e-a0a9-4c68-bbd0-fb78d6495e92", "comment": "browser_script_api_$network", "command": "runScript", "target": "await $network.clearProxy(); await $network.setProxy(${proxyConfig.proxy}, ${proxyConfig.noproxy});", "targets": [], "value": "" }
-
Use the
$attributes
API to customize attributes.{ "id": "26438c58-868d-4d6d-9e6f-dbe9d8f373fd", "comment": "browser_script_api_$attributes", "command": "executeScript", "target": "$attributes.set(\"name\", \"user1\"); return $attributes.get(\"name\")", "targets": [], "value": "user_name" }, { "id": "1d760093-15a2-44ed-ac41-00a08f67ed8b", "comment": "echo user insights result", "command": "echo", "target": "This is my user name: ${user_name}", "targets": [], "value": "" }
Example
In the following example, Selenium commands invoke Instana browser testing APIs and global variables.
Note: Replace the variable <proxy_server> with your actual proxy server.
{
"id": "04e7ae01-927d-4937-acbd-f35f5f8de715",
"version": "2.0",
"name": "search-engine",
"url": "https://www.google.com",
"tests": [{
"id": "868fa683-e289-47bb-82de-c347c99d9ba8",
"name": "search instana",
"commands": [{
"id": "10d09a25-d101-43b0-84df-f22265b7cec6",
"comment": "proxy_store_json",
"command": "storeJson",
"target": "{\"proxy\": \"<proxy_server>:8080\", \"noproxy\": \"localhost,192.168.1.0/24\"}",
"targets": [],
"value": "proxyConfig"
}, {
"id": "a418460e-a0a9-4c68-bbd0-fb78d6495e92",
"comment": "browser_script_api_$network",
"command": "runScript",
"target": "await $network.clearProxy(); await $network.setProxy(${proxyConfig.proxy}, ${proxyConfig.noproxy});",
"targets": [],
"value": ""
},{
"id": "71ac6b1c-fbeb-48d1-80d1-3960862fc577",
"comment": "",
"command": "open",
"target": "/",
"targets": [],
"value": ""
}, {
"id": "99075bf4-411e-4351-804d-e78f5d83824e",
"comment": "",
"command": "type",
"target": "name=q",
"targets": [],
"value": "instana"
}, {
"id": "9f1b06f4-1cfb-4381-9566-2399742a46c2",
"comment": "",
"command": "sendKeys",
"target": "name=q",
"targets": [],
"value": "${KEY_ENTER}"
}, {
"id": "d13e50bd-f698-4a04-9420-701a21dcde8d",
"comment": "",
"command": "waitForElementVisible",
"target": "id=result-stats",
"targets": [],
"value": "5000"
},{
"id": "46eb59c2-5fd6-4481-b3e8-eaaddab79a69",
"comment": "",
"command": "assertTitle",
"target": "instana - Google Search",
"targets": [],
"value": ""
}]
}],
"suites": [{
"id": "a4b81281-f8cf-4870-b802-668af4ee5f04",
"name": "Advanced APIs",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["868fa683-e289-47bb-82de-c347c99d9ba8"]
}],
"urls": ["https://www.google.com/"],
"plugins": []
}