It took me a while to figure out how to get Selenium IDE to click a link, wait for the new tab's page-load to settle down, and validate the URL of the new page, but I did it.
Overall, I'm pretty satisfied with Selenium IDE. If you have business processes that involve visiting a web site and clicking around a bunch to "make sure everything looks good," it's a nifty tool for pretending to be yourself, only sped up really really fast.
Steps
The one and only test present in this Selenium IDE project runs through 8 steps:
- Open the Katie Kodes page on Ko-Fi
- Command:
open
- Target:
katiekodes
(on top of a test base URL ofhttps://ko-fi.com/
)
- Command:
- Click the Katie Kodes blog link
- Command:
click
- Modify new window configuration -> New Window Configuration Enabled: checked, Window Name:
blog_new_tab
, Timeout: 2000, click "Confirm" - Target:
xpath=(//a[@target="_blank" and contains(@href, "katiekodes.com")])[1]
- Command:
- Close the original Ko-Fi tab
- Command:
close
- Command:
- Make sure we are viewing the new blog tab
- Command:
select window
- Target:
handle=${blog_new_tab}
- Command:
- Wait for something bloggey to be on the screen
- Command:
wait for element present
- Target:
xpath=(//a[contains(@href, "ko-fi.com")])[1]
- Value:
30000
- (Technically, this isn't required for this example, but the situation I was dealing with opened a new tab and then handed off cookies through about 4 different URLs before settling down on one, so I decided to validate that things were "all done" by looking for a weird, distinctive HTML element I knew only existed in the final, settled page.)
- Command:
- Save the blog URL to a variable
- Command:
execute script
- Target:
return document.URL;
- Value:
theurl
- Command:
- Assert that the blog URL is correct
- Command:
assert
- Target:
theurl
- Value:
https://katiekodes.com/
- Command:
- Close the web browser
- Command:
close
- Command:
Code
To try it yourself, save this code as Selenium Demo.side
on your computer and open it as a project with the Selenium IDE browser plugin, then click the "Validate the new-tab URL" test and click "Run current test."
{
"id": "ca2c89aa-50b1-4eea-91e6-c2e01ae6cb0a",
"version": "2.0",
"name": "Selenium demo",
"url": "https://ko-fi.com/",
"tests": [{
"id": "e363b287-2838-40db-b1b8-57dd100af3a5",
"name": "Validate the new-tab URL",
"commands": [{
"id": "712005e0-c6ec-4f10-9162-da97499d5e23",
"comment": "Open Katie Kodes Ko-Fi donations page",
"command": "open",
"target": "katiekodes",
"targets": [],
"value": ""
}, {
"id": "9eaf4f01-f179-4c19-855c-4eb9a1968158",
"comment": "Click the Katie Kodes blog link",
"command": "click",
"target": "xpath=(//a[@target=\"_blank\" and contains(@href, \"katiekodes.com\")])[1]",
"targets": [],
"value": "",
"opensWindow": true,
"windowHandleName": "blog_new_tab",
"windowTimeout": 2000
}, {
"id": "3c0233e1-b2d4-4c82-b806-7d9133e94e96",
"comment": "Close the original Ko-Fi tab",
"command": "close",
"target": "",
"targets": [],
"value": ""
}, {
"id": "5683db68-8b78-48a7-b959-84ebccd70119",
"comment": "Make sure we are viewing the new blog tab",
"command": "selectWindow",
"target": "handle=${blog_new_tab}",
"targets": [],
"value": ""
}, {
"id": "a37060a8-8e9b-4848-9068-f4a1fcb5f2ca",
"comment": "Wait for something bloggey to be on the screen",
"command": "waitForElementPresent",
"target": "xpath=(//a[contains(@href, \"ko-fi.com\")])[1]",
"targets": [],
"value": "30000"
}, {
"id": "ff897cc8-d4f0-4762-8695-d9551d7f4e96",
"comment": "Save the blog URL to a variable",
"command": "executeScript",
"target": "return document.URL;",
"targets": [],
"value": "theurl"
}, {
"id": "b3b8f50b-4266-4c68-902b-33e150279274",
"comment": "Assert that the blog URL is correct",
"command": "assert",
"target": "theurl",
"targets": [],
"value": "https://katiekodes.com/"
}, {
"id": "68c8b88e-84bb-4c80-b914-3a0278995967",
"comment": "Close the web browser",
"command": "close",
"target": "",
"targets": [],
"value": ""
}]
}],
"suites": [{
"id": "398fd234-8bcf-48ff-ab6c-4785b1ab469f",
"name": "My first suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["e363b287-2838-40db-b1b8-57dd100af3a5"]
}],
"urls": ["https://ko-fi.com/"],
"plugins": []
}
Top comments (0)