简体   繁体   中英

How to create TestNg classes

i need help on creating a testng`` scipt..

i have created one class which contain only @beforesuite which contains the command to open the application

@beforesuite

and second class contains 3 methods

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

and third class contains @AfterSuite which closes the application...

@AfterSuite

How to write an xml file to run these classes one after another..??

Is there any better approach to write the script???

Any suggestions will be helpfull.

Thanks in advance.

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.

<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. 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. 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.

  3. To implement the excel sheet read/write, Apache POI is a very good library. It supports both xls and xlsx files. 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.

This is how to mention your tests in XML file:

<?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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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