我们正在尝试为我们的 Java Web 应用程序进行 Selenium 测试。我们希望能够结合使用 java 函数“System.getProperty”并修改可用于测试的配置文件来快速配置我们的测试。
这样做的原因是我们可以通过简单更改 netbeans 中的下拉框(从 < default config > 到“服务器名称/详细信息”)来测试不同的服务器。我们的服务器运行诸如快照、RC 和修补程序分支之类的东西,因此这对于在引入错误时进行跟踪非常有帮助。
我们目前执行此操作的方法是在每次运行之前修改测试变量以针对我们想要的服务器(糟糕!)。
任何想法都会有帮助
最佳答案
最简单的机制很可能是创建 profiles在您的 POM 中由系统属性或环境变量激活。
Maven 文档中的示例(为清晰起见进行了小幅修改):
<profiles>
<profile>
<activation>
<property>
<name>myProperty</name>
<value>test</value>
</property>
</activation>
...
</profile>
</profiles>
您将使用以下方式手动激活:
mvn groupId:artifactId:goal -DmyProperty=test
You'd enable this based on an environment variable by using the fact that Maven maps environment vars into properties with the name env.…
(with case normalization on Windows):
<profiles>
<profile>
<activation>
<property>
<name>env.ENVIRONMENT</name>
<value>test</value>
</property>
</activation>
...
</profile>
</profiles>
激活方式:
export ENVIRONMENT=test # Does not need to be done every build, just per session
mvn groupId:artifactId:goal
关于java - Maven/Netbeans 有不同的测试配置文件和环境变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10922477/