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 only comfortable with one programming language, 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 have 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?
1. Java. No good, because it is not a scripting language. We call test scripts for a reason. I was considered a 10x Java programmer (I rarely need a mouse when coding in Intellij IDEA, using keyboard shortcuts), people came to me for rescuing their failing Java projects. I still use Java for some app development, but I would NOT use Java for functional test automation.
2. C#, as above.
4. 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.
5. 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).
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:
“Our team chose Ruby because it’s a purely object-oriented, dynamic, interpreted language with a syntax that is elegant, expressive, and tersely powerful. More importantly, Ruby is an ideal tool for the creation of Domain Specific Language (DSL).”
The adjectives in the quote are important attributes for a good scripting language, don’t you agree? Now, try to judge Java with the above, you will understand why most UI test automation attempts failed.
UI Test automation, for many, is new knowledge, 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 giving Ruby a try, the chance of mastering UI test automation is very slim.
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.