Skip to main content
blog title image

4 minute read - Java For Testers Programming WebDriver

Which programming language?

Jan 31, 2020

TLDR; Getting started with programming is the hardest part. Installing the IDE, adding dependencies, writing your first test. Pick whichever language you have someone to help you with, or you have a tutorial to work through. Switching languages when you know one is not too hard so do not worry about being stuck with a language, focus on getting started.

Which programming language should I learn?

I still receive a lot of questions about “Which programming language should I learn?”

And the answer is really - whichever language you can get more support for from people that you know.

Because languages are pretty much the same, once you know one.

Families

As an example.

I am much more comfortable with Java, than any other language.

It wasn’t always thus.

I used to prefer, in order:

  • ZX Basic
  • 68000 asm
  • C
  • Visual Basic
  • C++
  • Java

And along the way I’ve learned JavaScript, C#, Fortran, Pascal, Cobol, Hope, Prolog, a variety of basics, Smalltalk, Miranda, Z80, Ruby, Python, Lisp, PHP, ML and a few others.

Languages fall pretty much into ‘families’ and if you learn one in a family you can learn pretty much any other in that family pretty easily.

  • Assembly - Z80, 68000
  • Function Based - C, Pascal, Fortran, Cobol
  • Functional - ML, Hope, Miranda
  • Symbolic - Prolog, Lisp
  • Object Oriented - Java, C++, JavaScript, C#, Python, Ruby, PHP, Pascal
  • Pure Object Oriented - Smalltalk

I kind of made up the ‘function based’ name for programming languages that didn’t orginally have the concept of Objects - they often had structs and pointers which allowed simulating objects by creating structs with pointers to functions or other structs. Later, object oriented concepts were added to Pascal, Fortran and Cobol and then in the later C variants C++, Objective-C etc.

And some languages allow you to mix styles e.g. functional programming, or Object Oriented. I wouldn’t worry about this when getting started. I’m trying to point out that once you know one, you can switch to another, you won’t get stuck with an out of date language and find it hard to move on.

Code Example

And as a quick code example.

This is a C# example of using WebDriver

[Test]
public void Test1()
{
    IWebDriver driver = new ChromeDriver();
    driver.Navigate().GoToUrl("https://eviltester.github.io/synchole/");

    driver.FindElement(By.LinkText("Collapseable Div")).Click();
    driver.FindElement(By.CssSelector(".condense")).Click();
    
    new WebDriverWait(driver, TimeSpan.FromSeconds(10)).
        Until(ExpectedConditions.ElementToBeClickable(
        By.Id("aboutlink"))).Click();

    Assert.AreEqual("About The Sync Hole", driver.FindElement(By.TagName("h1")).Text);
    
    driver.Close();
}

This is the same example in Java.

@Test
public void test1()
{
    WebDriver driver = new ChromeDriver();
    driver.navigate().to("https://eviltester.github.io/synchole/");

    driver.findElement(By.linkText("Collapseable Div")).click();
    driver.findElement(By.cssSelector(".condense")).click();

    new WebDriverWait(driver, 10).
            until(ExpectedConditions.elementToBeClickable(
                    By.id("aboutlink"))).click();

    Assertions.assertEquals("About The Sync Hole", driver.findElement(By.tagName("h1")).getText());

    driver.close();
}

Many of the subtle differences in method name are handled by code completion in the IDE i.e. I start typing and see a list of the method names I can use. Then over time I learn the nuances of the language.

C# prefers to have upper case naming for methods, Java does not.

Setup

The hardest thing for learning a language is getting started in the first place.

  • How do I install it
  • How do I add dependencies to the project e.g. NUnit, Selenium, JUnit etc.

So working through an up to date set of install videos and following them exactly can help.

Unfortunately this is the hardest part of a course to keep up to date and is most often the part that confuses people.

Which is why… pick a language that you can get support in.

People like Ruby and Python for this reason, because they seem to have fewer startup hurdles. But as soon as you start writing Unit Tests or working with Selenium or HTTP or REST then you need to add libraries, and you do that through dependency management systems.

And this is usually where things get hard.

So if you can… find an example project for the library on Github and download the code to work out how the dependency management works.

Once you have started, you’ll be able to switch between languages pretty easily so don’t spend too much time wondering which to learn. Look around at where you can get support, and start based on that.