我有一个包含 junit 测试的 Java 项目,需要通过 Jenkins 在不同的测试环境(Dev、Staging 等)上运行。
如何将项目的构建设置到不同的环境以及如何将 url、用户名和密码传递给 maven?
我可以使用 maven 3 配置文件从属性文件中读取环境 url、用户名和密码吗?
编辑:我已将配置文件添加到项目 POM:
<profiles>
        <profile>
            <id>Integration</id>
        </profile>
        <profile>
            <id>Staging</id>
        </profile>
        <profile>
            <id>PP1</id>
        </profile>
        <profile>
            <id>PP2</id>
        </profile>
        <profile>
            <id>PP3</id>
        </profile>
</profiles>
如何将 url、用户名和密码传递给这些配置文件?
目前,测试正在从属性文件中获取测试环境详细信息:
 public  class BoGeneralTest extends TestCase {
    protected WebDriver driver;
    protected BoHomePage boHomePage;
    protected static Properties systemProps;
    String url = systemProps.getProperty("Url");
    String username = systemProps.getProperty("Username");
    String password = systemProps.getProperty("Password");
    int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements"));
    static {
        systemProps = new Properties();
        try {
            systemProps.load(new FileReader(new File("src/test/resources/environment.properties")));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
编辑2:
在测试运行器类中实现的更改:
public class BoGeneralTest extends TestCase {
    protected WebDriver driver;
    protected BoHomePage boHomePage;
    protected static Properties systemProps;
    String url = systemProps.getProperty("Url");
    String username = systemProps.getProperty("Username");
    String password = systemProps.getProperty("Password");
    int defaultWaitTime = Integer.parseInt(systemProps.getProperty("waitTimeForElements"));
    String regUsername = RandomStringUtils.randomAlphabetic(5);
    final static String appConfigPath = System.getProperty("appConfig");
    static {
        systemProps = new Properties();
        try {
            systemProps.load(new FileReader(new File(appConfigPath)));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }