banner



How To Create Xml File In Selenium Testng

In this post, we will learn How To Create TestNG XML File . We know this there are so many uses of this file.

In real time project, we have never a single class, instead of that we have many classes for every functionality like loginTestcase.java, forgotpasswordTestCases.java and many. So it's not possible to run each test case separately.

We need to do integrate between test classes, so now testng.xml comes into picture.

Why testng.xml – for integrating test cases classes and many other things are there which explained later in this post.

To start our project follows steps.

Create LoginTestcases.java and ForgotPasswordTestcases.java

Then start putting test cases inside every class. Make one pass and other failed in each class total 2 test cases will be passed [one in every class].

See below code.

package SamplePkg;  import org.testng.Assert; import org.testng.annotations.Test;    public class LoginTestCases {          @Test(priority=0, alwaysRun=true,dependsOnMethods="checkSpecialCharUname")     public void checkBlankUname() {                  Assert.assertEquals("Blank not Allowed", "Blank not Allowed");              }          @Test     public void checkSpecialCharUname() {                  Assert.assertEquals("Special char not allowed", "Special char not allowed");     }                  }              

How to generate testng.xml?

Right click project >> goto convert to testng >> finish.

convert testng xml

Now you can see testng.xml generated in our project.

testng.xml

In below image you can see both classes added.

testng.xml

In live company projects this file is created only once.

Every automation engineer has to place his class name there in this file once test class is created so that it will start running in integration suite.

One more this we need to explore @Test annotation in client.

testng annotation

In the above snap priority is attributes of test annotations, we have many attributes like this for test annotation.

  • alwaysRun – If set to true, this test method will always be run even if it depends on a method that failed.
  • dataProvider – The name of the data Provider for this test method.
  • dependsOnGroups – The list of groups this method depends on.
  • dependsOnMethods – The list of methods this method depends on.
  • enabled –  Whether methods on this class/method are enabled.
  • invocationCount – The number of times this method should be invoked.
  • invocationTimeOut – The maximum number of milliseconds this test should take for the cumulated time of all the invocation counts. This attributes will be ignored if invocation Count is not specified.
  • Priority – The priority for this test method. Lower priority will be scheduled first.
  • threadPoolSize – This size of the thread pool for this method. This method will be invoked from multiple threads as specified by invocation count.

Note: This attributes is ignored If invocationCount is not specified.

If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

Window Handling in Selenium

How To Create Xml File In Selenium Testng

Source: https://automationtestings.com/how-create-testng-xml/

Posted by: blanchtuadve2002.blogspot.com

0 Response to "How To Create Xml File In Selenium Testng"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel