I am trying to use my Selenium scripts in java with JMeter's WebDriver Sampler.
Inside the webdriver sampler, the language is seleced to java, and the following code added:
package automationFramework;
public class FirstTestCase {
public static void main(String[] args) {
// Create a new instance of the Firefox driver
WebDriver driver = new ChromeDriver();
//Launch the Online Store Website
driver.get("www.google.com");
// Print a Log In message to the screen
System.out.println("Successfully opened the website www.google.com");
//Wait for 5 Sec
Thread.sleep(5);
// Close the driver
driver.quit();
}
}
I am facing the following error:
java.net.MalformedURLException: unknown protocol: data
at java.net.URL.(URL.java:600)
at java.net.URL.(URL.java:490)
at java.net.URL.(URL.java:439)
at com.googlecode.jmeter.plugins.webdriver.sampler.WebDriverSampler.sample(WebDriverSampler.java:80)
at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:475)
at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:418)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:249)
at java.lang.Thread.run(Thread.java:745)
However, tests written in javascripts work just fine.
What is the problem here? How to solve it?
解决方案
You should not be instantiating WebDriver instance, JMeter does it for you given you add Chrome Driver Config element to your Test Plan and configure path to the ChromeDriver executable.
Once done you should be able to use WDS.browser shorthand like:
WDS.sampleResult.sampleStart();
WDS.browser.get("http://google.com");
WDS.log.info("Successfully opened the website www.google.com");
Thread.sleep(5000);
WDS.sampleResult.sampleEnd();
Also don't call quit() method, the WebDriver instance(s) will be shut down when test will be finished.
See Using Selenium with JMeter's WebDriver Sampler guide to get started with Selenium and JMeter integration.