"How much Java do I need to learn for mastering Selenium?"
"How much programming do I need to learn for test automation?"
My initial response is "as much Java as you can learn".
What I mean is that since the programming language is the most important skill for test automation, everyone should learn it as much as possible.
While I still like my response, it is not helpful for other testers that want to learn a programming language for test automation.
First, I want to say something about the question.
It implies that mastering Selenium happens after learning some Java programming.
A similar question could be:
I don't know how to swim but how much swimming do I need to learn to compete for Olympics?
To go from no swimming skills to just decent swimming is very difficult.
Going from decent swimming to mastery of swimming is just not realistic for most of people.
I picked swimming as a skill example as the process of learning test automation is similar to learning any other skill.
Mastering a skill usually means that you are at the highest level possible for it.
This does not happen obviously through just learning as a lot of practice and self-improvement are needed.
And time, perseverance and patience.
Going from a manual tester to a test automation engineer that masters Selenium is a very difficult goal.
Test automation engineers that master Selenium are usually software developers in test.
Meaning professional developers.
Still, how much Java do you need to master Selenium?
What concepts of Java do you need to learn to use Selenium?
Between manual tester with no programming skills and test automation engineer that masters Selenium, there are a few different levels.
1. Learn Java basics for Selenium test automation scriptsJava basic knowledge is sufficient for creating simple Selenium test automation scripts.
You will need to learn about
- fundamental data types (String, Integer, Boolean) and their operators
- conditional operators
- string methods
- conditional statements (if/else, switch)
- looping statements (for, while)
- read and write files
- use Java API
After learning the basic concepts, you should be able to create basic test automation scripts with Selenium.
These scripts will include WebDriver API which is ok while learning Selenium.
But as soon as you start having more and more scripts, the scripts maintenance will become an issue.
2. Create maintainable scripts with page object model
Having a large number of test automation scripts that include WebDriver APIs poses an issue from the maintenance point of view.
Since each script is independent and some scripts may just repeat the same lines of code, changing the test scripts for improvements or because of bugs is difficult to do.
The more complex test scripts are, the harder to maintain.
And we should remember that the biggest failure point in test automation efforts is test automation scripts complexity.
So we need to reduce the test scripts complexity and make scripts maintenance easier.
For these purposes, you need to start learning the Java object oriented programming concepts.
This includes learning about
- creating classes and objects
- class fields
- methods and constructors
- method overloading
- set/get methods
- class/field/method modifiers
The object oriented programming concepts will help implementing the page object model for your test automation scripts.
This means that you will create classes that correspond to site's pages (or components of site pages) and move the WebDriver API code from the test scripts to the page object model classes.
By doing this, you keep your test scripts free of any direct interaction with the site.
The interaction with the site is being done in the page object classes.
3. Create an automated testing framework with Selenium
After having page object classes, you will want to start creating your test automation framework.
The framework should be useful not only for one site but any number of sites.
And possibly for mobile applications as well.
You need to learn the Java advanced concepts like
- class inheritance
- base classes
- method overriding
- static classes
- inner classes
- abstract classes
4. Improve the test automation framework design
You need to learn code refactoring and design patterns for this purpose.
Code refactoring will help making your test automation framework simpler and more efficient.
Design patterns will provide proven ways of solving common development problems.
Are there more levels?
Yes. Learning a skill never ends.
There is a long way from manual testing to test automation with Selenium.
But taking it a step at a time will eventually get you there.
With perseverance and lots of patience.