You learned Selenium WebDriver. Automated a few tests, then a few more and more. Also, you learned some advanced tricks, strategies. You are becoming more confident in using it. It feels like there is no test that you can’t automate.
All positive test cases for the regression test suite are automated. You added negative tests. You want to automate everything with Selenium because now you know how to do that.
STOP!
Selenium WebDriver is a tool for automating Web UI tests. Not everything should be automated using Selenium. Let me show you few test cases, where it’s better NOT TO USE Selenium WebDriver, even though it’s possible to do so.
Test Case 1:
Let’s imagine a scenario, where your app sends emails to users, and there are some links in that email. QA needs to make sure all those links in the email work.
You may think that it’s really easy with Selenium:
- Open the browser
- Load Gmail, or some other email app.
- Log in
- Find the email that you need to test using date or keywords,
- Click the link
- Verify it opens a page that it suppose to open.
How many of the test steps are executed on your app, and how many on apps that you don’t control? Only opening the URL with your app is the step, that depends only on you. The rest of the steps is automating a third-party email app (Gmail/Hotmail/Other). So what if UI for the Gmail changes? It breaks your tests. You don’t want to automate apps, that are not under your control.
Besides, all those extra UI steps will slow down test execution.
So, in this case, using Selenium to open an email app and look for your email isn’t the best idea.
It’s better to use Gmail API to find your email and extract the link you need.
And only then use WebDriver to open this link in the browser and do your verification.
Or, if all you need is to make sure URL works, and you don’t need to do any other verification on your page, you don’t even need Selenium.
Get the URL from the email using Gmail API and then just verify it returns status code 200.
Gmail API documentation: https://developers.google.com/gmail/api
Test Case 2:
You have some form on your app. When you fill all fields in your form and then press the submit button, you are getting some results based on the data you provided.
And you already have some tests that verify your form works, and all links on results are working. Now you need to test just your data. Make sure that when you submit specific data, you are getting the correct data back.
And you have tens or hundreds of sets with different data to test.
So first thought, open the browser with the form, type all data, press the submit button to get results, and do verifications. And repeat for each data set.
These tests will be slow. You basically will use UI to test API. Why not just automate API? API tests are much faster and more reliable than UI tests. RESTAssured is a great tool to create a test automation framework for the API tests in Java. (don’t forget to checkout courses I have on RESTAssured and on Selenium WebDriver here)
Test Case 3:
You have a page, your web site sitemap for example. All you have to do is verify that all links on this page work.
Instead of opening that page in the browser and then clicking each link, you can just use jsoup to get all links from the page (https://jsoup.org/), and then HttpURLConnection to verify each link returns Status code 200.
HttpURLConnection con;
try {
con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestMethod("HEAD");
int response = con.getResponseCode();
softAssert.assertTrue(response == 200, "Response code is not 200");
} catch (Exception e) {
softAssert.fail("Couldn't verify url", e);
}
Selenium is a great tool for automating Web UI tests. But not all tests are Web UI tests. If there is a way to execute a test without involving UI interactions, then do it.