Advice on Self-Learning Test Automation with Selenium WebDriver
Self-Learning web test automation is possible, here are my practical tips
This is also included in my “How to in Selenium WebDriver” series.
Now and then, I receive requests for advice on learning test automation. The most effective way is to work with a real test automation mentor. For most, that might not be possible (unable to find one or unwilling to pay coaching fees). However, you can self-learn test automation. Here is my advice:
1. Make your mind on the test framework, not the tool
I highly recommend Selenium WebDriver + RSpec. Don’t fall into record/playback testing tools. Though they have existed for over 20 years, history has proved they were wrong. Still, ‘new’ test automation tools in a form of record-playback come out and die every year.
Selenium WebDriver unquestionably dominates browser testing for a simple reason: Selenium WebDriver is a W3C standard. So you shall use Selenium WebDriver, period.
2. Scripting
Automated tests need to be in a scripting language, such as Ruby. Don’t fall into a fancy demo of testing tools. History tells us that GUI-heavy tools (such as QTP) were no good. Automated tests need to be very flexible, only a scripting programming language can offer that. That’s also why Selenium WebDriver defeated commercial web testing tools from big vendors.
If you don’t know Ruby, even if you are already very comfortable with another programming language such as Java/JavaScript/C#, I would strongly recommend you try Ruby. The actual Ruby/RSpec knowledge required for basic automated test scriptwriting is not much at all.
For more reasons to use Ruby for test automation, check out this article: “Which Selenium WebDriver Language Binding is the Best?”
My recommendation is objective and informed, I have written a book for each of Selenium’s official language bindings: Ruby, Java, Python, Node.js and C#.
After attending my one-day Selenium training, most attendants (without selenium, automation or ruby knowledge) can start working on real tests the next day, under mentoring. Find it hard to believe, check out this article: Selenium WebDriver is the Easiest-to-Learn Web Test Automation Framework (including a screencast video).
3. Learn Selenium syntax gradually
Selenium WebDriver is very easy to learn, because it follows an intuitive pattern:
Example test steps:
driver.find_element(:link, "Sign In").click
driver.find_element(:id, "username").send_keys("agileway")
driver.find_element(:name, "password").send_keys("testwise")
driver.find_element(:id, "sign-btn").click
Read this article, and do some quick practices. You will find that you can use Selenium to do something useful in a very short time, in minutes. Don’t try to remember selenium syntax first, definitely get hands-on within the first half hour.
Like any skill, mastering will take some time. Learning Selenium can be very quick. In Test automation, not much theory, the target is clear: “find an element, drive it”. Just do it, you will grow confidence and find fun and motivation to do more.
Commonly, a tester started wrongly, such as with Java, TestNG and Cucumber. Yes, Selenium can work with them (actually those are bad choices), but why bother with new terminologies, such as compiling, annotation, interpretation layer, …, etc.? Those are not test automation, nor Selenium. The solution is simple: just write direct selenium scripts (note here, in a scripting language, such as Ruby) and run them quickly (in a testing tool, not a coding tool).
4. Read practical books
There are plenty of free online tutorials. For learning, however, I would suggest starting with a book. Google is super useful for finding specific information or solution. When it comes to learning and mastering a new skill set, a continuous flow of well-organized knowledge and practices are required. This is the same reason that textbooks are still a must for school students.
Common issues with many test automation books:
Wrong.
This is unfortunate. The fact that the authors have probably never seen one software project running automated UI regression testing daily (like the example here), even though many talk about it. This simply means: they are doing fake test automation. For example, prioritizing test scripts might be OK for manual testing, but not applicable for automation at all. The reason: if automated tests are not run often, they will be out-of-date, and you might as well delete them.
Too much theory.
The objective of web test automation is simple (regardless of opinions) and web technologies have been static for years: HTML+JavaScript+CSS. Dumping different testing jargon, such as exploratory testing and agile testing, does not help (actually confuses) new-to-automation testers.Not practical.
Testing is practical by nature. Being practical can keep the reader’s interest. Also, testing is about feedback, if you don’t see test execution or do not receive feedback quickly, you probably are doing it wrong.
I recommend ‘Practical Web Test Automation’ and ‘Selenium WebDriver Recipes’, which were written by me and used in my training, some might think I am promoting my books here, but that’s not my intent. (Try the sample chapters first; Also, Leanpub offers a 60-day happiness guarantee)
My two books are listed in top 10 Best-Selling Selenium eBooks of All Time by Book Authority.
These books are extracts from my 15 years of experience in web test automation, and I have used them to mentor many testers with great outcomes. Of course, there are alternatives, but remember that a good test automation book is light in theory. Too much theoretical stuff might hinder your journey to successful test automation.
5. Practise on a demo site
New-to-automation testers need to practice their skills on demo sites, to enforce the skills and habits to develop a test-automation mindset. Here are two demo sites I have created: free to use.
Agile Travel: https://travel.agileway.net, a very simple mock travel site, covers all basic HTML controls and AJAX and has already been featured in the Practical Web Test Automation book.
Sandbox WhenWise: https://whenwise.agileway.net, WhenWise is a modern service booking web app including many common modules such as user authentication, user management, booing, invoice, and reporting.
6. Tools
I recommend using TestWise (Disclaimer: I created TestWise; TestWise may be used in free mode with a limit on test execution count). Many people are confused between frameworks and tools. For example, C# is a language/framework, while Visual Studio is a tool.
Framework makes it work; Tool helps you be productive. Don’t let a tool to control you! — Zhimin Zhan
I started to create TestWise (formerly known as itest2, listed by Lisa Crispin, Agile Testing book author, as the first tool in her presentation) in 2006. Since then, I have been using TestWise almost every working day as a consultant, dev lead, tester, business analyst, manager, and product owner. The features of TestWise such as ‘ Run selected test steps against current browser’, Snippets, and Test refactoring can easily save tester hours of work on a day.
If you have your own preferred tool, such as Visual Studio Code, which is fine. Do spend some time mastering the tool, and use it efficiently, which you need when maintaining a large number of automated tests.
7. Start writing automated tests for your work
What a tester, who is new to test automation, really wants is that she/he can write real automated tests for the work at the end of the day. During my mentoring, I meant ‘the end of the first day’ literally, i.e. on the afternoon of the first day of mentoring, the testers could start to write the real test scripts for their assigned user stories. I just love to see the smile on their faces when they accomplish it. Almost everyone said, “it is far easier than previously thought, it is fun!”. Of course, they need to learn more to be fully independent, few can master XPath and regular expression within one day, and it is often unnecessary for beginners. They can learn these gradually. The important thing is that they could write real Selenium WebDriver test scripts with confidence, and fun!
This does not mean test automation is easy, far from that, writing test scripts is just the first step, and it is the easiest. Maintaining automated test scripts is a lot harder. If a tester is unable to learn to write test scripts within 1 or 2 days, the chance to master test script maintenance is slim.
8. Set up test executions in a Continuous Testing server
You shall always run all tests frequently, at least twice a day. When you have about 10 test cases, it is not practical to run them in your testing IDE/editor. Set up a continuous testing process to execute all tests in a CT server. Avoid CI servers such as Jenkins and Bamboo, as they were built for executing unit tests.
If you are unable to find a suitable CT server, I recommend the award-winning BuildWise, a free and open-source CT server created by me. Setting up BuildWise usually takes under 30 minutes. Refer to my other book “Practical Continuous Testing — make Agile/DevOps real” for more.
9. Maintain automated tests with daily runs of all automated tests.
This is the toughest task, comparing test creation and setup CT, as you need to act with extremely high efficiency. Many people did not realize that, because they never saw a single case of successful test automation. Imagine you are the engineer (usually the best engineer in the top companies) assigned to do this task. Every day, you need to
Trigger a run in the CT server
Analyze test failures
- if it is an infrastructure error, try to fix it or inform others
- if it is an incorrect/out-of-date test script, update the test script, check it in, trigger another build
- if it is a real bug, inform the developers
Another build is coming, and any one of the automated test suites could fail …
Remember, you must handle all the tests from Sprint 1 (and every sprint). Some now might realize that’s an impossible mission. No, it is possible, for real test automation engineers (who are rare). In fact, you have heard of this growingly popular term “In-Sprint Test Automation”. Check out this “great CI/DevOps Presentation: ‘Continuous Integration at Facebook’ ”. You will be impressed.
In summary, it is possible to self-learn Test Automation and Continuous Testing. Many engineers I mentored gave it up later on, as they found much easier and higher-paid jobs (generally after one engineer started doing test automation, his/her understanding of software development will excel the peers). For those who want to devote themselves to test automation and CT, you may use AgileWay Continuous Testing Grading as the guide for improvement.