这是 testNG.xml 文件:
这是 day4.java 文件
]
这是控制台结果。
为什么我会遇到这个问题?
我也尝试了@optional 方法,但这样我得到了 NULL 值。
您没有在 testng.xml 文件中传递任何参数值。您的 xml 文件应如下所示
<suite name="Parameter test Suite" verbose="1">
<!-- This parameter will be passed to every test in this suite -->
<parameter name="suite-param" value="suite level parameter" />
<test name="Home loan">
<classes>
<class name="test">
<methods>
<include name="demo" />
</methods>
</class>
</classes>
</test>
</suite>
这里参数名称和值将是您的URL
有关 xml 文件的更多详细信息 https://developers.perfectomobile.com/display/TT/TestNG+-User+specified+TestNG+xml+parameters
因此,您必须进行 2 处更改。
您的代码应如下所示:
@Parameter("URL")
@Test
public void webloginHomeloan(@Optional String urlname){
System.out.println("WebloginHome");
System.out.println("Parameterized value is:"+ URL)
}
在参数中添加@Optional,因为您没有从 String urlname 传递任何值并将“urlname”更改为“URL”