Please help me choose the programming language I should learn for Selenium automation and its benefit over other. Any pro's and con's?
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.Sign up to join this community
See, you can learn Selenium with any language, whether it is C#, Java, Ruby, Python etc. It doesn't matter whether the application you are going to test has been developed in the same language that you would use to write your test scripts, you can test an application developed using C# in Selenium with test scripts written in Java.
In addition to that, you don't need to learn any of these languages completely for working with automation. You should know the basic stuff and as you go on with testing and creating test cases you will keep on searching about the issues being faced and how they can be resolved, which in turn will enhance your programming skills as well. Selenium with Java is more easy and much better to use and learn, you will get lots of examples, training material, forums and communities for the same. Don't need to learn complete Java for this, only basics are enough.
But above all if you are more comfortable with other options, then they are not bad, if you don't have any past experience in programming and are starting from scratch Java is good option.
I am assuming that you:
Python is widely considered as best language for beginners (MIT among others). It works much harder for programmer (to make programmer life easier). Because is not as object obsessed as Java is, beginner programmer can write simpler procedural code using existing objects without the need to dive deeply to object design. There are many excellent free online books and courses to learn Python.
One important feature why learning Python is simpler than Java is Python console/interpreter. It allows learner to learn Python one line at a time, experimenting and playing with language, instead of writing complete page of code like with Java (and trying to debug it as a whole).
Another important reason why Python beats Java is flexibility to create data structures in Python. Lists, dictionaries, returning multiple values from a function is trivial in Python. Python is excellent language to parse and manipulate data in text files, you would want to learn it for that reason anyway (Java sucks in this task).
Python is excellent glue language which will allow you to write tools helping your other QA tasks. Recent example from our experience: get log messages from last 100 SVN logins, parse bug numbers and comitters, get bug status from bugzilla database, and print report (to make sure that bugs with commits are in proper status). Python is excellent for this, Java, C# or JS - less so. So you likely want to learn Python anyway, to write such little custom tools.
Yes, Python is bit a niche language (people often learn it as 4th or later language, or not at all) - you have the opportunity to learn it as your first. Check one hour Python intro and you will get idea what Python can do, and how easy it is.
Go with Python, and when you learn those other languages, you will see why Python was the best choice for a beginner.
As I said, first language is very important because it will affects how you think about programming. This type of cognitive bias has name Blub paradox - a term coined by famous programmer and founder of Y-combinator seed fund Paul Graham in article Beating Averages - where he explained how he become millionaire by using Lisp (even more dynamic language than Python) instead of Java in his startup. We may safely assume that he knows about using programming languages which make programmer productive :-)
This type of cognitive bias can explain why people who know only static languages like Java or C# do not "trust" Python and rarely recommend it to others, and @Kyralessa comments are perfect example of such blub programmer. I did not asked him, he volunteered, honest! :-)
Two free online edX courses to learn Python for beginners:
There are two sides of your question which I am interpreting (and may be I am wrong), but this is how I see it :
Let's talk about first- I have used both Python and Java implementations and I agree with Peter, that Python is a lot easier and simpler to learn compared to Java, and as such, if you are a complete novice, I would suggest you go with Python.
Also it is fairly easy to install and use, and hence I would prefer it over Java implementation any day.
But, here comes the second point, which both Dhiman and wmarchewka have outlined is the support for Java implementation of Selenium. You will find a lot of support for Java with Selenium, since most of the online guides and tutorials, you'd find will help you with Java and Selenium, and not Python.
That being said, I don't mean to imply that you wouldn't find any Python plus Selenium resource, but it is not at the level of Java.
So, I would say it's up to you to decide, which one is better suited for you.
If you want to learn from scratch I think that Java will be good, because there is a huge amount of support from the community in this language (I think most of the people use Java with WebDriver). I've started with Java and for any question or trouble there always was somebody that could help me.
Now I'm using Python with Selenium, and experience that there is a very big difference in support from the community.
According to the TIOBE Index Java is still the number one language for programming. Java will also net you the most online support because of this on for example Stack Overflow.
Very broad question and as a python fanboy I can only say Peter Masiars answer is very good but let me try to make a case for the other big ones.
It's the big one. You'll find tons of examples, it's strict enough to punish you for making beginner mistakes and forces you to understand data types before it starts working with you. Hard teacher but if you get it you have a language that wants you to write reliable, maintainable code. I mostly work with students or new graduates (since the other branches in our company tend to steal away my guys after I trained them) and it is the language everyone learned at university which helps with getting into it.
It's a must have at some point but as a first it might do more harm than good. Also, the same as Python, an IDE doesn't help as much as it does with languages that force you to declare a type.
.NETs Java. Almost anything I said about Java is also true for C# with the exception that some guy thought introducing a generic var type was a good idea and allowed for millions of anti patterns to take hold. It's a solid language and definitely a good recommendation for beginners. It can also handle JSON quite well which puts it miles before java the second you need anything from an API. The problem is that it pretty much only works on Windows. I know there are ways to run it under linux but I, personally, do not like any of it and remember, if your tests ever need to run within a dockerized environment (think CI strategy e.g.) you run into problems.
Well, there are many people that will tell you PHP is the worst language out there and that you shouldn't touch it with a five feet pole if you can avoid it and I get why. PHP lends itself to writing bad code since, similar to JS, it offers a lot of freedom. If you have the discipline to adhere to good design even though that one hack might get you a solution you can go for it but if that applies to you I'd recommend JS over it. It's a nice, loosely typed allrounder but not really good at anything but being a HTML preprocessor.
I can't say anything about Ruby since I never really got into it.
You start with Software testing which isn't something I would do with a beginner. Hell, I don't do that with a fresh hire. Software testing is, by it's nature, multi process code without native synchronisation interfaces. That's a hard thing to manage for a seasoned programmer but it's really bad if you start with it. Since the fact that determining the state of your AUT might be an already quite challenging thing to do you do really not want your language to make you any problems so all those loosely typed languages (JS, PHP, probably also python) might not be the best choice since your IDE doesn't help you as much and some errors might be harder to trace back. From the remaining ones I'd definitely recommend Java over C# since it works on all systems and tends to be the tutorial language. You'll google for a lot of things in the beginning and many examples, especially in the WebDriver context, tend to be in Java. If you need to read JSON from some source it's suboptimal but it's just the language that holds your hand the most. Just a warning: Once you get better at it you'll hate the boiler plate and enforcements that in the beginning help you and you'll curse your system for needing 5 lines for something python would do in one.
Also, look at what the other guys in your company use. Having a mentor while learning something is invaluable and might even be worth to choose a less optimal language.