1

在并行运行测试时,有时我会收到以下消息:

org.openqa.selenium.NoSuchSessionException: invalid session id

我正在使用 WebDriverManager:

private WebDriver driver;
    static { WebDriverManager.chromedriver().setup(); }

public Browser() {
    Map<String, Object> prefs = new HashMap<>();
    ChromeOptions chromeOptions = new ChromeOptions();
    if (GVDLUtils.isOnServerEnv()) {
        System.out.println("working on server");
        chromeOptions.addArguments("--window-size=1400,900");
        chromeOptions.addArguments("--headless");
        chromeOptions.addArguments("--no-proxy-server");
        chromeOptions.addArguments("--proxy-server='direct://'");
        chromeOptions.addArguments("--proxy-bypass-list=*");
    }

    String FilesPath = System.getProperty("user.dir") + File.separator + SeleniumUtilities.getDownloadsPath();
    prefs.put("download.default_directory", FilesPath);
    chromeOptions.setExperimentalOption("prefs", prefs);

    this.driver = new ChromeDriver(chromeOptions);

    if (!GVDLUtils.isOnServerEnv()) {
        this.driver.manage().window().maximize();
    }
}

我在每次测试之前启动新浏览器:

public static String redux = "";
protected Browser browser;

@BeforeMethod
public void initTest() {
    this.browser = new Browser();
    JavascriptExecutor jse = (JavascriptExecutor) this.browser.getDriver();
    jse.executeScript("localStorage.setItem('redux', '"+redux+"')");
}

任何想法为什么会发生?

4

0 回答 0