javaselenium-webdriverjmeterselenium-chromedriverjmeter-plugins

WebDriver returns error 500 in Jmeter Selenium


I'm new to Jmeter/Selenium, right now I'm using Java 17.0.8 and Jmeter 5.6.2, with Selenium 4.13.0.0. I tried a sample code using Java language as this:

import org.openqa.selenium.*
import org.openqa.selenium.support.ui.*

WDS.sampleResult.sampleStart();
WDS.browser.get("google.com");
WDS.sampleResult.sampleEnd();

Then I would get a 500 error code with the log below:

2023-12-25 11:53:16,662 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2023-12-25 11:53:16,662 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2023-12-25 11:53:16,662 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2023-12-25 11:53:16,692 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2023-12-25 11:53:16,692 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2023-12-25 11:53:16,692 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2023-12-25 11:53:16,692 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2023-12-25 11:53:16,693 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2023-12-25 11:53:16,693 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2023-12-25 11:53:16,693 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2023-12-25 11:53:16,697 WARN c.g.j.p.w.c.WebDriverConfig: Old browser object is inaccessible, will create new
org.openqa.selenium.NoSuchWindowException: no such window: target window already closed
from unknown error: web view not found
  (Session info: chrome=120.0.6099.130)
Build info: version: '4.13.0', revision: 'ba948ece5b*'
System info: os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.8'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [40e3d0d2a79e037d9bf1204692b3f91e, getCurrentUrl {}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 120.0.6099.130, chrome: {chromedriverVersion: 120.0.6099.109 (3419140ab66..., userDataDir: C:\Users\TriNP\AppData\Loca...}, fedcm:accounts: true, goog:chromeOptions: {debuggerAddress: localhost:37159}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: windows, proxy: Proxy(system), se:cdp: ws://localhost:37159/devtoo..., se:cdpVersion: 120.0.6099.130, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}
Session ID: 40e3d0d2a79e037d9bf1204692b3f91e
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
    at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
    at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
    at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:52) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:191) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:196) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:171) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:602) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:675) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:679) ~[selenium-remote-driver-4.13.0.jar:?]
    at org.openqa.selenium.remote.RemoteWebDriver.getCurrentUrl(RemoteWebDriver.java:316) ~[selenium-remote-driver-4.13.0.jar:?]
    at com.googlecode.jmeter.plugins.webdriver.config.WebDriverConfig.hasThreadBrowser(WebDriverConfig.java:169) [jmeter-plugins-webdriver-4.13.0.0.jar:?]
    at com.googlecode.jmeter.plugins.webdriver.config.WebDriverConfig.threadStarted(WebDriverConfig.java:145) [jmeter-plugins-webdriver-4.13.0.0.jar:?]
    at org.apache.jmeter.threads.JMeterThread$ThreadListenerTraverser.addNode(JMeterThread.java:802) [ApacheJMeter_core.jar:5.6.2]
    at org.apache.jorphan.collections.HashTree.traverseInto(HashTree.java:1029) [jorphan.jar:5.6.2]
    at org.apache.jorphan.collections.HashTree.traverse(HashTree.java:1012) [jorphan.jar:5.6.2]
    at org.apache.jmeter.threads.JMeterThread.threadStarted(JMeterThread.java:770) [ApacheJMeter_core.jar:5.6.2]
    at org.apache.jmeter.threads.JMeterThread.initRun(JMeterThread.java:758) [ApacheJMeter_core.jar:5.6.2]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:264) [ApacheJMeter_core.jar:5.6.2]
    at java.lang.Thread.run(Thread.java:833) [?:?]
2023-12-25 11:53:17,367 ERROR c.g.j.p.w.s.WebDriverSampler: In file: inline evaluation of: ``import org.openqa.selenium.* import org.openqa.selenium.support.ui.*  WDS.sample . . . '' Encountered "import" at line 2, column 1.
 in inline evaluation of: ``import org.openqa.selenium.* import org.openqa.selenium.support.ui.*  WDS.sample . . . '' at line number 2
2023-12-25 11:53:17,367 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2023-12-25 11:53:17,367 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2023-12-25 11:53:17,368 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2023-12-25 11:53:17,368 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

The only difference is that my GoogleChrome browser is at 120.0.6099.130 and my driver is at 120.0.6099.109, is there any way that I can bypass this ? I did try to put remote-allow-origins=* but it won't work


Solution

  • When you choose java language it's not real Java, it's Beanshell interpreter and the code you've copied and pasted from somewhere is not valid Beanshell code.

    Suggested changes:

    WDS.sampleResult.sampleStart();
    WDS.browser.get("https://google.com");
    WDS.sampleResult.sampleEnd();
    

    Going forward consider migrating to groovy language, it's more Java compatible, has better performance and offers some syntax sugar on top of standard Java SDK. See Apache Groovy: What Is Groovy Used For? article for more details.