1

I just upgraded to version 4.5.0 of WebDriver, using JMeter 5.5, and can't perform any actions.

Based on the official docs: https://jmeter-plugins.org/wiki/WebDriverSampler/ should be using like:

var pkg = JavaImporter(org.openqa.selenium) but I faced exception. 

Is there any way how to resolve this exception, so I can use it for sendKeys or click actions?

enter image description here

2 Answers 2

1
  1. You're using groovy as the language
  2. JavaImporter object is specific for JavaScript

This mix of languages is not supported, you either need to switch to javascript in the "Language" dropdown or re-write your code in Groovy using import statement and replace var occurrences with def

Also according to Top 15 UI Test Automation Best Practices

NEVER use Thread.sleep() unless there are specific test requirements

so consider migrating to Explicit Wait instead

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

3 Comments

Under current implementaion javaScript is not available to be selected. I only have: beanshell | java | groovy | bsh | jexl2 | jexl. IS there any way how to enable JS, or groovy is recommended?
1. Groovy is recommended mainly because it provides better performance than other scripting engines. 2. JavaScript has been removed in Java 15. If you want JavaScript back you need to migrate to Java 14- or use GraalVM
Is there any proper example you can share with me on how to use groovy code? Especially handling the driver. thanks
1

thanks @ Dmitri T for your direction. Since javaScript is droppped after java15, here is some sample code that I found usefull using: Jmeter5.5 + Java17 + selenium version 4.5.0 + groovy as language

import org.apache.jmeter.threads.JMeterContextService; import org.apache.jmeter.threads.JMeterVariables; import org.openqa.selenium.*; import org.openqa.selenium.support.ui.*; import org.openqa.selenium.By; import org.openqa.selenium.WebElement; WDS.sampleResult.sampleStart(); WDS.browser.get("http://gmail.com/"); JMeterVariables vars = JMeterContextService.getContext().getVariables(); java.lang.Thread.sleep(3000); def userIdElement = WDS.browser.findElement(By.xpath("//input[@id='identifierId']")); userIdElement.sendKeys("[email protected]"); java.lang.Thread.sleep(3000); WDS.sampleResult.sampleEnd() 

1 Comment

NICE, this works and answered my question, after hours of searching

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.