如何从jmeter运行用Java编写的Selenium脚本? [英] How to run selenium scripts written in java from jmeter?

查看:161
本文介绍了如何从jmeter运行用Java编写的Selenium脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Java的Selenium脚本与JMeter的WebDriver Sampler一起使用.

I am trying to use my Selenium scripts in java with JMeter's WebDriver Sampler.

在webdriver采样器内部,该语言被选择为java,并添加了以下代码:

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();
    }
} 

我遇到以下错误:

java.net.MalformedURLException: unknown protocol: data
at java.net.URL.<init>(URL.java:600)
at java.net.URL.<init>(URL.java:490)
at java.net.URL.<init>(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)

但是,用javascript编写的测试也可以正常工作.

However, tests written in javascripts work just fine.

这是什么问题?怎么解决呢?

What is the problem here? How to solve it?

推荐答案

您不应实例化WebDriver实例,只要您添加

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.

完成后,您应该可以使用WDS.browser速记,例如:

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();

也不要调用quit()方法,测试完成后,WebDriver实例将关闭.

Also don't call quit() method, the WebDriver instance(s) will be shut down when test will be finished.

请参见将硒与JMeter的WebDriver Sampler一起使用指南以开始使用Selenium和JMeter集成.

See Using Selenium with JMeter's WebDriver Sampler guide to get started with Selenium and JMeter integration.

这篇关于如何从jmeter运行用Java编写的Selenium脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆