0

I am trying to use groovy script to launch my client using webdriver sampler and it doesn't work as expected.only JavaScript is working with the following code

var pkg = JavaImporter(org.openqa.selenium); //WebDriver classes var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait); //WebDriver classes var wait = new support_ui.WebDriverWait(WDS.browser, 5000); WDS.sampleResult.sampleStart(); //captures sampler's start time WDS.sampleResult.getLatency(); WDS.log.info("Sample started"); WDS.browser.get('https://google.com/'); 

1 Answer 1

2
  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:

    import org.openqa.selenium.support.ui.WebDriverWait def wait = new WebDriverWait(WDS.browser,5000); WDS.sampleResult.sampleStart(); //captures sampler's start time WDS.sampleResult.getLatency(); WDS.log.info("Sample started"); WDS.browser.get('https://google.com/'); 

    Demo:

    enter image description here

Check out Apache Groovy - Why and How You Should Use It article to get started with Groovy scripting in JMeter

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for the response Dmitri T and quick one as we are trying to use waits and expected conditions in our webDriver Sampler as below def closeButton = By.xpath("//button[@aria-label='Close']") wait.until(elementToBeClickable(closeButton)) WDS.findElement(closeButton).click(); WDS.browser.findElementByXpath("//button[@aria-label='Close']").click(); WDS.browser.findElementByCss('button[aria-label=Close]').click(); none of the above code works as expected and there any documentation available for WDS usage in groovy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.