【问题标题】:Selenium: Run Automation code with different URL for three environmentsSelenium:为三种环境运行具有不同 URL 的自动化代码
【发布时间】:2019-11-29 11:40:07
【问题描述】:

我有一个 Java 自动化测试框架。我需要这段代码在 SIT、UAT 和 Prod 等多个环境中运行,但所有这些环境都有不同的 URL。

sit-config.properties

主页 = XXX

uat-config.properties

主页 = YYY

Maven 配置文件

<profiles>
    <profile>
        <id>sit</id>
        <activation>
            <property>
                <name>environment</name>
                <value>sit</value>
            </property>
        </activation>
    </profile>
    <!-- mvn -Denvironment=sit clean test -->

    <profile>
        <id>uat</id>
        <activation>
            <property>
                <name>environment</name>
                <value>uat</value>
            </property>
        </activation>
    </profile>

  </profiles>

我有一个 Java Owner 库的示例,但 testng 不是 Maven。 http://www.testautomationguru.com/selenium-webdriver-how-to-execute-tests-in-multiple-environments/

问题: 如何将 Java Owner 库与 Maven 配置文件集成?

请帮忙。谢谢。

【问题讨论】:

    标签: java maven selenium


    【解决方案1】:

    看起来您对于不同的环境 sat、uat 和 prod 有不同的数据属性文件。实际上,您不需要为每个执行环境创建单独的配置文件。按照这个:

    1:在pom开头创建一个全局属性。让属性的名称是属性文件,并给它一个默认名称,如 sat-config.properties

    <properties>
        <propertyFile>sit-config.properties</propertyFile>
    </properties>
    

    2:更新读取器逻辑以从系统属性中读取文件名,如

    System.getProperty("propertyFile");
    

    3:现在你可以像

    一样从命令行传递文件名
    mvn clean test -DpropertyFile=uat-config.properties
    

    【讨论】:

    • 如果我有三个属性文件怎么办? sit-config.properties、uat-config.properties 和 prod-config.properties。
    • 它可以运行 n 个文件。您只需要在运行时在 maven 命令中设置 -DpropertyFile={name of your file}。
    • 其实maven命令中给出的值最终会在运行时替换pom文件中提到的值
    • 第 1 步似乎没用,因为它在运行时被 maven 命令覆盖。我可以跳过吗?
    • 实际上它不会为您创建一个运行时变量并使用默认值对其进行初始化。如果您不想这样做,那么您需要使用 System.setProperty("propertyFile","name of file ")
    猜你喜欢
    • 2019-11-21
    • 2022-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2012-02-09
    • 1970-01-01
    • 2021-05-05
    相关资源
    最近更新 更多