Check a URL with Selenium IDE
06 Apr 2022
Table of Contents
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 donations page on Ko-Fi
- 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.”
Selenium IDE caveats
Test design
It helps a lot to understand both “how the web site you’re testing supposed to work” and a good deal of HTML.
Right-clicking on, say, a link in Selenium IDE’s recorder and telling it that you want to verify that it’s labeled “Hello World” is kind of useless when the Selenium IDE recorder decides that it should select the link by … looking for the link that says “Hello World.”
(Meaning if the test fails, it fails because it can’t find the link, not because it says the wrong thing. D’oh.)
So being able to do a little surgery in Selenium IDE to improve the “selector” for the HTML element you’re interested in is useful.
It also helps not to be completely overwhelmed by small bits of JavaScript, because things like “Validate the contents of the URL I’m now on” doesn’t come with Selenium IDE’s commands – instead you have to write 3 words of JavaScript code to get the URL of whatever page Selenium IDE is visiting on your behalf.
Team use
Even if not every tester on your team both understands the product and understands HTML, the tool is free and maintained by the official Selenium project, so maybe just one person could design the .side
file and then share it around with everyone else.
Even if some tests fail because every tester’s experience of a site might be a little different, as long as they understand that and you’ve labeled the tests & their steps well enough for them to be able to troubleshoot, “Oh, that makes sense that that failed for me,” it should still be better than nothing.
Suites of tests run all the tests even if one test fails, so it’s not like things are going to “get stuck” if one or two tests fail.
Test execution
Selenium IDE, at least as run as a Chrome plugin, just piggybacks on your current Chrome state, including cookies of sites you’re logged into, and opens new tabs for each test it runs.
So it works well for testing sites that you have to be logged into, as long as you leave a browser window open in the background that you’ve already logged into the site.
If half the battle is getting logged in, Selenium IDE won’t make your life much better. But if, once you’re in, you have dozens or hundreds of parts of the site to click around, you might really like Selenium IDE.
Security
Speaking of testing web sites behind login-walls…
Software is only as secure as the good intentions of the people who publish it.
While these browser plugins are maintained by a well-respected open-source project, even open-source projects are only as good as the careful review of the gatekeepers accepting “volunteer contributions.”
If you install any plugin into a web browser, it’s pretty much now you on the web. As long as you install a version that’s in good shape, it won’t do anything weird like “phone home” exfiltrating data like your passwords … but … y’know, if you accidentally install a hacked update … it could. So give it its due skepticism at work and maybe have a colleague who can actually understand the browser plugin’s codebase do a quick look-over to make sure the plugin still isn’t doing anything weird when you get ready to install it.
Further reading
- Selenium IDE Tutorial Getting Started Guide by Joe Colantonio
- Web App Testing, Selenium IDE Is Back by Lance Cleveland
- Selenium IDE Tutorial (No Coding Automation) by Vaneesh Behl
- 16 reasons why to use Selenium IDE in 2021 by Michael Battat