What is Selenium Java?
Frankly there is enough information on internet on Selenium Java. In fact when we search for selenium, the first hits probably are the ones on Java side. Little do we know that selenium is actually very nicely implemented on Ruby side with selenium-webdriver + watir-webdriver gem that in fact for Test Automation has a very easy learning curve. That said, we already talked about what is selenium in general.
We also talked extensively on why a programming language choice is the first point of entry even when we talk about Selenium. In our series on Choosing Automation solution, we talked about pros and cons of various parameters and the trade-offs.
What is Selenium Java?
Well, since selenium is implemented in multiple languages, we want to talk about what is specific to Java world.
The selenium components are going to be the same regardless of the programming language. Because the components sit between the actual server and our code base and follow WebDriver protocol [send JSON messages which is language neutral]. By selenium components we mean the following
- chromedriver executable (chromedriver.exe for windows for example)
- IEDriverServer Executable
- Safari Executable
- And so on…
We will have to install (or put them in PATH) whichever programming language we use. So for Java World too, we have to put them in ENV, so that it is accessible for the code to pick up.
The API’s are packaged as .jar files in Java world. In fact any library is pretty much a .jar file in Java. So what libraries are we interested while we deal with Selenium on Java side.
- Language specific client driver api (selenium source jars)
- selenium-server-standalone jar (has an internal http server and hence used as Selenium GRID)
How do we use or consume these jars ?
1) Raw and Native Ways
We can always have these jars in classpath and access the api’s , that means we have to do the .jar management, maintain it in a file , execute or set it in env everytime.
Obviously we are past those times when we have to explicitly manage every little jar and its transitive dependencies and so on. Maven is a very nice build and configuration tool that helps us specify the jar as a GAV (group, artifact, version) in a xml file, that helps manage the project dependencies in a succinct manner.
We dont want to go into details here, but suffice to say that if we need any jar in Java world, chances are we would find it in a repository called maven central , so we would find selenium jar too. All we need to get is the xml and copy it in our project POM.xml.
So if we specify the below GAV in our project POM.xml (assuming that our project is maven project), we will get access to all selenium source api’s that we can start coding with.
Similar to Maven, Gradle is a build configuration tool, however with much more “configuration” capabilities [Yes we are talking about convention vs. configuration]
Gradle projects use a file called “build.gradle” that contains again all information of libraries that the project uses [much like maven POM.xml]. But build.gradle can have code written into it inline [unlike maven, where we can have only xml]. Anyways, I like Gradle and at some point will move all my github java projects to gradle, not there yet.
4) More ways..
I am sure you have figured the pattern here. It is the project dependency management tool that determines the way we access selenium api jars. There are others like Ivy etc. but it is beyond the scope of this discussion to get into that world.
So in this post we talked about what selenium means in the java world and that it is different from selenium components. Selenium jars would be the ones we should be interested in when we talk about selenium java.
On this website, whenever we refer to Cucumber JVM, we implicitly use Selenium Java as the programming language binding.