【发布时间】:2017-11-03 13:47:05
【问题描述】:
我有一个使用 Maven 作为构建工具的 Selenium 项目,我想从 .properties 文件中读取不同的环境详细信息(协议、域、子域等)。是否可以使用 Maven 配置文件,以便根据我在触发 mvn 命令时指定的配置文件在不同的环境(例如 dev、staging、prod)上运行我的测试?
dev.properties:
protocol=http
domain=domain.com
subdomain=www
pom.xml:
<profiles>
<profile>
<id>prod</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>pre_prod</id>
</profile>
<profile>
<id>dev</id>
</profile>
</profiles>
mvn:
mvn clean test -Pdev
然后应该在 java 代码中使用
检索数据System.getProperty("protocol");
System.getProperty("domain");
System.getProperty("subdomain");
非常感谢任何帮助。
谢谢!
【问题讨论】:
标签: java maven selenium properties maven-profiles