'Full details for jp@gc - WebDriver Sampler- Can I Used script language JAVA?

I want to write some selenium script using jp@gc - WebDriver Sampler . Here I used Script Language JAVA. Can Here I used main function ? or is it supported only JUnit? Can I write a script in TestNG?
Already I wrote one script for that I got error" when used (driver.get("https://opensource-demo.orangehrmlive.com"); )

java.net.MalformedURLException: unknown protocol: data
at java.net.URL.<init>(URL.java:618)
at java.net.URL.<init>(URL.java:508)
at java.net.URL.<init>(URL.java:457)
at com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler.sample(WebDriverSampler.java:90)
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:638)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256)
at java.lang.Thread.run(Thread.java:750)


Solution 1:[1]

  1. There is no java language either in WebDriver Sampler or in JSR223 Test Elements, when you choose java in the language drop-down the script will be evaluated by Beanshell interpreter. If you're looking for the closest to Java syntax - go for groovy

  2. There is no need to define an "entry point", the interpreter reads the script at once and executes line-by-line. You can have classes if you want. You can have main() function if you want but you will need to explicitly call it.

  3. There a pre-defined WebDriver instance WDS.browser so the minimal test would be something like:

    WDS.sampleResult.sampleStart()
    WDS.browser.get('http://example.com')
    WDS.sampleResult.sampleEnd()
    

    You may find The WebDriver Sampler: Your Top 10 Questions Answered article useful.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1