【问题标题】:How to create TestNg classes如何创建 TestNg 类
【发布时间】:2015-06-08 06:47:40
【问题描述】:

我需要帮助来创建一个 testng`` scipt..

我创建了一个只包含@beforesuite 的类,其中包含打开应用程序的命令

@beforesuite

第二类包含3个方法

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

第三类包含关闭应用程序的@AfterSuite...

@AfterSuite

如何编写一个xml文件来依次运行这些类..??

有没有更好的方法来编写脚本???

任何建议都会有所帮助。

提前致谢。

苏达瓦

【问题讨论】:

    标签: java testng appium


    【解决方案1】:

    只需将这些类放在一个测试套件文件中,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>
    

    顺便说一句,为什么要为@AfterSuite 和@BeforeSuite 方法设置不同的类。如果所有人都在同一个班级,那就更简单了。但这只是我的想法。

    【讨论】:

      【解决方案2】:

      我建议如下:

      1. 请浏览这个link,这是一个非常详细的TestNG文档。您可以为 Test 注解设置 'priority' 属性。

        //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. 由于这看起来像一个关键字驱动的框架,我建议您从 Excel 表中传递类名称,而不是实现 XML 解析器。

      3. 要实现excel表的读/写,Apache POI是一个非常好的库。它同时支持 xls 和 xlsx 文件。这样修改执行顺序也很容易。有关关键字驱动框架的更多信息,请参阅此link

      4. 就报告结构而言,TestNG 可能会生成自己的报告,但ATU Graphical Reporter 具有很好的视觉吸引力。

      【讨论】:

        【解决方案3】:

        这是在 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> 
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-02-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-05-12
          • 2015-12-14
          • 1970-01-01
          相关资源
          最近更新 更多