TestNG测试正在使用一个测试的参数,而不是它们自己的参数。

huangapple 未分类评论48阅读模式
英文:

TestNG tests are using the parameter of one test instead of their own

问题

我正在使用带有参数的TestNG,对于一个测试用例,它可以正常工作。但是一旦我添加另一个测试用例,参数就开始混乱。它们不再使用在xml文件中定义的各自的参数,而只使用一个测试用例的参数。

例如,在这个文件中,Test1和Test2都使用了值为value_1key参数。以下是我在设置中如何调用这些参数(我使用@BeforeMethod,因为我们需要它来进行BrowserStack设置):

@Parameters(value={"key"})
@BeforeMethod(alwaysRun=true)
public void setup(String key) {

这种情况发生的原因是什么?我找不到其他有相同问题的人。

英文:

I'm using TestNG with parameters and it works fine for one test. But as soon as I add another test, the parameters start messing up. Instead of using their own parameters as defined in the xml file, they only use the parameter of one test.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

&lt;suite name=&quot;Test suite&quot; &gt;
	&lt;parameter name=&quot;key&quot; value=&quot;value_1&quot;/&gt;
	&lt;test name=&quot;Test1&quot; &gt;	
		&lt;classes&gt;
			&lt;class name=&quot;package.Test&quot; &gt;
				&lt;methods&gt;
					&lt;include name=&quot;method1&quot; /&gt;
				&lt;/methods&gt;
			&lt;/class&gt;
		&lt;/classes&gt;
	&lt;/test&gt;
	&lt;parameter name=&quot;key&quot; value=&quot;value_2&quot;/&gt;
	&lt;test name=&quot;Test2&quot; &gt;	
		&lt;classes&gt;
			&lt;class name=&quot;package.Test&quot; &gt;
				&lt;methods&gt;
					&lt;include name=&quot;method1&quot; /&gt;
				&lt;/methods&gt;
			&lt;/class&gt;
		&lt;/classes&gt;
	&lt;/test&gt;
 &lt;/suite&gt;

<!-- end snippet -->

For example on this file, both Test1 and Test2 use key with value value_1.
Here's how I call the parameters in my setup (I use @BeforeMethod because we need it for BrowserStack)

	@Parameters(value={&quot;key&quot;})
	@BeforeMethod(alwaysRun=true)
	public void setup(String key) {

Is there a reason why this is happening? I can't find anyone else with the same issue

答案1

得分: 0

如果您想并行执行测试,我建议您使用下面提到的BrowserStack Sample TestNg GitHub仓库。这对我来说效果不错。
https://github.com/browserstack/testng-appium-app-browserstack

英文:

If you want to execute test in parallel I would recommend you to use BrowserStack Sample TestNg GitHub Repo as mentioned below. It worked fine for me.
https://github.com/browserstack/testng-appium-app-browserstack

huangapple
  • 本文由 发表于 2020年5月4日 12:49:41
  • 转载请务必保留本文链接:https://java.coder-hub.com/61585378.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定