Which Selenium WebDriver Language Binding is the Best?
Test Scripts are better with scripting languages, such as Ruby.
Selenium WebDriver comes with 5 official programming languages: Ruby, Java, Python, JavaScript, and C#. The question comes: which one is best?
Unfortunately, for most software projects, in reality, the answer commonly is whichever language your tech lead/test architect knows. It is surprising (and depressing) to see how limited this generation of programmers have in terms of programming languages. If a tester/programmer is only comfortable with one programming language, that’s a bit of a concern. Please read the classic (and must-have) book: The Pragmatic Programmer — From Journeyman to Master by Andrew Hunt and David Thomas.
My answer is Ruby. My love for the Ruby language started in 2006 after I had programmed Java for 9 years. Programmers tend to be fixated/biased on a preferred language. I am probably more objective than most, as My Selenium Recipes Book series covers all these five languages.
My opinion is based on experiences from developing (more importantly, maintaining) thousands of test scripts in each language binding.
Before examining these five language choices, I want to be clear: each language can work, here we are talking about which one is better?
Java.
No good, because it is not a scripting language. We call test scripts for a reason. I was considered a 10x Java programmer then (I rarely need a mouse when coding in Intellij IDEA, using keyboard shortcuts), and people came to me to rescue their failing Java projects. I still use Java for some app development, but I would NOT use Java for functional test automation.C#, as above (not a scripting language).
JavaScript.
The ‘Promises, async/await’ in the current official implementation adds unnecessary complexities (and is verbose too). Some turn to WebDriverIO, another implementation. This adds confusion. A common pattern I see in failed test automation attempts using JavaScript is “cycling through frameworks”, such as raw Selenium WebDriver (JS) →WebDriverIO → Cypress → TestCafe → Playwright, …, and failing it one by one. However, JavaScript is a bit fast (see my comparison benchmark).
For more reasons to avoid JavaScript, please read:Python.
As a scripting language, Python is well suitable for test automation. Python is popular, too. However, it is more restrictive than Ruby, such as indentation and parenthesis are required in Python 3, which frustrates non-python programmers. Remember, automated functional test scripts are for the whole team. Furthermore, based on my benchmark, Python binding is about 10% slower than Ruby.
Ruby 😀.
Ruby is a concise, powerful, and elegant scripting language, which has a long history of being a scripting language for test automation. For example, Watir was created in 2001 and still remains a popular framework (now based on Selenium WebDriver). Please note “Watir” stands for ‘Web Application Testing in Ruby’, which shows the creators’ love for Ruby. (The same goes for the super famous Ruby on Rails web framework).
I know my words won’t be enough to convince you to learn Ruby, so I borrowed a quote from the classic Agile Testing book:
The adjectives (object-oriented, dynamic, elegant, expressive, powerful, ideal) in the quote are important attributes for a good scripting language, don’t you agree? Now, try to judge Java with the above, and you will understand why most UI test automation attempts (using Java, C# and JavaScript) failed.
UI Test automation, for many, is new knowledge and requires learning. (Doing a simple ‘hello world’ sample automated testing is easy, everyone can do it. However, to master real UI test automation is extremely hard without a good mentor, you see everyone talked about selenium automation but rarely seen used for regression testing.) So if a tester/programmer lacks learning altitude, not give Ruby a try, the chance of mastering UI test automation is very slim.
Quite often, programmers (typically tech leads) who failed test automation blame the ‘Selenium WebDriver’ framework rather than their limited knowledge of test automation and the wrong choice of language. Please read False ‘Selenium WebDriver Cons’ and Evil Mudslingings against Selenium WebDriver.
If I have to use one adjective for why choose Ruby for scripting automated tests? It is fun. I leave you to try and figure it out.