
How much Java do I need to learn for Selenium?
Updated: Feb 17, 2018
I see these questions often on testing forums like Quora:
"How much Java do I need to learn for mastering Selenium?"
"How much programming do I need to learn for test automation?"
My response is "as much Java as you can".
The programming language is the most important skill for test automation so everyone should learn it very well.
But going from manual tester (with no programming skills) to test automation engineer is not an easy task because there are many learning levels in between.
1. Learn the Java basics
Understanding the Java basics will help you to create simple Selenium automation scripts.
You need to cover
variables
fundamental data types (String, Integer, Boolean)
conditional operators
string methods
conditional statements (if/else, switch)
looping statements (for, while)
arrays
packages
exceptions
lists
read and write files
use Java API
The automation scripts that you can create with the Java basics will include WebDriver objects and methods which is ok for now.
But as soon as you start having more and more scripts, the scripts maintenance becomes a problem.
2. Improve the Maintenability of Automation Scripts
Your scripts are long, they include WebDriver objects and methods and have duplicated and complicated code.
They are very difficult to change and maintain.
In test automation (and development in general), the code should work as expected but it should also be short, well organized, easy to read and easy to maintain.
All these can be achieved with Java object oriented concepts such as:
classes and objects
class fields
methods and constructors
method overloading
set/get methods
class/field/method modifiers
With these concepts clear, you can start structuring your automation scripts as per the Page Object Model.
Page Object Model is about creating classes that implement the interaction with the site pages and page elements. The WebDriver objects and methods will be moved from the test scripts to the page classes.
This way, automation scripts do not interact directly with the site but through the page object classes.
The automation scripts become simple, easy to understand and maintain since all complex code is moved out of them.
3. Create an automated testing framework
Next, you should focus on simpliying the page classes code.
This is done by identifying duplicated or complicated code in the page classes and creating new and simpler classes with it.
These new classes will be part of your automation framework.
More Java advanced concepts are useful at this point:
class inheritance
class composition
base classes
method overriding
polymorphism
interfaces
generics
reflection
predicates
streams
lamdba expressions
inner classes
abstract classes
4. Improve the test automation framework design
The automation framework can get very complicated as well. You may have very simple and clear automation scripts and page classes but the automation classes may need still lots of work.
Code refactoring and design patterns should be the next thing to learn about.
Code refactoring is about transforming complicated code to simple through common practices.
Design patterns provides 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.