How to add my own/custom methods to Selenium WebDriver jar?

592 views
Skip to first unread message

HemaSundar Penugonda

unread,
May 31, 2015, 10:29:02 PM5/31/15
to seleniu...@googlegroups.com, shnake...@gmail.com
Hi Team,

Our Project Environment:
Selenium WebDriver, Selenium Grid
Prog. lang. : JAVA, TestNG

In our current project, we implemented Selenium Grid & WebDriver using JAVA and everything working fine. 

In most of the test cases we need to save the screen shot of a particular webElement from browser window at run time and perform pixel to pixel comparison with the expected image (Expected image is present on Selenium hub system). Image comparison is Java Code.

We have implemented all this on Selenium grid.

As per the selenium documentation says, selenium hub executes only selenium commands on node system, remaining java code execution is using hub resources (CPU) only. Because of this all the image comparison execution is on Hub machine only.

So now our test case execution is finally dependent on hub resources and all the benefit of earlier steps executed on selenium node is gone. We want to execute image comparison on selenium node as well.

Our solution is: Using Selenium grid to execute the image comparison method on node system (not on Hub). 

To achieve this, i have tried the following:
a) imported the selenium project from git
b) tried to add the my custom method in:
  • com.thoughtworks.selenium.webdriven.commands package
  • com.thoughtworks.selenium.webdriven.WebDriverCommandProcessor class
  • org.openqa.selenium.htmlunit.HtmlUnitDriver class
  • org.openqa.selenium.remote.RemoteWebDriver class
  • org.openqa.selenium.support.events.EventFiringWebDriver class
  • org.openqa.selenium.WebDriver interface
c) generated the build using "go clean release" command
d) tried using the jar files created, but i couldn't see the custom method i added.

Please explain how can i extend selenium webdriver or how to add my own method to selenium jar file? 
or please let me know if there is some solution to my current problem.

Krishnan Mahadevan

unread,
May 31, 2015, 11:00:03 PM5/31/15
to Selenium Users
You are doing this wrong.
You can very well get this done with the current Grid infrastructure itself. 

All you need is to be able to build a custom servlet at the node end and inject it into the node. When you are ready for performing image comparison at the node, you would directly trigger an invocation to the servlet at the node which would do what you need and respond back with a response which your test can leverage upon.

The overall idea of how to get this done can be found in my blog post : 

We did something similar when we built SeLion [ http://selion.io

Take a look at the servlets here : 

Relevant configuration here : 

Some documentation : 


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/a97c0f2a-5065-49ce-86b1-77f5777db6f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David

unread,
Jun 1, 2015, 1:43:28 PM6/1/15
to seleniu...@googlegroups.com, shnake...@gmail.com
FYI, if I'm not mistaken, the reality is that the non-Selenium Java code executes on the code execution machine, which may or may not be the Selenium grid hub. It is if you happen to execute the test code locally on the hub machine (as localhost). But if you actually connect to the hub remotely over IP/hostname, then the Java/test code including the image comparison actually executes on the test client not the hub.

mayank nishesh

unread,
Jun 6, 2017, 8:33:31 AM6/6/17
to Selenium Users
Hi Krishnan,

I am facing challenges in attaching the custom servelet to the selenium grid.Could you guide me step by step process for this or can refer to me any link.
Also whether the servelet which we export as jar should be a runnable jar or normal jar?

Krishnan Mahadevan

unread,
Jun 6, 2017, 9:54:43 AM6/6/17
to seleniu...@googlegroups.com

Have you referred to the official selenium documentation here : http://www.seleniumhq.org/docs/07_selenium_grid.jsp#customizing-the-grid

 

Once you have built your servlet, you can wire it in using two ways:

 

  1. Build an uber jar wherein you have selenium and its dependencies all bundled into one single jar. You can refer here if you are using Maven and refer here if you are using gradle.
  2. Build a regular jar, drop it in your classpath and then use the java -cp command to spawn the hub.

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ http://wakened-cognition.blogspot.com/

My Technical Scribbings @ http://rationaleemotions.wordpress.com/

 

Reply all
Reply to author
Forward
0 new messages