2

I want to execute (I would like to extend later) my first Java based Selenium test in Apache Jmeter but I got an error message in the log section:

Here is my simple code:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

System.setProperty("webdriver.gecko.driver","c:\\DEVTOOLS\\PERFORMANCE_TEST\\FIREFOX_GECKO_DRIVER\\geckodriver.exe")
WebDriver driver = new FirefoxDriver();

String url="https://www.google.com/")
driver.get(baseUrl);
driver.close();

This is the error:

2020-06-30 14:52:20,702 INFO o.a.j.e.StandardJMeterEngine: Running the test!
2020-06-30 14:52:20,702 INFO o.a.j.s.SampleEvent: List of sample_variables: []
2020-06-30 14:52:20,703 INFO o.a.j.g.u.JMeterMenuBar: setRunning(true, *local*)
2020-06-30 14:52:20,710 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2020-06-30 14:52:20,710 INFO o.a.j.e.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2020-06-30 14:52:20,710 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
2020-06-30 14:52:20,710 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=1 ramp-up=1 delayedStart=false
2020-06-30 14:52:20,710 INFO o.a.j.t.ThreadGroup: Started thread group number 1
2020-06-30 14:52:20,710 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
2020-06-30 14:52:20,711 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2020-06-30 14:52:20,719 ERROR o.a.j.p.j.s.JSR223Sampler: Problem in JSR223 script JSR223 Sampler, message: javax.script.ScriptException: In file: inline evaluation of: ``import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.Firefox . . . '' Encountered "WebDriver" at line 5, column 1.
 in inline evaluation of: ``import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.Firefox . . . '' at line number 5
javax.script.ScriptException: In file: inline evaluation of: ``import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.Firefox . . . '' Encountered "WebDriver" at line 5, column 1.
 in inline evaluation of: ``import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.Firefox . . . '' at line number 5
    at bsh.engine.BshScriptEngine.evalSource(BshScriptEngine.java:82) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
    at bsh.engine.BshScriptEngine.eval(BshScriptEngine.java:46) ~[bsh-2.0b6.jar:2.0b6 2016-02-05 05:16:19]
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) ~[?:1.8.0_202]
    at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:224) ~[ApacheJMeter_core.jar:5.3]
    at org.apache.jmeter.protocol.java.sampler.JSR223Sampler.sample(JSR223Sampler.java:72) [ApacheJMeter_java.jar:5.3]
    at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:630) [ApacheJMeter_core.jar:5.3]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:558) [ApacheJMeter_core.jar:5.3]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:5.3]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:5.3]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_202]
2020-06-30 14:52:20,719 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2020-06-30 14:52:20,719 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2020-06-30 14:52:20,720 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2020-06-30 14:52:20,720 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

I don't know exactly why is happening because every jars are copied into: Apache Jmeter lib folder and lib/ext/ folder as well.

I would like to leave the WDS.Sampler if it possible. This is the reason why I started using SR223Sampler.

UPDATES:

Here is the final solution what I have. It works as I expected.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;

System.setProperty("webdriver.gecko.driver","c:\\DEVTOOLS\\PERFORMANCE_TEST\\FIREFOX_GECKO_DRIVER\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions().setAcceptInsecureCerts(true);

WebDriver driver = new FirefoxDriver(options);

String expectedTitle = "Google";
String actualTitle = "";
String baseUrl = "https://google.com";

driver.get(baseUrl);

actualTitle = driver.getTitle();

if (actualTitle.contentEquals(expectedTitle)){
    System.out.println("Test Passed!");
    } else {
    System.out.println("Test Failed");
    }

Thread.sleep(5000);
driver.close();

1 Answer 1

1

The issue is due to a malformed as a result of a syntax issue in the line:

String url="https://www.google.com/")

You need to pass the proper url and replace the line as:

String baseUrl = "https://www.google.com/";

Then pass the url string to the get() method as follows:

driver.get(baseUrl);  

Additionally, on systems the drive is C: (in uppercase) instead of c: (in lowercase). Effectively, the line would be:

System.setProperty("webdriver.gecko.driver","C:\\DEVTOOLS\\PERFORMANCE_TEST\\FIREFOX_GECKO_DRIVER\\geckodriver.exe")
Sign up to request clarification or add additional context in comments.

2 Comments

Ohh thanks. It is a shame from my side :'(. I appreciate your help! There was one more issue, namely the ; missed from the System.setProperty line.
@Imi There's nothing shame in asking a question when we are out of ideas. Have a great learning ahead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.