【问题标题】:What is the best way to pass environment variable to TestNG for Automation将环境变量传递给 TestNG 以实现自动化的最佳方法是什么
【发布时间】:2017-05-24 11:41:43
【问题描述】:

我想为数据库连接和许多其他实用程序传递环境变量。目前,我将 POM.xml 中的这个变量作为一个工作正常的变量传递,但为多个环境创建了多个 pom.xml。有没有其他标准方法可以实现这一点?

【问题讨论】:

    标签: maven testing automation testng maven-surefire-plugin


    【解决方案1】:

    您可能只想为此利用 JVM 参数。

    例如,您可以在代码中定义如下内容,其中您还为 JVM 参数定义默认值:

    String username = System.getProperty("username","defaultUser");
    String password = System.getProperty("password","password");
    

    您现在可以使用-Dusername=sa -Dpassword=sa通过命令行为这些值传递值

    【讨论】:

      猜你喜欢
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 2018-09-29
      • 2013-12-29
      相关资源
      最近更新 更多