是否可以从Testng.xml文件传递变量的值?

问题描述 投票:0回答:1

这是我的代码

public class Environment {

    public static String baseURL;

    public static String setURL(String paramSet) {

        /*
        @BeforeSuite
     @Parameters("env")
         */

        if (paramSet.equalsIgnoreCase("Production")) {
            baseURL = Constants.prodBase;

        } else if (paramSet.equalsIgnoreCase("Staging")) {
            baseURL = Constants.stagingBase;
        }
        return baseURL;
    }

    public static void getURL() {
        RestAssured.baseURI = setURL("Production");
    }
}

在方法getURL()中,我想传递方法setURL(myvariable)中的参数,其值为Staging/Production,来自TestNG.xml文件。我知道我可以将它作为参数传递,但是这个函数getURL()将在每个测试中被调用,并且要求不是为了传递每个方法中的参数。

rest automated-tests testng testng-dataprovider
1个回答
0
投票
Parameters({ "env-param" })
@BeforeSuite
public void prameterTestOne(String env) {
    System.out.println("Test one suite param is: " + env);
}

XML文件

<suite name="Parameter test Suite" verbose="1">
<!-- This parameter will be passed to every test in this suite -->
<parameter name="suite-param" value="Production / Staging" />
<test name="Parameter Test one">
    <classes>
        <class name="someClassName"> 
        </class>
    </classes>
</test>
© www.soinside.com 2019 - 2024. All rights reserved.