简体   繁体   English

如何创建TestNg类

[英]How to create TestNg classes

i need help on creating a testng`` scipt.. 我需要在创建Testng Scipt方面的帮助..

i have created one class which contain only @beforesuite which contains the command to open the application 我创建了一个仅包含@beforesuite的类,该类包含打开应用程序的命令

@beforesuite

and second class contains 3 methods 第二类包含3种方法

 @test{method1}
 @test{method2}
 @test{method3}

and third class contains @AfterSuite which closes the application... 第三类包含@AfterSuite,它将关闭应用程序...

@AfterSuite

How to write an xml file to run these classes one after another..?? 如何编写一个xml文件来依次运行这些类。

Is there any better approach to write the script??? 有没有更好的方法来编写脚本?

Any suggestions will be helpfull. 任何建议都会有所帮助。

Thanks in advance. 提前致谢。

Sudhanva Sudhanva

Just put these classes in a test suite file and testNG will take care of running the class which has the @BeforeSuite first, the classes which has @test next, followed by the class which has the @aftersuite tag. 只需将这些类放在测试套件文件中,testNG将负责运行首先具有@BeforeSuite的类,其次具有@test的类,然后是具有@aftersuite标记的类。

<suite>
<test name ="myTest">
<classes>
<class name ="Class1"/> <!-- Class with @beforeSuite-->
<class name ="Class2"/> <!-- Class with @test-->
<class name ="Class3"/> <!-- Class with @afterSuite-->

</classes>
</test>
</suite>

By the way, why do you want to have different classes for @AfterSuite and @BeforeSuite methods. 顺便说一句,为什么要为@AfterSuite和@BeforeSuite方法使用不同的类。 It would have been simpler if all are in the same class. 如果所有人都在同一个班上,那会更简单。 But its just my thought. 但这只是我的想法。

I suggest the following: 我建议以下内容:

  1. Please go through this link , which is a very detailed documentation of TestNG. 请通过此链接 ,它是TestNG的非常详细的文档。 You can set the 'priority' attribute for the Test annotation. 您可以为测试注释设置“优先级”属性。

     //this decides the order in which your tests are executed @test{priority=1} //executed first @test{priority=2} //executed second @test{priority=3} //executed third 
  2. Since this looks like a keyword driven framework, I suggest you to pass the Class names from an excel sheet instead of implementing an XML parser. 由于这看起来像是关键字驱动的框架,因此建议您从excel工作表中传递类名称,而不要实现XML解析器。

  3. To implement the excel sheet read/write, Apache POI is a very good library. 要实现对Excel工作表的读写, Apache POI是一个很好的库。 It supports both xls and xlsx files. 它同时支持xls和xlsx文件。 This way modifying the order of execution would also be easy. 这种修改执行顺序的方法也很容易。 See this link for more info on a keyword driven framework. 有关关键字驱动框架的更多信息,请参见此链接

  4. As far as reporting structure goes, TestNG may generate its own report, but ATU Graphical Reporter has a nice visual appeal. 就报告结构而言,TestNG可以生成自己的报告,但是ATU Graphical Reporter具有很好的视觉吸引力。

This is how to mention your tests in XML file: 这是在XML文件中提及测试的方法:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="SuiteName" verbose="1" data-provider-thread-count="10"
    thread-count="10">
    <test name="TestName" thread-count="10">
        <classes>
            <class name="packageName.ClassName"/>
            <class name="packageName.ClassName" />
        </classes>
    </test>
</suite> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM