如何使TestNG向testng-customsuite.xml添加参数? [英] How to make TestNG to add parameters to testng-customsuite.xml?

查看:592
本文介绍了如何使TestNG向testng-customsuite.xml添加参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在eclipse中,当我们运行一些具有测试方法的Java文件时,通过右键单击它并选择 Run As-> TestNG Test ,我们可以在控制台"选项卡中看到以下行-

In eclipse, when we run some java file, having test methods, by right clicking on it and selecting Run As -> TestNG Test, we can see following line in 'Console' tab -

[TestNG] Running:
  C:\Users\USER-NAME\AppData\Local\Temp\testng-eclipse-1663319006\testng-customsuite.xml

这意味着TestNG生成并运行testng-cutomsuite.xml.

This means TestNG generates testng-cutomsuite.xml and runs it.

testng-cutomsuite.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default suite">
  <test verbose="2" name="Default test">
    <classes>
      <class name="org.test.saifur.StackOverflowTest"/>
    </classes>
  </test> <!-- Default test -->
</suite> <!-- Default suite -->

但是如果我在项目中已经testng.xml并且它的参数--

But if I've testng.xml in my project and it has parameters like -

<parameter name="browser" value="chrome" />
<parameter name="baseUrl" value="http://stackoverflow.com" />

当我通过eclipse将测试类作为TestNG运行时,我希望将这些参数添加到testng-customsuite.xml中,以便这些参数将在测试脚本中使用.

and when I run my test class as TestNG through eclipse, I want these parameters to be added to testng-customsuite.xml so that those parameters will be used in the test script.

有什么方法可以实现上述目标?

Is there any way by which I can achieve above?

推荐答案

我从testng-users谷歌网上论坛(

I got answer for this question from testng-users google groups(https://groups.google.com/forum/#!topic/testng-users/q7mLtIsEUCc). Posting same here so that if others who are looking for this get benefited -

Set your testng.xml as a TestNG template xml file via Project > Properties > TestNG in eclipse. What you are looking for should now be available. This feature exists only in eclipse and not in IntelliJ

Set your testng.xml as a TestNG template xml file via Project > Properties > TestNG in eclipse. What you are looking for should now be available. This feature exists only in eclipse and not in IntelliJ

这篇关于如何使TestNG向testng-customsuite.xml添加参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆