Getting started with Selenium WebDriver in Java (Windows)

[renewed at 5 Dec 2018]
IMHO Java is the most popular programming language in the Selenium project, which means, that whenever you face a Selenium problem, the probability of finding the solution in Java is the highest. So start using Selenium in Java!
 
There are generelly 3 approches to get started with Selenium in Java:
Maven
The official one: Setting Up a Selenium-WebDriver Project
The sophisticated one (by Mark Collin, aka Ardesco): Selenium-Maven-Template
IDE
The official one: The 5 Minute Getting Started Guide Note: Here you find an example with HtmlUnitDriver. I experienced too often, that HtmlUnitDriver wasn’t working even with correct Selenium code, so I recommand not using it at all.
Without IDE, without Maven
This approach takes the most time but is the most back-to-the-roots one and shows best how Java works under the hood.
 

Approach without IDE, without Maven

Some backgrounds to Java
This paragraph is only a little refreshment for your aged Java knowledge. If you never had Java knowledge, you should go for a tutorial.
If you haven’t done yet, download the Java JDK from the download page (take the most actual Java Platform (JDK)). Execute it and follow the wizard. After that, set PATH.
The Java JDK not only comprises the JRE (jre.exe) – the JRE is the environment to run java-programs – but also the Java Compiler (javac.exe). The Compiler is necessary, because you have to compile the file of your source-code (yourname.java) to become an executable file. The result of that compilation is yourname.class. The program then can be executed by java yourname in your Command Prompt (after you navigated in the directory, where the yourname.class resides).
 
Selenium Setup
Download Selenium Standalone Server and put it e.g. on your desktop.
Selenium on Chrome works pretty out of the box: Download ChromeDriver, unzip it to e.g. the desktop and just run it.
If you want to run your tests on Internet Explorer, you need more time for configuration: look
 
Your first Selenium program
1.) Copy the following code in an editor and save it as Example.java e.g. on your Desktop:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Example  {
    public static void main(String[] args) {
        // Create a new instance of the Chrome driver
        // Notice that the remainder of the code relies on the interface,
        // not the implementation.
        WebDriver driver = new ChromeDriver();
        // And now use this to visit Google
        driver.get("http://www.google.com");
        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"));
        // Enter something to search for
        element.sendKeys("Cheese!");
        // Now submit the form. WebDriver will find the form for us from the element
        element.submit();
        // Check the title of the page
        System.out.println("Page title is: " + driver.getTitle());
    }
}

2.) As every Java program, it needs to be compiled. For the Java Compiler to find your Selenium library, you have to provide it in the so-called classpath. Execute the following in your Command Prompt (of course with the correct version number):

javac -classpath "%UserProfile%\Desktop\selenium-server-standalone-3.141.59.jar" %UserProfile%\Desktop\Example.java

3.) If everything is ok, you find Example.class on your desktop. Execute the following in your Command Prompt to run your first Selenium program (of course with the correct version number):

cd "%UserProfile%\Desktop

java -classpath .;"%UserProfile%\Desktop\selenium-server-standalone-3.141.59.jar" Example
… for historical reasons the JRE needs to point also to the actual folder, that is .;
 
Now Chrome should write „Cheese!“ in google search and finally you should find in the Command Prompt: „Page title is: Google“. The browser-window is not closing, as you might admire the results for some time!

Skillset of a Selenium Engineer

Note
This article is dedicated to show an approach, how to find the optimal skillset of a Selenium Engineer, based on the real project market. Please be aware, that the scope of my study in this article is on the German project market only, examining just 26 projects. So the statistical population is small and focussed, but current (no project description is older than 11.11.2012). There is no distinction between must-have-skills and nice-to-have-skills – all mentioned skills are weighted the same.
Results
Programming languages
* 85% of the projects want Java-skills (of these 68% explicitely want JEE-skills).
* 15% want PHP-skills
* 8% want Obj. C-skills
* 4% want C#-skills
Build-tools
Just 35% of the projects want skills in build-tools (of these 78% want Maven). Perhaps this percentage is so low, because having that knowledge is considered as self-evident for Java-programmers … like knowing your IDE.
CI-Tools
At least 38% of the projects want CI-skills (of these explicitly want: 40% Jenkins, 20% Hudson, 10% Bamboo).
Javascript
Not really surprising, that 58% of the projects want JavaScript-skills. But surprisingly 33% of these explicitly want jQuery-skills – hey, managers, shall we test or paint …
Testing Frameworks/Testing Tools
This category is really interesting, as it reveals much about the test setup of the projects:
The winner is JUnit – 62% of the projects want skills in that one. Don’t the responsibles know TestNG …?
12% of the projects want TestNG-skills.
I could hardly understand that they’re looking for skills in HP QC (8%), but why the hell they are looking for HP QTP-skills (8%) in Selenium-related projects …
Only 4% are looking for FitNesse, which makes me sad …
Only 4% (=1 project) are looking for BDD-Tools (in that single project, it’s Cucumber). Don’t they know, that BDD is hip, too?
Few are looking for PHPUnit(8%), JMeter (8%), CasperJS (4%), GreenPepper (4%), Tosca (4%), JDepend (4%), SOAP UI (4%), TestLink (4%).
Agile Methodologies
Wow, 58% of the projects want Agile Skills (of these 93% want Scrum, just 7% want Kanban). Is this because all the projects really work with Agile, or is this because asking for Agility is in vogue …
ISTQB
Being such important for the general software-testing-project-market, ISTQB-certificates are really underrepresented in Selenium-related projects. Only 12% of the projects ask for that!
miscellaneous
At least 23% of the projects are looking for skills in Web Services (of these 50% explicitly want it RESTful, and 10% want it SOAPy). 27% ask for AJAX-skills.
12% ask for skills in code-metrics (all of these want them in sonar!).
As a Selenium Engineer it seems, that you should be able to understand things like: SELECT * FROM mywebapp.testdata WHERE type = ‚edge-case‘ – 73% of all projects want you to database (of these 31% in Oracle, 26% in DB2, 4% in mySQL).
„Corner Cases“
One project just ask for Selenium – no other skills are wanted.
Just one project offers an opportunity to work remote.
Methodology
1.) As this study is focused on Germany, I went to all (known to me) German project exchanges on 8th/9th/10th Jan. 2013. For this study I only used project descriptions, that were accessible without registration. Forthermore I only regarded projects in Germany and for freelancers (no permanent positions).
2.) Every project exchange has some sort of search-tool, where I entered just „Selenium“.
3.) I made a fundus with screenshots of the resulting project offerings:


4.) I filtered the doublets.
[Excursion: At least in case of German project market it seems, that the enterprises generally don’t use the project exchanges – only recruiting agencies post project offerings there. Some enterprises contract multiple agencies and so different offerings appear for the same project. Unfortunately the agencies don’t reveal the name of the project’s enterprise (for commission reasons). Anyhow, similarities in skillsets, project location, project timeframe and time of posting are something like a fingerprint of a project. With little experience you can „see“ the same project behind different offerings and so filter the doublets.]
5.) I made a list of the skills/skill-categories, that are relevant to my study (not „HTML“ which is obviously needed in every Selenium-related project). You find them in the first column of the Excel.
Excel-file to download
6.) I filled the Excel project-by-project manually.
7.) At the end I extrapolated the results from the Excel.
Outlook
You don’t need a PhD, to conclude that the skillprofile in a project offering reflects the „anatomy“ of real-world projects. So, beyond freelancers, this approach can get useful for tool vendors, service providers, software architects …
Due to my time restrictions, this study is pretty limited. But this approach can be picked up e.g. in seminar papers, interships, (…) and extended in many aspects. E.g. the statistical population should be much broader to get scientific statements and to apply some sophisticated statistical analysis.
This study based only on German project exchanges within a short timespan. People with good relationships to employees of project exchanges may get data with a much longer timespan. Job exchanges (like monster or stepstone) may be covered, too.
Future research can distinguish between must-have- and nice-to-have skills, can include softskills, …
This post is about Selenium only, but the approach may be applied to any other core-skills (…)

Selenium Cloud

Last Friday I had some talks at Groupon in Berlin touching the state of the art of cloud-computing in the Selenium ecosystem. I like to share these slides, again showing the service of the Sauciers my respect.
[slideshare id=15519188&doc=slideshareseleniumcloud-121206091145-phpapp02]
For those who are interested – there’s a discussion about TestingBot at the mailinglist: https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/CCkJkxN93sc
UPDATE: New Selenium cloud service: Usetrace

Anpacken!