Junit脚本中声明的静态驱动程序导致Jmeter中多个加载失败

Junit脚本中声明的静态驱动程序导致Jmeter中多个加载失败,junit,jmeter,load-testing,Junit,Jmeter,Load Testing,在Junit中,在BeforeClass方法中,chorme驱动程序只能是静态的。请参考以下代码:- static WebDriver driver = new HtmlUnitDriver(); @BeforeClass public void beforeTest() { System.out.println("Before Test"); String chromeDriverPath = "C:\\JmeterJunit\\eclipse\\chromed

在Junit中,在BeforeClass方法中,chorme驱动程序只能是静态的。请参考以下代码:-

static WebDriver driver = new HtmlUnitDriver();

@BeforeClass
  public void beforeTest() {

    System.out.println("Before Test");    
    String chromeDriverPath = "C:\\JmeterJunit\\eclipse\\chromedriver_win32\\chromedriver.exe" ;  
    System.setProperty("webdriver.chrome.driver", chromeDriverPath);  
    ChromeOptions options = new ChromeOptions();  
    options.addArguments("--headless", "--disable-gpu", "--ignore-certificate-errors");  

    driver = new ChromeDriver(options);  

    driver.get("http://www.gmail.com/");
    driver.manage().window().maximize();
  }
当驱动程序处于静态状态时,在多个负载测试中,第一个启动的浏览器成功工作,但在进一步启动的浏览器中执行失败。我认为主要原因是声明的静态驱动程序。

考虑迁移到有注释的地方,并且如果您使用注释类,则使用它注释的函数不必是静态的

示例代码:

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class SomeClass {

    private ChromeDriver driver;


    @BeforeAll
    void beforeTest() {

        System.out.println("Before Test");
        String chromeDriverPath = "C:\\\\JmeterJunit\\\\eclipse\\\\chromedriver_win32\\\\chromedriver.exe";
        System.setProperty("webdriver.chrome.driver", chromeDriverPath);
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless", "--disable-gpu", "--ignore-certificate-errors");

        driver = new ChromeDriver(options);

        driver.get("http://www.gmail.com/");
        driver.manage().window().maximize();
    }

    @Test
    void testSomething() {

    }
}
将WebDriver封装到中也是一个好主意


还要注意,有一个与JMeter线程模型完全兼容的模型,因此您不必担心实例化等问题。

我不太明白这里的问题是什么?请你至少详细说明一下你的测试计划是什么样子的好吗?