如何解决无法初始化io.cucumber.core.options.PluginOption类
我有一段Cucumber + JUNIT + Selenium WebDriver代码在JMeter中用于负载测试。 以下是一段代码:
package runner;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import cucumber.api.cli.Main;
import pageobjects.alinea.AssetsMetadataPage;
public class TestRunner{
private static Logger Log = LogManager.getLogger(AssetsMetadataPage.class);
public ClassLoader load;
public TestRunner(String str) {
// TODO Auto-generated constructor stub
this();
}
public TestRunner() {
// TODO Auto-generated constructor stub
}
// Test method is defined with Cucumber Main run method.
// "-g" signifies glue code (package where the code is),"-t" signifies the tag. The location of the feature file which defines the test scripts
@Test
public void runTest() throws Throwable {
try {
Main.run(new String[]{"-g","step_definitions","-t","@upload","src/test/resources/features/addcontent.feature"},ClassLoader.getSystemClassLoader());
//log.info("Print");
Log.info("Print");
} catch (Exception e) {
e.printStackTrace();
}
}
// Post Test what the JUNIT test needs to do
}
这是功能文件:
@Upload
Scenario: User upload the image
Given navigate to folder and upload a picture
并将这些jar导入到jmeter的lib文件夹中:
junit-4.13.jar
cobertura-1.8.jar
mockito-core-3.5.5.jar
cucumber-core-5.7.0.jar
cucumber-java-5.7.0.jar
cucumber-junit-5.7.0.jar
cucumber-jvm-deps-1.0.6.jar
gherkin-15.0.2.jar
selenium-server-standalone-2.53.0.jar
当我尝试从Eclipse运行时,没有问题,执行完成没有任何故障。 但是当我从jmeter运行此程序时出现以下错误:
**Error -- runTest(org.apache.jmeter.protocol.java.sampler.JUnitSampler$AnnotatedTestCase): io/cucumber/plugin/SummaryPrinter
Trace -- java.lang.NoClassDefFoundError: io/cucumber/plugin/SummaryPrinter
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/java.net.URLClassLoader.defineClass(URLClassLoader.java:550)
at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:458)
at java.base/java.net.URLClassLoader$1.run(URLClassLoader.java:452)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:451)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at io.cucumber.core.options.PluginOption$1.<init>(PluginOption.java:37)
at io.cucumber.core.options.PluginOption.<clinit>(PluginOption.java:36)
at io.cucumber.core.options.RuntimeOptions.addDefaultFormatterIfAbsent(RuntimeOptions.java:60)
at io.cucumber.core.options.RuntimeOptionsBuilder.build(RuntimeOptionsBuilder.java:132)
at io.cucumber.core.cli.Main.run(Main.java:61)
at runner.TestRunner.runTest(TestRunner.java:31)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.jmeter.protocol.java.sampler.JUnitSampler$AnnotatedTestCase.runTest(JUnitSampler.java:595)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at org.apache.jmeter.protocol.java.sampler.JUnitSampler.sample(JUnitSampler.java:395)
at org.apache.jmeter.threads.JMeterThread.doSampling(JMeterThread.java:630)
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.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.ClassNotFoundException: io.cucumber.plugin.SummaryPrinter
at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:589)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 28 more**
**
我是否缺少在jmeter中为黄瓜选项添加的内容?预先感谢您的回答!
解决方法
我认为您无法在JMeter中运行Cucumber测试,因为JMeter的JUnit Sampler使用Java Reflection API来依次调用以JUnit annotations和Cucumber注释的功能在运行时从功能文件生成Java类,并且此行为与JMeter不兼容。
因此,与其使用真实的浏览器进行性能测试,我不建议将您的Cucumber测试转换为“纯” JMeter测试,足以通过HTTP(S) Test Script Recorder通过JMeter的configuring the proxy in your Selenium code运行它,您将获得HTTP Request采样器将执行文件上传。
在执行之前,请务必确保将您的Cucumber测试将要上传的文件复制到JMeter安装的“ bin”文件夹中,否则JMeter将无法正确捕获请求,请参阅Recording File Uploads with JMeter文章有关更多详细信息。
最后但并非最不重要的一点是,现代浏览器占用大量资源,例如Firefox 78 requires 1 CPU core and 2GB of RAM 每个浏览器实例,并且使用JMeter,您只需一次即可轻松模拟数百个虚拟用户浏览器
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。