Use of groovy Webdriver scripts in WebdriverSampler

We are using groovy script to launch our client using webdriver sampler but it is not working as expected.
JavaScript is working with the code given below
var mypkg = JavaImporter(org.openqa.selenium);
var my_ui = JavaImporter(;
var wait = new my_ui.WebDriverWait(WDS.browser, 4000);
WDS.sampleResult.getLatency();"Sample started");

Please help us.
Thanks in advance.


  • Solution :
    1. Groovy syntax differ from JavaScript, i.e. there is no JavaImporter there, you should use import keyword instead
    2. There is no var keyword in Groovy/Java (unless you're using Java 10), you need to change it to def keyword
    3. Assuming all above you need to amend your code to look like:
    def wait = new WebDriverWait(WDS.browser,5000);
    WDS.sampleResult.sampleStart(); //captures sampler's start time
    WDS.sampleResult.getLatency();"Sample started");

Sign In or Register to comment.