You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IntelliJ中除运行配置外还有哪里可设置Java VM系统属性?

解决方案

方案1:修改Cucumber Java运行配置模板(最推荐)

  • 打开IntelliJ顶部菜单栏的「运行」>「编辑配置」(Run > Edit Configurations)
  • 点击左下角的「编辑配置模板」(Edit configuration templates)按钮
  • 在弹出的模板列表里找到「Cucumber Java」选项点击
  • 在右侧的「VM选项」(VM options)输入框里填入你需要的参数:-Dwebdriver.chrome.driver=src/test/resources/drivers/windows/chromedriver.exe
  • 点击「应用」>「确定」保存即可

后续所有自动生成的单个Cucumber测试运行配置,都会自动继承这个模板里的VM参数,不需要再手动修改。

方案2:在项目的Maven pom.xml中统一配置(适合全团队统一配置场景)

如果你的项目用Maven管理测试,可以直接在pom.xml的maven-surefire-plugin配置里添加系统参数,所有通过IntelliJ跑的测试都会自动读取该配置:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>3.2.2</version>
      <configuration>
        <systemPropertyVariables>
          <webdriver.chrome.driver>src/test/resources/drivers/windows/chromedriver.exe</webdriver.chrome.driver>
        </systemPropertyVariables>
      </configuration>
    </plugin>
  </plugins>
</build>

方案3:通过测试代码硬编码(兜底方案,不推荐跨环境共享时使用)

可以在Cucumber测试的Hook或者启动类最开头手动设置系统属性,不需要修改IDE配置:

@BeforeAll
public static void setChromeDriverPath() {
    System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/windows/chromedriver.exe");
}

内容的提问来源于stack exchange,提问作者Neil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.03 17:39:03