Why Selenium WebDriver is So Easy to Learn?
Raw Selenium WebDriver is the most easy-to-learn web automation framework.
I will give my conclusion first. Raw Selenium WebDriver, besides being the most reliable and feature-complete, is also the easiest-to-learn test automation framework.
Table of Contents:
· How long does it take to learn Selenium WebDriver?
· Reason 1: Intuitive
∘ Step 1: Find a web control (also known as element)
∘ Step 2: perform an action on it.
· Reason 2: Can use Ruby as the scripting language
· Reason 3: Can use RSpec as the syntax framework
· Reason 4: There is TestWise Functional Testing IDE
· Learning Effectively
· Q & A
How long does it take to learn Selenium WebDriver?
Let’s see the conventional answer on Google Search:
The second-ranked result: “We can learn selenium normally in 3 months”
However, this is not right, it is way too long! The reason is that many people learned test automation wrongly or from the wrong person. The fact: real test automation engineers are extremely rare.
“95% of the time, 95% of test engineers will write bad GUI automation just because it’s a very difficult thing to do correctly”.
- this interview from Microsoft Test Guru Alan Page (2015)
Then, how long exactly will it take to learn Selenium WebDriver? My answer is 2–4 hours. Surprised? I have actually proved it a number of times via my one-day training: Web Test Automation with Selenium WebDriver. Most of the attendants to my training are manual testers who have no automation and programming experience.
Please note, my one-day training covers much more than Selenium WebDriver. It includes the RSpec syntax framework, maintainable test design, functional test refactoring, …, etc. The training content can be viewed here.
Learning ≠ Mastering
Mastering any skill well will take some time. However, if a learner can start using the newly acquired knowledge to do some real work (though it will be still rough on the edges), in my opinion, it will definitely be an effective learning.
Yes, 2–4 hours is the time, under proper guidance, a manual tester takes to learn to use Selenium effectively.
Reason 1: Intuitive
Any skill, regardless of how simple it appears to be, if not intuitive, is hard to learn. On the other hand, traffic rules are quite complex (my state’s driver handbook is over 180 pages), but everyone finds it easy to learn. The reason, most of the traffic rules are intuitive.
Selenium WebDriver’s main syntax follows
Step 1: Find a web control (also known as element)
How? Easy, and you don’t need an extra tool, just use the browser. Right-click the element in Chrome and select ‘Inspect’.
The HTML fragment will be shown on the right panel. Anyone with basic HTML knowledge (if not, can be taught in minutes) will understand.
Remember, we don’t need to understand all HTML syntax or strong programming knowledge, just a very small part of that is required for test automation.
Choose one of 8 Selenium locators, such as id
, name
, and others. The selenium (ruby) statement to locate the user name control can be
driver.find_element(:id, "username")
or
driver.find_element(:name, "username")
Step 2: perform an action on it.
After locating the control, we perform an appropriate action on it. For example, clicking a hyperlink or button, sending keys to a text box, …, etc.
The statement for entering the above text is
driver.find_element(:id, "username").send_keys("gotyou")
Some might wonder: how to clear the existing text in the text box?
driver.find_element(:id, "username").clear
driver.find_element(:id, "username").send_keys("gotyou")
Now have a look at the scripts below:
driver.get("https://travel.agileway.net")
driver.find_element(:id, "username").send_keys("agileway")
driver.find_element(:name, "password").send_keys("testwise")
driver.find_element(:xpath, "//input[@value='Sign in']").click
It is pretty easy to understand, isn’t it?
Some might argue that this is only a HelloWorld-level test. What about those complex scenarios?
Can you guess what the below scripts do?
elem = driver.find_element(:id, "comments")
elem.send_keys("multi Line\r\n Text")
driver.action.click(elem)
.key_down(:control)
.send_keys("a")
.key_up(:control)
.send_keys(:backspace)
.perform
Most people (who came to my training and were new to test automation or selenium) guessed it correctly: “Select All and Delete”. The last step is “Advanced User Interactions” syntax in Selenium.
Reason 2: Can use Ruby as the scripting language
Ruby is the best programming language for scripting automated tests, period. I am probably more objective than most people as My Selenium Recipes Book series covers all these five languages.
Don’t just take my word for it. Lisa Crispin and Janet Gregory wrote this down in their classic ‘Agile Testing’ book in 2009.
It is a pity that most test automation attempts chose the wrong language such as Java and JavaScript. For most software projects, in reality, whichever language your tech lead/test architect knows will be selected, sadly.
Java is not a scripting language. We call test scripts for a very good reason. JavaScript is another popular wrong choice, usually by programmers who think they know a little about automated testing. Many people did not know that JavaScript has a poor reputation in test automation. For example, Phantom JS was deprecated (in 2017), Protractor has been deprecated, Cypress had too many limitations. For more on this, check out this article: Why JavaScript Is Not a Suitable Language for Real Web Test Automation?
A common mistake is that the projects that tend to choose the coding language for scripting automated tests. I often heard: “Our app is developed in React.js, so we chose JavaScript for scripting automated tests.” This is very wrong. I have successfully developed numerous automated tests in Ruby for apps developed in Java, C#, Python, Ruby, and JavaScript. The interface of End-to-End UI tests is the HTML in a browser, which has nothing to do with the code behind it. The audience of automated test scripts are the whole team + customers, not programmers.
Choose Ruby for your automation testing. It will be much easier and more fun!
Reason 3: Can use RSpec as the syntax framework
Selenium WebDriver is an automation framework, it drives browsers.
Test Automation Framework = Automation Framework + Test Syntax Framework
Test syntax framework provides structure and assertions. The examples are RSpec, JUnit, and Cucumber. For its simplicity, I would strongly recommend RSpec.
Below is a typical RSpec test script containing two test cases. I usually need to explain one thing, The it "..." do
to end
marks a test case.
Can you guess the output?
Easy, right?
A common mistake is to use the Gherkin style BDD framework (e.g. Cucumber and SpecFlow) as the test syntax. For more, please check out my other article: Why Gherkin (Cucumber, SpecFlow,…) Always Failed with UI Test Automation?
Reason 4: There is TestWise Functional Testing IDE
New-to-test automation engineers don’t often know what to start which is normal. They might have looked up some tutorials online. But it would not be easy to put all pieces together.
Install Language runtime, such as Ruby, JDK, Node.js or Python
Install Selenium WebDriver library
Install test syntax frameworks such as RSpec or Mocha, and other supporting libraries
Install ChromeDriver
If all of the above is done correctly, it only means that you can run Selenium tests now. There will be more to consider:
What tool to use to edit, run, or debug test scripts?
Test Project structure?
Sample test projects?
Instructions to create a new test project for work?
With TestWise IDE, however, you don’t need to worry about the above at all. You can get all set up in minutes. Check out my daughter’s article: “Set up Running Automated UI tests on your First day at work”.
Disclaimer: I created TestWise, a dedicated functional testing IDE designed from the ground up. I have been using it on a daily basis since 2007.
TestWise (former name: iTest2) was demonstrated at Agile 2009 conference’s AAFTT workshop in Chicago, listed as the first testing tool by Agile testing book author Lisa Crispin, and a finalist in the 2010 Ruby Award.
TestWise may be used in either free or licensed mode, both fully featured. In free mode, users are limited to 15 test executions per launch. Once the limit is reached, you can simply relaunch TestWise (which takes ~3 seconds) to restart the counter. Please note, TestWise only supports free and open-source automation frameworks such as Selenium and Appium, and test scripts are in plain text. Therefore, there is no vendor locking at all. You are free to change and use another coding editor.
If you are interested, check out some of the TestWise features.
Test AJAX Properly and Efficiently with Selenium WebDriver, and Avoid ‘Automated Waiting’
Supports Maintainable Automated Test Design, such as Page Objects
Learning Effectively
Automated End-to-End Testing is super practical. Don’t waste much time on memorizing Selenium syntax or studying the benefits of Page Objects. Just put them in practice, hands-on.
During my training, within the first hour, all attendants will complete two automated tests, one by one:
Log in OK
Log in failed
The actual test scripts (in Selenium) are quite simple. While each test is executed OK individually, there is a dependency between these two tests (the second test would fail, if running both together). Then, I will introduce the concept of ‘independent test design’ and how to stabilize test scripts. The attendants would fix them under my guidance.
This is the pattern of my training. Every 10 minutes or so, attendants learn the new concept (syntax, design, or practice) and do them hands-on. Their confidence grows, while having fun.
All these are possible because raw Selenium WebDriver is simple and intuitive.
Q & A
1. Why do so many people say Selenium is hard to learn?
There are many reasons which I will list shortly. The main reason is that people learned it wrongly or from the wrong person. The fact, very few people mastered real test automation.
“In my experience, great developers do not always make great testers, but great testers (who also have strong design skills) can make great developers. It’s a mindset and a passion. … They are gold”.
- Google VP Patrick Copeland, in an interview (2010)“Testing is harder than developing. If you want to have good testing you need to put your best people in testing.”
- Gerald Weinberg, in a podcast (2018)
Common mistakes:
Choose the wrong language binding, such as Java, JavaScript or C#. Should go for Ruby.
Choose the wrong test syntax framework, such as Cucumber, SpecFlow, and Gauge.
Not focusing on hands-on. Automated Testing is super practical, you can only learn faster and better with guided exercises.
Lacking a good practice site in learning. Check out this Free Test Automation Practice Site with Database Reset.
Tech leads introduce their ‘own frameworks’ on top of Selenium. This is silly, which can make the best stuff worse. Please check out my other article: “Please, Not Another Web Test Automation Framework, Just Use Raw Selenium WebDriver”.
Don’t know how to make automated test scripts reliable. Check out my other article: Working Automated Test ≠ Good Reliable Test
Test scripts are poorly-designed, slow, and hard to read.
- Optimize Selenium WebDriver Automated Test Scripts: Speed
- Optimize Selenium WebDriver Automated Test Scripts: ReadabilityTest scripts are difficult to maintain. When the app changes, many test scripts are broken.
- Is Your Test Automation on Track? Maintenance is the key
- Optimize Selenium WebDriver Automated Test Scripts: Maintainability
Astute readers will see that there are many problems that are generally for most automation frameworks, and the main reason is the lack of general test automation knowledge among all tech team members. Unfortunately, many of them think they do have the knowledge. When test automation attempts fail, they blame the framework such as Selenium.
However, these people usually don’t blame commercial tool vendors, such as QTP, Tosca and SmartBear. Why? Because they paid quite a lot of money for it.
Check out my other article: Evil Mudslingings against Selenium WebDriver.
2. How do I learn Selenium effectively?
Start with my book: Practical Web Test Automation with Selenium WebDriver which I used for my training. Also, I incorporate the feedback from the attendants into the updated book.
Once, I received a thank-you email. One week after reading this book, a manual tester found his first test automation engineer role (in Europe).
Please check out this article, Advice on Self-Learning Test Automation with Selenium WebDriver.
Above all, hands-on automation. Check out my new Selenium Training Workshop, a series of short (~20 mins) and purposeful test automation exercises.
Further reading: