Friday, December 25, 2015

What is Selenium Java?

Well, since selenium is implemented in multiple languages, we want to talk about what is specific to Java world.

Selenium Components

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.

Selenium API

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.

2) Maven

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

3)Gradle

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.

No comments:

Post a Comment