Hello, friends. Here is how you can have Selenium run from SoapUi Groovy script step. This solution was created and tested with:
- SoapUI 5.X
- Selenium 3.X
- upgrade the libs under $SOAPUI_HOME/lib (! not bin/ext)
- use a custom java library (goes under $SOAPUI_HOME/bin/ext)
Code examples can be found here. An example of a project with a Groovy script is inside the project under auxmaterials folder.
Please note, that auxmaterials also contains some Selenium drivers, they are only there because I'm lazy. Feel free to throw them away, because there are now dependecies in the code (as described below, you need to configure a location for Selenium binaries youself). You, of course, can move the contents to a Groovy script, but in my opinion it won't be convenient to use.
And now to the steps you need to take:
1. Replace the following libraries under $SOAPUI_HOME/lib (I simply moved out the old ones to an archive subfolder):
- guava,
- httpcore,
- httpclient.
2. Do not try to implement Selenium script from a Groovy test step, contrary to what is said on the Selenium site. Selenium is quite a tricky and unstable thing, and it needs a lot of configuration and tweaking. This is not something a sane person would do, and the work would be enormous and unreliable.
Personally, I converted a driver helper class from my old TAF which already supported detecting of a browser type & profiles, os platform etc (a link to the lib once again).
3. Assuming you can run your new lib with, say, Eclipse, you can now export it as a runnable jar. You need the option called "copy required libraries into a sub-folder next to the generated jar". When done you copy your new runnable jar + the libraries into $SOAPUI_HOME/bin/ext.
NB: Do not copy libs as a folder, but as a set of files, they need to be on the same level as your runnable jar.
4. Having failed to reliably reference Selenium driver binaries from within the lib, I decided to keep them separately and take their location as a mandatory parameter when my lib starts. I guess, you should do the same.
5. Finally, you need to write something like this in your Groovy script (syntax heavily depends on whatever I put in my lib):
// this one imports my lib
import app.helpers.*
def dhelper = new app.helpers.DriverHelper()
log.info("Library status: " + dhelper.healthCheck())
// these, of course can be parameterized
def browser = "FF"
def pathToSelenium = "C:\\work\\seleniums"
log.info(browser)
log.info(pathToSelenium)
def wd = dhelper.getDriverInstanceByName(browser, pathToSelenium)
wd.get("http://google.com")
Hope, you find it helpful.
3. Assuming you can run your new lib with, say, Eclipse, you can now export it as a runnable jar. You need the option called "copy required libraries into a sub-folder next to the generated jar". When done you copy your new runnable jar + the libraries into $SOAPUI_HOME/bin/ext.
NB: Do not copy libs as a folder, but as a set of files, they need to be on the same level as your runnable jar.
4. Having failed to reliably reference Selenium driver binaries from within the lib, I decided to keep them separately and take their location as a mandatory parameter when my lib starts. I guess, you should do the same.
5. Finally, you need to write something like this in your Groovy script (syntax heavily depends on whatever I put in my lib):
// this one imports my lib
import app.helpers.*
def dhelper = new app.helpers.DriverHelper()
log.info("Library status: " + dhelper.healthCheck())
// these, of course can be parameterized
def browser = "FF"
def pathToSelenium = "C:\\work\\seleniums"
log.info(browser)
log.info(pathToSelenium)
def wd = dhelper.getDriverInstanceByName(browser, pathToSelenium)
wd.get("http://google.com")
Hope, you find it helpful.
No comments:
Post a Comment