Example Selenium scripts
The following Selenium scripts demonstrate how to record a script you can use with Veracode Dynamic Analysis. You can use these scripts as templates.
Example script 1
The following script demonstrates signing in to a web application where the username and password fields are on the same page.
{
"id": "b66324ad-1350-4277-85f1-c48b3800a868",
"version": "2.0",
"name": "Login",
"url": "https://veracode.com",
"tests": [{
"id": "577b18f4-5b2f-49e8-9fc3-e320cd8f00fa",
"name": "Login",
"commands": [{
"id": "03d62bf6-8784-48cc-b319-30e1c809ab11",
"comment": "",
"command": "open",
"target": "/",
"targets": [],
"value": ""
}, {
"id": "81b9dc4d-7c78-49f9-bc4c-9e2186625169",
"comment": "",
"command": "waitForElementVisible",
"target": "id=username",
"targets": [],
"value": "30000"
}, {
"id": "53c5ed70-6548-4e39-b456-d0e5502945d4",
"comment": "",
"command": "type",
"target": "id=username",
"targets": [],
"value": "user1"
}, {
"id": "1b55d2a4-e472-48e6-822d-a5b54a2986d9",
"comment": "",
"command": "type",
"target": "id=password",
"targets": [
["id=password", "id"],
["name=password", "name"],
["css=#password", "css:finder"],
["xpath=//input[@id='password']", "xpath:attributes"],
["xpath=//form[@id='form-login']/div/div[2]/div/div/div/div/div/input", "xpath:idRelative"],
["xpath=//input", "xpath:position"]
],
"value": "abc123"
}, {
"id": "da24efdf-cdd3-4858-b9f8-52e0666b6d73",
"comment": "",
"command": "click",
"target": "id=login-submit",
"targets": [],
"value": ""
}, {
"id": "566c3651-194c-4621-bc87-7f5cb64356fe",
"comment": "",
"command": "waitForElementVisible",
"target": "id=create-space-button-next",
"targets": [],
"value": "30000"
}]
}],
"suites": [{
"id": "e17f2325-4ac8-46d3-8f25-7b087a41d356",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["577b18f4-5b2f-49e8-9fc3-e320cd8f00fa"]
}],
"urls": ["https://veracode.com/"],
"plugins": []
}
Example script 2
The following script demonstrates signing in to a web application where the username and password fields are on separate pages.
{
"id": "b66324ad-1350-4277-85f1-c48b3800a868",
"version": "2.0",
"name": "Login",
"url": "https://veracode.com",
"tests": [{
"id": "577b18f4-5b2f-49e8-9fc3-e320cd8f00fa",
"name": "Login",
"commands": [{
"id": "03d62bf6-8784-48cc-b319-30e1c809ab11",
"comment": "",
"command": "open",
"target": "/",
"targets": [],
"value": ""
}, {
"id": "81b9dc4d-7c78-49f9-bc4c-9e2186625169",
"comment": "",
"command": "waitForElementVisible",
"target": "id=username",
"targets": [],
"value": "30000"
}, {
"id": "53c5ed70-6548-4e39-b456-d0e5502945d4",
"comment": "",
"command": "type",
"target": "id=username",
"targets": [],
"value": "user1"
}, {
"id": "d2ba43a8-e109-415a-a2be-0b19e9ffef75",
"comment": "",
"command": "click",
"target": "id=login-submit",
"targets": [],
"value": ""
}, {
"id": "4f9104fd-0f7f-4aeb-885f-b27b1eca4363",
"comment": "",
"command": "waitForElementVisible",
"target": "id=password",
"targets": [],
"value": "30000"
}, {
"id": "1b55d2a4-e472-48e6-822d-a5b54a2986d9",
"comment": "",
"command": "type",
"target": "id=password",
"targets": [
["id=password", "id"],
["name=password", "name"],
["css=#password", "css:finder"],
["xpath=//input[@id='password']", "xpath:attributes"],
["xpath=//form[@id='form-login']/div/div[2]/div/div/div/div/div/input", "xpath:idRelative"],
["xpath=//input", "xpath:position"]
],
"value": "abc123"
}, {
"id": "da24efdf-cdd3-4858-b9f8-52e0666b6d73",
"comment": "",
"command": "click",
"target": "id=login-submit",
"targets": [],
"value": ""
}, {
"id": "566c3651-194c-4621-bc87-7f5cb64356fe",
"comment": "",
"command": "waitForElementVisible",
"target": "id=create-space-button-next",
"targets": [],
"value": "30000"
}]
}],
"suites": [{
"id": "e17f2325-4ac8-46d3-8f25-7b087a41d356",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["577b18f4-5b2f-49e8-9fc3-e320cd8f00fa"]
}],
"urls": ["https://veracode.com/"],
"plugins": []
}
Example script 3
The following script demonstrates signing in to a web application with multi-factor authentication (MFA) enabled using the TOTP scanner variable.
{
"id": "68c1e8b0-d794-4b37-a7c6-793eb8a434dc",
"version": "2.0",
"name": "Login_TOTP",
"url": "<appURL>",
"tests": [{
"id": "d084a794-2ca2-48ce-bb5c-a4638eeb1f94",
"name": "Login",
"commands": [{
"id": "8b2550d6-ee29-4230-9ccd-f44798a2407a",
"comment": "",
"command": "open",
"target": "<loginPath>",
"targets": [],
"value": ""
}, {
"id": "439e6617-c4d8-49d7-8073-54f638aafc21",
"comment": "",
"command": "waitForElementPresent",
"target": "name=user",
"targets": [],
"value": "30000"
}, {
"id": "3c0db2ff-db10-4fcd-8d43-a2c7438e8e1e",
"comment": "",
"command": "type",
"target": "name=user",
"targets": [
["name=user", "name"],
["css=tr:nth-child(1) .form-control", "css:finder"],
["xpath=//input[@name='user']", "xpath:attributes"],
["xpath=//div/input", "xpath:position"]
],
"value": "<user-totp>"
}, {
"id": "ee4e1cc9-f9ff-4119-ad3e-b3d3cda39824",
"comment": "",
"command": "type",
"target": "name=password",
"targets": [
["name=password", "name"],
["css=tr:nth-child(2) .form-control", "css:finder"],
["xpath=//input[@name='password']", "xpath:attributes"],
["xpath=//tr[2]/td[2]/div/input", "xpath:position"]
],
"value": "<password>"
}, {
"id": "55f3d219-a84f-471d-a13e-41638ad396dc",
"comment": "",
"command": "click",
"target": "id=login",
"targets": [
["id=login", "id"],
["name=Login", "name"],
["css=#login", "css:finder"],
["xpath=//button[@id='login']", "xpath:attributes"],
["xpath=//button", "xpath:position"],
["xpath=//button[contains(.,'Login')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "9840bd4c-52b8-4df8-9b8c-dc7c3bf71b6e",
"comment": "",
"command": "waitForElementPresent",
"target": "name=totpcode",
"targets": [],
"value": "30000"
}, {
"id": "14b8ff3c-05e8-4dbb-a824-2d6dcf39988d",
"comment": "",
"command": "type",
"target": "name=totpcode",
"targets": [
["name=totpcode", "name"],
["css=.form-control", "css:finder"],
["xpath=//input[@name='totpcode']", "xpath:attributes"],
["xpath=//input", "xpath:position"]
],
"value": "${TOTP_SECRET}"
}, {
"id": "7c0231b6-84f6-4229-9d0b-928f8df5a378",
"comment": "",
"command": "click",
"target": "id=submit",
"targets": [
["id=submit", "id"],
["name=Submit", "name"],
["css=#submit", "css:finder"],
["xpath=//button[@id='submit']", "xpath:attributes"],
["xpath=//button", "xpath:position"],
["xpath=//button[contains(.,'Submit')]", "xpath:innerText"]
],
"value": ""
}, {
"id": "5218f117-7594-45f9-b0fe-31ac08144ddf",
"comment": "",
"command": "waitForElementPresent",
"target": "id=<PageElementID>",
"targets": [],
"value": "30000"
}]
}],
"suites": [{
"id": "34ea279e-bdb6-4c97-b562-1c06635c7898",
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["d084a794-2ca2-48ce-bb5c-a4638eeb1f94"]
}],
"urls": ["<appURL>"],
"plugins": []
}