6

Java or Javascript? or maybe another language?

Please help me choose the programming language I should learn for Selenium automation and its benefit over other. Any pro's and con's?

  • OP: as you may found, selecting a "best" language is for many programmers close to Holy war. But it is easy to form informed opinion: start by googling "best programming language for beginner". Then, try to write trivial program, like print first 10 numbers. – Peter M. Aug 5 '15 at 23:44
  • Or check program to print song "99 bottles of beer" in Java and Python. Python is shorter, even if half of the code handles special case of 1 bottle (singular), which Java version does not. You can poke around for more examples. – Peter M. Aug 5 '15 at 23:44
  • One thing I would like to add to this, look into the languages that are used at the company you work for. If you have a C# background at your work, you are much more likely to get their help on a question if you write yours in that same language. – DEnumber50 Aug 6 '15 at 21:09
  • Spend one hour with Python intro and you will get idea what Python can do, and how easy it is. For Java or C#, you will need at least a week of hard work to write such simple example. – Peter M. Aug 7 '15 at 16:15
9

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.

  • Static typing in Java/C# is a big drag for a beginner. And lack of console/interpreter is another drag when learning programming language, especially first, when writing even 20 lines of correct code is a big obstacle. That's why I suggest Python, with both dynamic typing and console as first language for beginner – Peter M. Aug 5 '15 at 15:08
  • 2
    @PeterMasiar, au contraire, I would say dynamic typing is a big drag for a beginner. You never know what methods you can call on an object, since you never know till runtime what kind of object it is. C# is a great choice for a beginner because static typing and Intellisense make it easy to know what any given object can do. – Kyralessa Aug 7 '15 at 19:42
  • With language console, you can check methods of the object anytime, it is trivial and I do it all the time. At runtime. Without reading the code. Without intellisense. With all multi-dispatch trickery resolved, at runtime. This feature of Python is exactly why it is better for beginners. @Kyralessa I don't think you know Python, or know about import pdb magic. – Peter M. Aug 7 '15 at 21:01
  • @PeterMasiar, do you know C#? – Kyralessa Aug 7 '15 at 21:04
  • 1
    Yes, I do. Also Java, Perl, VB and many other languages. Did you read article about Blub paradox linked in my answer? And I assume you don't know Python? – Peter M. Aug 7 '15 at 21:59
6

I am assuming that you:

  1. want to become competent programmer, with goal to learn programming beyond Selenium automation.
  2. have nobody around to ask for guidance (if you do, ask locally)
  3. also want to be able to write simple tools supporting QA tasks, and beyond.

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).

Java or Javascript might be good as second language (if you feel the need), when you understand basics of programming. Yes, Java is bit faster - but speed of execution is irrelevant for a beginner, or for automating Selenium. Javascript is a must for web front end developer - but Javascript is more quirky, confusing and less forgiving than Python.

I know Python, Java, Javascript (and I learned many other languages before these three), so IMHO my opinion is based on more experience than people who know only one or two languages. First language you learn is very important, it forms base to understanding other languages, and bad habits of thinking from first language could be hard to overcome later.

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:

  • So have recent versions of Python fixed the problem where variable declaration wasn't required, thus allowing someone to misspell a variable name and thereby inadvertently create a whole new variable? Or is that still an issue with the language? – Kyralessa Aug 7 '15 at 22:00
  • I can see that you really do not know any Python, your knowledge of languages is limited to C# and such. Problem you mention was never a problem in Python (Perl and javascript do have such autovivification of variables, and have this problem, Python never had - it was always runtime error, and trivial to fix). So I guess we will have a Holy War? – Peter M. Aug 7 '15 at 22:31
  • No, to each his own. If you like the fact that accidentally misspelling a variable causes a runtime error instead of an easily-fixable compile-time error, who am I to argue. – Kyralessa Aug 8 '15 at 1:17
4

There are two sides of your question which I am interpreting (and may be I am wrong), but this is how I see it :

  1. You can choose your language based on the ease of learning.
  2. You can choose your language based on the support for that particular implementation.

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.

I, personally haven't used the Javascript version, but I know that as Node.JS and other such JS libraries get popular, eventually JS would be the language of choice for many.

So, I would say it's up to you to decide, which one is better suited for you.

1

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.

I think that with Javascript you will have little support because this language is used with WebDriver less often.

0

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.

JavaScript is becoming more popular though, certainly with the rising of NodeJS.

I would bet on JavaScript more then Java or C#, since its the language of the web. For a decent JavaScript starting training have a look at the JS Codecademy track course.

Have a look at WebDriver.IO or WebDriverJS for JavaScript versions of Selenium.

  • Niels, I highly regard your opinions, but here you are mixing two concepts: Java as widely used language, vs Python as widely considered best for beginners. – Peter M. Aug 5 '15 at 14:41
  • 1
    Huh? I don't talk about Python... :) Maybe for learning programming Python is very good, but I wonder if Python will find you a job outside of academics. Most jobs here in Europe/Netherlands are Java, C#, JavaScript and still some PHP. I bet on JavaScript personally. – Niels van Reijmersdal Aug 5 '15 at 14:43
  • 1
    Most Java positions I know require you to know a certain amount of JavaScript (amongst other languages) anyway. And it's just so flippin' useful as a power user. Annoying dropdown on a website? Change it in the dev console! – corsiKa Aug 5 '15 at 15:00
  • I do have Python job outside of academics. One of the reasons why my previous job in academia failed was the effort to standardize on Java, which severely limited our productivity (and our competitor, who used Python, eat our lunch). There are plenty of Python/Django web jobs in USA. – Peter M. Aug 5 '15 at 15:05
  • BTW poster asked not for a most widely used language (which I agree is of course Java, the COBOL of our times), but for a best language to learn programming and Selenium automation . Even you agree that Python is best to learn programming - and Java might be excellent second language, if you are stuck in locality where Python is not popular yet. – Peter M. Aug 5 '15 at 15:13
0

If you are starting out and not sure which language to learn first, let Stack Overflow help! Stack Overflow does a developer survey every year that might be helpful. Javascript is the most popular and Go pays the best in the US. I haven't seen a Go Selenium setup, but I haven't looked... So if you want to skills you pick up to apply to a broader set of work, try javascript/nodejs with Selenium.

0

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.

Java

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.

Javascript

It's the "Candy van guy" of programming languages. At first it baits you with loose typing, nice functions for everything and hey, at some point you need to understand it since it's the backbone of the internet but then it strikes you down from behind by treating a null value as a 0 and has you debugging for hours. The benefit is clear, there is no style break, if you need something more complex. In any other language you need to pass something into the AUT via the JavascriptExecutor and at that point you need to know js. It also helps with manual testing since you get a better grasp of what happens in your application. It's a horrible first language, imo, since it gives you too much freedom and tends to do weird things which are hard to handle if you don't have a good understand of programming languages and how things work internally. The concept of nested functions also lends itself to unreadable code which is really bad if a feature changes down the line and you have 12 layers of anonymous functions because it seemed a good idea at the time.

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.

C#

.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.

PHP

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.

Personal recommendation

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.