我在这一点上陷入困境。我成功多次使用过JUnit Sampler。但这次我在尝试运行简单程序时遇到以下错误。
我尝试过不同版本的jemeter。 我将selenium服务器文件复制到jemeter / lib 我将jar文件复制到lib / junit
我尝试了他们的测试课,我尝试了我的课程
2014/11/05 16:27:23 INFO - jmeter.protocol.java.sampler.JUnitSampler: Trying to find constructor with one String parameter returned error: test.BeforeAnnotatedTest.<init>(java.lang.String)**
整个堆栈跟踪:
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Running the test!
2014/11/05 16:27:23 INFO - jmeter.samplers.SampleEvent: List of sample_variables: []
2014/11/05 16:27:23 INFO - jmeter.gui.util.JMeterMenuBar: setRunning(true,*local*)
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Starting 1 threads for group Thread Group.
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Thread will stop on error
2014/11/05 16:27:23 INFO - jmeter.threads.ThreadGroup: Starting thread group number 1 threads 1 ramp-up 1 perThread 1000.0 delayedStart=false
2014/11/05 16:27:23 INFO - jmeter.threads.ThreadGroup: Started thread group number 1
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: All thread groups have been started
2014/11/05 16:27:23 INFO - jmeter.threads.JMeterThread: Thread started: Thread Group 1-1
**2014/11/05 16:27:23 INFO - jmeter.protocol.java.sampler.JUnitSampler: Trying to find constructor with one String parameter returned error: test.BeforeAnnotatedTest.<init>(java.lang.String)**
2014/11/05 16:27:23 INFO - jmeter.threads.JMeterThread: Stop Thread detected by thread: Thread Group 1-1
2014/11/05 16:27:23 INFO - jmeter.threads.JMeterThread: Thread finished: Thread Group 1-1
2014/11/05 16:27:23 INFO - jmeter.engine.StandardJMeterEngine: Notifying test listeners of end of test
2014/11/05 16:27:23 INFO - jmeter.gui.util.JMeterMenuBar: setRunning(false,*local*)
这是我的班级:
package jmeter;
import java.io.File;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class ShoppingCartTest {
public WebDriver driver=null;
//Initializes/loads the driver based on type of browser defined in config file
@Before
public void initDriver(){
driver =new FirefoxDriver();
driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void verifyAnItemToWishList() throws InterruptedException{
driver.get("http://www.google.com")
System.out.println("done");
}
}
答案 0 :(得分:0)
您的代码看起来很好,并且没有问题。确保满足以下条件:
user.classpath
属性指定的位置下)@Before
和@Test
注释 - 您正在使用JUnit4。在这种情况下,您需要在JUnit Request Sampler中勾选Search for JUnit4 annotations
框,如下所示:
有关在JMeter中使用JUnit的所有方面的全面演练,请参阅How to Use JUnit With JMeter指南。
P.S。可能更容易通过WebDriver Sampler来考虑提供JMeter Plugins吗?
答案 1 :(得分:0)
我有类似的问题。它在下载新的Jmeter实例,安装Selenium / WebDriver支持插件和Selenium Server Standalone jar时解决了。所以这个错误可能只是因为没有在Jmeter Lib文件夹中需要Jar。
答案 2 :(得分:0)
我面临同样的问题,它通过添加System.setProperty得到了解决,我dint添加任何其他构造函数(默认构造函数和任何参数构造函数,我甚至试过这两个构造函数,即使那时它没有工作,然后我添加了它工作的System.setProperty,
对于firefox,
System.setProperty("webdriver.gecko.driver", "D:\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
这解决了我的问题。