<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TestNG Archives | Selenium Webdriver Appium Complete Tutorial</title>
	<atom:link href="https://automationtesting.in/category/testng/feed/" rel="self" type="application/rss+xml" />
	<link>https://automationtesting.in/category/testng/</link>
	<description>Automation Testing</description>
	<lastBuildDate>Mon, 24 Apr 2017 23:52:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.2</generator>
	<item>
		<title>Read data from Excel to DataProvider in Selenium</title>
		<link>https://automationtesting.in/read-data-from-excel-dataprovider-in-selenium/</link>
					<comments>https://automationtesting.in/read-data-from-excel-dataprovider-in-selenium/#comments</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Sun, 23 Apr 2017 13:38:41 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[@DataProvider]]></category>
		<category><![CDATA[apache poi]]></category>
		<category><![CDATA[Automation (Industry)]]></category>
		<category><![CDATA[Data provider]]></category>
		<category><![CDATA[Data-driven Testing]]></category>
		<category><![CDATA[excel to dataprovider]]></category>
		<category><![CDATA[how to read data from excel]]></category>
		<category><![CDATA[Microsoft Excel (Software)]]></category>
		<category><![CDATA[Passing data to dataprovider from excel]]></category>
		<category><![CDATA[poi]]></category>
		<category><![CDATA[poi api]]></category>
		<category><![CDATA[read data from excel in java]]></category>
		<category><![CDATA[read data from excel to dataprovider]]></category>
		<category><![CDATA[Selenium (Software)]]></category>
		<category><![CDATA[Software Framework (Software Genre)]]></category>
		<category><![CDATA[Webdriver]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=1563</guid>

					<description><![CDATA[<p>Read data from excel to dataprovider in selenium will explain how we can get the data from excel sheet and will pass the same to testng dataprovider. While working with the data driven testing we need to pass so much of data to the test methods as parameters. But maintaining the data is very difficult [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/read-data-from-excel-dataprovider-in-selenium/">Read data from Excel to DataProvider in Selenium</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
<span style="font-weight: 400;">Read data from excel to dataprovider in </span><a href="http://www.seleniumhq.org/"><span style="font-weight: 400;">selenium</span></a><span style="font-weight: 400;"> will explain how we can get the data from excel sheet and will pass the same to testng dataprovider. While working with the data driven testing we need to pass so much of data to the test methods as parameters. But maintaining the data is very difficult within the method as sometimes we need to pass multiple data sets to same method as parameters to test the same functionality.</span></p>
<div class="post-video"><iframe loading="lazy" title="Read data from Excel to DataProvider in Selenium" width="1165" height="874" src="https://www.youtube.com/embed/wJWFXyaZFlo?wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p><span style="font-weight: 400;">To simplify this we will use </span><a href="https://automationtesting.in/testng-dataprovider/"><span style="font-weight: 400;">TestNG DataProvider</span></a><span style="font-weight: 400;"> concept. Will read multiple sets of data from excel and will place the same in dataprovider object array and will pass the same to the test method as parameters. Here, we need to remember one thing is; dataprovider array values and test method parameter values must be same. </span></p>
<p><span style="font-weight: 400;">We will take one sample program to read data from excel to dataprovider. Here to interact with the excel sheet will use </span><a href="https://poi.apache.org/"><span style="font-weight: 400;">Apache POI</span></a><span style="font-weight: 400;"> api.  Will read some sample data from excel to dataprovider and will print the same. </span><br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p><b>Below is the sample Excel File:</b></p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/Sample-Excel.png"><img decoding="async" loading="lazy" class="alignnone size-full wp-image-1040" src="https://automationtesting.in/wp-content/uploads/2016/12/Sample-Excel.png" alt="Sample Excel" width="706" height="374" srcset="https://automationtesting.in/wp-content/uploads/2016/12/Sample-Excel.png 706w, https://automationtesting.in/wp-content/uploads/2016/12/Sample-Excel-300x159.png 300w" sizes="(max-width: 706px) 100vw, 706px" /></a></p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
<b>Below is the sample program:</b></p>
<pre class="brush: java; highlight: [10,11,22,23,24,25,26,27,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47]; title: ; notranslate">
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ExcelToDataProvider {
    
    String xlFilePath = &quot;/KRISHNA VOLUME/Jar Files/poi-3.16-beta1/TestData.xlsx&quot;;
    String sheetName = &quot;Credentials&quot;;
    ExcelApiTest eat = null;
    
    @Test(dataProvider = &quot;userData&quot;)
    public void fillUserForm(String userName, String passWord, String dateCreated, String noOfAttempts, String result)
    {
       System.out.println(&quot;UserName: &quot;+ userName);
       System.out.println(&quot;PassWord: &quot;+ passWord);
       System.out.println(&quot;DateCreated: &quot;+ dateCreated);
       System.out.println(&quot;NoOfAttempts: &quot;+ noOfAttempts);
       System.out.println(&quot;Result: &quot;+ result);
       System.out.println(&quot;*********************&quot;);
    }
    
    
    @DataProvider(name=&quot;userData&quot;)
    public Object&#x5B;]&#x5B;] userFormData() throws Exception
    {
        Object&#x5B;]&#x5B;] data = testData(xlFilePath, sheetName);
        return data;
    }
    
    public Object&#x5B;]&#x5B;] testData(String xlFilePath, String sheetName) throws Exception
    {
        Object&#x5B;]&#x5B;] excelData = null;
        eat = new ExcelApiTest(xlFilePath);
        int rows = eat.getRowCount(sheetName);
        int columns = eat.getColumnCount(sheetName);
                
        excelData = new Object&#x5B;rows-1]&#x5B;columns];
        
        for(int i=1; i&lt;rows; i++)
        {
            for(int j=0; j&lt;columns; j++)
            {
                excelData&#x5B;i-1]&#x5B;j] = eat.getCellData(sheetName, j, i);
            }
            
        }
        return excelData;
    }
}
</pre>
<p><span style="font-weight: 400;">In the above program, </span><b>fillUserForm() </b><span style="font-weight: 400;">is a test method and will accept 5 parameters. So, we need to read data from excel to dataprovider to pass these 5 parameters multiple times. For this we will use </span><b>testData()</b><span style="font-weight: 400;"> method to read the data from the excel sheet using Apache POI. It takes two parameters called excel file path and sheet name. By using these two parameters it will read the excel data and store in Object array.</span></p>
<p><b>userFormData()</b><span style="font-weight: 400;"> is actually a dataProvider to pass the data to test method. It will get the data from the </span><b>testData() </b><span style="font-weight: 400;">method and the return type of this method is Object array. We have separated this testData() method from the dataProvider because there is a chance of using the same logic more than one test method. In this scenario we can use the same testData() method to create a separate dataProvider for each and every test method to get the parameters.</span></p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
<b>Output of the above program is:</b></p>
<p><a href="https://automationtesting.in/wp-content/uploads/2017/04/Excel-to-DataProvider-output.png"><img decoding="async" loading="lazy" class="alignnone size-full wp-image-1564" src="https://automationtesting.in/wp-content/uploads/2017/04/Excel-to-DataProvider-output.png" alt="Excel to DataProvider" width="600" height="570" srcset="https://automationtesting.in/wp-content/uploads/2017/04/Excel-to-DataProvider-output.png 600w, https://automationtesting.in/wp-content/uploads/2017/04/Excel-to-DataProvider-output-300x285.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a></p>
<p><span style="font-weight: 400;">Can get the code for how we can get </span><a href="https://automationtesting.in/row-count-and-column-count-in-excel/"><span style="font-weight: 400;">row count and column count in excel here</span></a><span style="font-weight: 400;">.</span></p>
<p><span style="font-weight: 400;">Please watch the youtube video for better understanding and more examples.</span><br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-1563" data-postid="1563" class="themify_builder_content themify_builder_content-1563 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/read-data-from-excel-dataprovider-in-selenium/">Read data from Excel to DataProvider in Selenium</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/read-data-from-excel-dataprovider-in-selenium/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Running TestNG Tests Programmatically</title>
		<link>https://automationtesting.in/running-testng-tests-programmatically/</link>
					<comments>https://automationtesting.in/running-testng-tests-programmatically/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 14:42:53 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[convert testng.xml into code]]></category>
		<category><![CDATA[execute testng programmatically]]></category>
		<category><![CDATA[how to execute testng using code]]></category>
		<category><![CDATA[how to run testng using code]]></category>
		<category><![CDATA[run testng programmatically]]></category>
		<category><![CDATA[testng.xml]]></category>
		<category><![CDATA[XmlClass]]></category>
		<category><![CDATA[XmlSuite]]></category>
		<category><![CDATA[XmlTest]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=987</guid>

					<description><![CDATA[<p>Running testng tests programmatically will discuss about how to execute testng tests programmatically.  Till now we have executed all the tests using testng.xml file in the previous blogs. In this blog, will see how to avoid xml file (i.e testng.xml) and execute the same functionality using java file(i.e. programmatically). We have some limitations with the [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/running-testng-tests-programmatically/">Running TestNG Tests Programmatically</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img src='http://automationtesting.in/wp-content/uploads/2016/12/Running-TestNG-programmatically.png'></p><p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Running testng tests programmatically will discuss about how to execute testng tests programmatically.  Till now we have executed all the tests using testng.xml file in the previous blogs. In this blog, will see how to avoid xml file (i.e testng.xml) and execute the same functionality using java file(i.e. programmatically).</p>
<div class="post-video"><iframe loading="lazy" title="Running TestNG Tests Programmatically" width="1165" height="655" src="https://www.youtube.com/embed/oJ82AKgXIWA?t=25s&#038;wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>We have some limitations with the xml file that xml files are static and can not be changed at runtime. As per the requirement sometimes we need to change some of the configurations at runtime, which is depends on an Excel sheet or database data interaction. To achieve these kinds of things TestNG provided a feature to define and execute TestNG tests through program by using some of the APIs provided by the TestNG.</p>
<p>All the things which is possible with the testng.xml file can be achieved by the API provided by TestNG. And after completion of writing the program we can easily execute the code as this is a normal java file.</p>
<p>Below are the two sample programs we can execute these files using testng program.</p>
<p><strong>First Sample java file:</strong></p>
<pre class="brush: java; title: ; notranslate">
import org.testng.Assert;
import org.testng.annotations.Test;

public class SampleProgramOne {
    @Test
    public void testOne() {
        Assert.assertTrue(true);
        System.out.println(&amp;amp;amp;amp;quot;Pass Test case - testOne&amp;amp;amp;amp;quot;);
    }

    @Test
    public void testTwo() {
        Assert.assertEquals(&amp;amp;amp;amp;quot;AutomationgTesting&amp;amp;amp;amp;quot;, &amp;amp;amp;amp;quot;AutomationgTest&amp;amp;amp;amp;quot;);
        System.out.println(&amp;amp;amp;amp;quot;Pass Test case - testOne&amp;amp;amp;amp;quot;);
    }

    @Test
    public void testThree() {
        Assert.assertTrue(true);
        System.out.println(&amp;amp;amp;amp;quot;Pass Test case - testThree&amp;amp;amp;amp;quot;);
    }
}
</pre>
<p><strong>Second Sample java file:</strong></p>
<pre class="brush: java; title: ; notranslate">
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class SampleProgramTwo {

    @BeforeMethod
    public void beforeMethod() {
        System.out.println(&amp;amp;amp;amp;quot;I am in beforeMethod&amp;amp;amp;amp;quot;);
    }

    @Test
    public void testOne() {
        System.out.println(&amp;amp;amp;amp;quot;I am in Simple Test&amp;amp;amp;amp;quot;);
    }

    @AfterMethod
    public void afterMethod() {
        System.out.println(&amp;amp;amp;amp;quot;I am in afterMethod&amp;amp;amp;amp;quot;);
    }
}
</pre>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>Using Listeners is mandatory while executing the suite through code. Otherwise it will not show the errors information in detail. Means, which method got failed and what is exact error message will not be given if you not using the listeners. Below is the sample listener class.</p>
<pre class="brush: java; highlight: [21]; title: ; notranslate">
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class ListenerTest implements ITestListener {

    @Override
    public void onTestStart(ITestResult result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTestSuccess(ITestResult result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTestFailure(ITestResult result) {
        System.out.println(result.getName() + &amp;amp;amp;amp;quot; : &amp;amp;amp;amp;quot; + result.getThrowable());

    }

    @Override
    public void onTestSkipped(ITestResult result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStart(ITestContext context) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onFinish(ITestContext context) {
        // TODO Auto-generated method stub

    }
}
</pre>
<p>In the above program, <strong>result.getName()</strong> will give the method name which is failed and <strong>result.getThrowable()</strong> will give the exact error message.<br />
Below is the testng java configuration file which is the replacement for testng.xml file:</p>
<pre class="brush: java; highlight: [12,13,14,16,17,19,20,22,23,25,26,28,30,32,34,36,37,38,42,43]; title: ; notranslate">
import java.util.ArrayList;
import java.util.List;

import org.testng.TestNG;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

public class TestNgXmlUsingCode {
    public void testNgXmlSuite() {

        List&amp;amp;amp;amp;lt;XmlSuite&amp;amp;amp;amp;gt; suites = new ArrayList&amp;amp;amp;amp;lt;XmlSuite&amp;amp;amp;amp;gt;();
        List&amp;amp;amp;amp;lt;XmlClass&amp;amp;amp;amp;gt; classes = new ArrayList&amp;amp;amp;amp;lt;XmlClass&amp;amp;amp;amp;gt;();
        List&amp;amp;amp;amp;lt;Class&amp;amp;amp;amp;gt; listenerClasses = new ArrayList&amp;amp;amp;amp;lt;Class&amp;amp;amp;amp;gt;();

        XmlSuite suite = new XmlSuite();
        suite.setName(&amp;amp;amp;amp;quot;ProgramSuite&amp;amp;amp;amp;quot;);

        XmlTest test = new XmlTest(suite);
        test.setName(&amp;amp;amp;amp;quot;ProgramTest&amp;amp;amp;amp;quot;);

        XmlClass clss1 = new XmlClass(&amp;amp;amp;amp;quot;SampleProgramOne&amp;amp;amp;amp;quot;);
        classes.add(clss1);

        XmlClass clss2 = new XmlClass(&amp;amp;amp;amp;quot;SampleProgramTwo&amp;amp;amp;amp;quot;);
        classes.add(clss2);

        listenerClasses.add(ListenerTest.class);

        test.setXmlClasses(classes);

        suites.add(suite);

        TestNG tng = new TestNG();

        tng.setXmlSuites(suites);
        tng.setListenerClasses(listenerClasses);
        tng.run();
    }

    public static void main(String&#x5B;] args) {
        TestNgXmlUsingCode tnxuc = new TestNgXmlUsingCode();
        tnxuc.testNgXmlSuite();
    }
}
</pre>
<p>The above program is the testng configuration file which is replacement of testng.xml file creating programmatically. By executing the above java program normally we can achieve the same functionality which is available with xml file.</p>
<p>Below is the output of the above program:</p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/1-6.png"><img decoding="async" loading="lazy" class="size-full wp-image-1035 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/1-6.png" alt="1" width="1321" height="583" srcset="https://automationtesting.in/wp-content/uploads/2016/12/1-6.png 1321w, https://automationtesting.in/wp-content/uploads/2016/12/1-6-300x132.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/1-6-768x339.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/1-6-1024x452.png 1024w" sizes="(max-width: 1321px) 100vw, 1321px" /></a></p>
<p>This output look is different from the testng,.xml configuration file output.<br />
In the above program, XmlSuite is equal to suite tag in testng.xml file, XmlTest is equal to test tag, XmlClass is equal to class tag.<br />
This way we can create testng.xml file programmatically in TestNG.<br />
Please watch You tube video for better understanding.<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-987" data-postid="987" class="themify_builder_content themify_builder_content-987 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/running-testng-tests-programmatically/">Running TestNG Tests Programmatically</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/running-testng-tests-programmatically/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Executing Only Failed Tests in TestNG</title>
		<link>https://automationtesting.in/executing-failed-tests-testng/</link>
					<comments>https://automationtesting.in/executing-failed-tests-testng/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 14:37:56 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[execute fail tests]]></category>
		<category><![CDATA[execute only failed tests]]></category>
		<category><![CDATA[fail tests]]></category>
		<category><![CDATA[failed tests]]></category>
		<category><![CDATA[how to execute failed tests]]></category>
		<category><![CDATA[how to execute only failed tests]]></category>
		<category><![CDATA[run only failed tests]]></category>
		<category><![CDATA[testng-failed.xml]]></category>
		<category><![CDATA[testng.xml]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=979</guid>

					<description><![CDATA[<p>Executing only failed tests in TestNG will discuss about how we can execute only failed test cases in the test suite once the execution of the suite completed. Most of the times when we execute bulk tests as suite then there is a chance of failing some of the tests. For these failures there may [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/executing-failed-tests-testng/">Executing Only Failed Tests in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Executing only failed tests in TestNG will discuss about how we can execute only failed test cases in the test suite once the execution of the suite completed. Most of the times when we execute bulk tests as suite then there is a chance of failing some of the tests.</p>
<div class="post-video"><iframe loading="lazy" title="Execute Only Failed Tests in TestNG" width="1165" height="655" src="https://www.youtube.com/embed/HHheCU8wAtY?t=25s&#038;wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>For these failures there may be so many reasons. Will see some of them below:</p>
<p>1.Some of the elements may not load properly.<br />
2.Due to some network slowness.<br />
3.Functionality may got changed.<br />
4.Locator value may got changed.. Etc…</p>
<p>Because of the reasons tests will fail. After completion of the execution if there are any failures, immediately we can not raise bugs. In the above scenarios failures due to 1,2 and 4 will not cause the bugs as this is because of loading elements and network slowness. But due to 3, we can raise the bugs.</p>
<p>But how we can come to know that the failures because of which reason. To get the confirmation we need to rerun the failed scripts to know the exact reason. Then how we can execute only failed tests?</p>
<p>To execute only failed tests we have provision in the TestNg. After completion of the suite execution; just refresh the project folder then you can find a folder called <strong>“test-output”</strong> and there you can find an xml file called <strong>“testng-failed.xml”</strong>. This xml file contains only failed test cases. So, we can execute this xml file to rerun the failed test again.</p>
<p>Below is the sample program:</p>
<pre class="brush: java; title: ; notranslate">
import org.testng.Assert;
import org.testng.annotations.Test;

public class OnlyFailedTestExecution {
    @Test
    public void testOne() {
        Assert.assertTrue(true);
        System.out.println(&quot;Pass Test Case&quot;);
    }

    @Test
    public void testTwo() {
        Assert.assertTrue(false);
        System.out.println(&quot;Faile Test Case&quot;);
    }
}
</pre>
<p>Execute the above program using below testng.xml file:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE suite SYSTEM &quot;http://testng.org/testng-1.0.dtd&quot;&gt;
&lt;suite name=&quot;Suite&quot;&gt;
  &lt;test name=&quot;Test&quot;&gt;
    &lt;classes&gt;
      &lt;class name=&quot;OnlyFailedTestExecution&quot;/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
</pre>
<p>Once your execute the above xml file then we can find the below output:</p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/1-5.png"><img decoding="async" loading="lazy" class="size-full wp-image-1029 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/1-5.png" alt="1" width="1050" height="490" srcset="https://automationtesting.in/wp-content/uploads/2016/12/1-5.png 1050w, https://automationtesting.in/wp-content/uploads/2016/12/1-5-300x140.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/1-5-768x358.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/1-5-1024x478.png 1024w" sizes="(max-width: 1050px) 100vw, 1050px" /></a></p>
<p>Now we want to execute only failed tests. For this we will go to the test-output folder and will execute the <strong>testng-failed.xml</strong>. Then we can see the below output.</p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/2-3.png"><img decoding="async" loading="lazy" class="size-full wp-image-1030 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/2-3.png" alt="2" width="476" height="600" srcset="https://automationtesting.in/wp-content/uploads/2016/12/2-3.png 476w, https://automationtesting.in/wp-content/uploads/2016/12/2-3-238x300.png 238w" sizes="(max-width: 476px) 100vw, 476px" /></a></p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/3-1.png"><img decoding="async" loading="lazy" class="size-full wp-image-1031 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/3-1.png" alt="3" width="1050" height="517" srcset="https://automationtesting.in/wp-content/uploads/2016/12/3-1.png 1050w, https://automationtesting.in/wp-content/uploads/2016/12/3-1-300x148.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/3-1-768x378.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/3-1-1024x504.png 1024w" sizes="(max-width: 1050px) 100vw, 1050px" /></a></p>
<p>In the above output we can see that only failed test got executed. And it ignores the execution of passed tests.<br />
This way we can execute the only failed tests in testNg.<br />
Please watch You tube video for better understanding.<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-979" data-postid="979" class="themify_builder_content themify_builder_content-979 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/executing-failed-tests-testng/">Executing Only Failed Tests in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/executing-failed-tests-testng/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Capture Screenshot for Failed Tests in TestNG</title>
		<link>https://automationtesting.in/capture-screenshot-failed-tests-testng/</link>
					<comments>https://automationtesting.in/capture-screenshot-failed-tests-testng/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 14:31:14 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[capture screenshot]]></category>
		<category><![CDATA[capture screenshot for failed tests]]></category>
		<category><![CDATA[ITestListener]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[screenshot]]></category>
		<category><![CDATA[screenshot for failed tests]]></category>
		<category><![CDATA[take screenshot]]></category>
		<category><![CDATA[take screenshot for failed tests]]></category>
		<category><![CDATA[testng.xml]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=968</guid>

					<description><![CDATA[<p>Capture screenshot for failed tests in testNG will discuss about how to take a screenshot when a test case fails while executing the test suite. The screenshot will give the information about on which screen the script  got failed during the execution. Then we can easily identify the issue by looking into the screenshot. To [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/capture-screenshot-failed-tests-testng/">Capture Screenshot for Failed Tests in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img src='http://automationtesting.in/wp-content/uploads/2016/12/Capture-Screenshot-for-Failed-Tests.png'></p><p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Capture screenshot for failed tests in testNG will discuss about how to take a screenshot when a test case fails while executing the test suite. The screenshot will give the information about on which screen the script  got failed during the execution. Then we can easily identify the issue by looking into the screenshot.</p>
<div class="post-video"><iframe loading="lazy" title="Capture Screenshot For Failed Tests in TestNG" width="1165" height="655" src="https://www.youtube.com/embed/-X2dCOdVhzI?t=25s&#038;wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>To achieve this we need to write 2 utility classes. One is to take the screenshot and another is to listen to the test status result and take the screenshot accordingly. For this we need to use Listeners in the testNG. We need to implement the <strong>ITestListener</strong> from the testNG in order to get the status of the test case. If the test case is fail then it will track that information and then will take the screenshot using the screenshot utility.</p>
<p>Below will see how can we achieve this. For this, we need to write 4 different classes. One is MainTest which will be used to initiate the WebDriver as we need to use the same webdriver instance across our framework. So, whenever there is a need of using webdriver instance then that class will extend this MainTest. Then we can maintain a single webdriver instance across our project.</p>
<p>Second is GetScreenshot which will be used to take the screenshot when there is a need. This is not only useful for the failed tests. If you want to capture screenshot anywhere in the project then you can use this utility to take the screenshot. But here we are using this in the listener as we need to take the screenshot for the failed tests.</p>
<p>Third is ListenerTest which will be used to listen the status of our test cases and act accordingly. For this we need to implement ITestListener interface from the testNG. And we need to use this listener in the testng.xml file to track the test cases status. Once there is any failure in the test case then it will call the listener and we have to mention to take the screenshot for the failed test.</p>
<p>Here, we need to implement all the methods which are available in the ITestListener interface. And it is not mandatory to implement all the methods but atleast we need to mention those methods without any logic. Here the useful method is onTestFailure. And this method contains the logic to capture the screenshot.</p>
<p>Fourth is CaptureScreenshotTests which is the class contains actual test cases which we are going to execute. Once there is any failure then it will be tracked by the onTestFailure from the listener class and then it will take the screenshot for the same.</p>
<p><strong>Below program is to initialize the webdriver:</strong></p>
<pre class="brush: java; highlight: [6]; title: ; notranslate">
package com.automationtesting.screenshot;

import org.openqa.selenium.WebDriver;

public class MainTest {
    public static WebDriver driver;
}
</pre>
<p><strong>Below program is to capture the screenshot:</strong></p>
<pre class="brush: java; highlight: [13,14,15,16,17]; title: ; notranslate">
package com.automationtesting.screenshot;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;

public class GetScreenshot extends MainTest {
    public static String capture(String screenshotName) throws IOException {
        TakesScreenshot ts = (TakesScreenshot) driver;
        File source = ts.getScreenshotAs(OutputType.FILE);
        String dest = System.getProperty(&amp;amp;quot;user.dir&amp;amp;quot;) + &amp;amp;quot;/ErrorScreenshot/&amp;amp;quot; + screenshotName + &amp;amp;quot;.png&amp;amp;quot;;
        File destination = new File(dest);
        FileUtils.copyFile(source, destination);

        return dest;
    }
}
</pre>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
<strong>Below program is to implement the listener:</strong></p>
<pre class="brush: java; highlight: [26]; title: ; notranslate">
package com.automationtesting.screenshot;

import java.io.IOException;

import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class ListenerTest extends MainTest implements ITestListener {

    @Override
    public void onTestStart(ITestResult result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTestSuccess(ITestResult result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTestFailure(ITestResult result) {
        try {
            GetScreenshot.capture(result.getName());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    @Override
    public void onTestSkipped(ITestResult result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStart(ITestContext context) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onFinish(ITestContext context) {
        // TODO Auto-generated method stub

    }
}
</pre>
<p><strong>Below program is for actual test cases:</strong></p>
<pre class="brush: java; highlight: [15]; title: ; notranslate">
package com.automationtesting.screenshot;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.Test;

public class CaptureScreenshotTests extends MainTest {

    @Test
    public void captureScreenshot() {
        System.setProperty(&amp;amp;quot;webdriver.firefox.marionette&amp;amp;quot;, &amp;amp;quot;D:\\drivers\\geckodriver-0.10.0\\geckodriver.exe&amp;amp;quot;);
        driver = new FirefoxDriver();
        driver.get(&amp;amp;quot;https://automationtesting.in&amp;amp;quot;);
        String title = driver.getTitle();
        Assert.assertEquals(&amp;amp;quot;Home - Automation Test&amp;amp;quot;, title);
        driver.close();
    }
}
</pre>
<p>In the above program it will try to assert the page title. But we intentionally failing this assert to capture the screenshot for this failure.</p>
<p><strong>Below program is to execute the test cases from testng.xml file:</strong></p>
<pre class="brush: xml; highlight: [4,5,6]; title: ; notranslate">
&amp;amp;lt;?xml version=&amp;amp;quot;1.0&amp;amp;quot; encoding=&amp;amp;quot;UTF-8&amp;amp;quot;?&amp;amp;gt;
&amp;amp;lt;!DOCTYPE suite SYSTEM &amp;amp;quot;http://testng.org/testng-1.0.dtd&amp;amp;quot;&amp;amp;gt;
&amp;amp;lt;suite name=&amp;amp;quot;Suite&amp;amp;quot;&amp;amp;gt;
&amp;amp;lt;listeners&amp;amp;gt;
&amp;amp;lt;listener class-name=&amp;amp;quot;com.automationtesting.screenshot.ListenerTest&amp;amp;quot;&amp;amp;gt;&amp;amp;lt;/listener&amp;amp;gt;
&amp;amp;lt;/listeners&amp;amp;gt;
  &amp;amp;lt;test name=&amp;amp;quot;Test&amp;amp;quot;&amp;amp;gt;
    &amp;amp;lt;classes&amp;amp;gt;
      &amp;amp;lt;class name=&amp;amp;quot;com.automationtesting.screenshot.CaptureScreenshot&amp;amp;quot;/&amp;amp;gt;
    &amp;amp;lt;/classes&amp;amp;gt;
  &amp;amp;lt;/test&amp;amp;gt;
&amp;amp;lt;/suite&amp;amp;gt;
</pre>
<p>Once you execute the above xml file then it capture the screenshot and it will place that in the <span style="color: #99cc00;">ErrorScreenshot <span style="color: #000000;">folder</span></span> with the method name  in the current project folder structure.<br />
This way we can achieve this functionality.<br />
Please watch You tube video for better understanding.<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-968" data-postid="968" class="themify_builder_content themify_builder_content-968 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/capture-screenshot-failed-tests-testng/">Capture Screenshot for Failed Tests in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/capture-screenshot-failed-tests-testng/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Preserve Order in TestNG</title>
		<link>https://automationtesting.in/preserve-order-testng/</link>
					<comments>https://automationtesting.in/preserve-order-testng/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 14:27:36 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=962</guid>

					<description><![CDATA[<p>Preserve Order in TestNG will discuss about the order of test case execution in testNG. Usually the order of execution in the testNG will be alphabetical order. Means, if you not set any priority then it will execute the test cases in alphabetical order. In our previous blog (i.e.Prioritizing Tests in testng) we have seen [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/preserve-order-testng/">Preserve Order in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Preserve Order in TestNG will discuss about the order of test case execution in testNG. Usually the order of execution in the testNG will be alphabetical order. Means, if you not set any priority then it will execute the test cases in alphabetical order. In our previous blog (i.e.Prioritizing Tests in testng) we have seen how to use the priority attribute of @Test annotation to execute the test cases in our own order.</p>
<p>We will write the test cases how we want to execute but by default testNG will not execute in order how we have written. For this we need to use priority attribute for each and every test to execute the test cases in predefined order. But writing priority for each test case is tedious as we may have so many test cases in our test suite.</p>
<p>To overcome this problem, there is one more option called <strong>“preserve-order”</strong>in the testNG. We can use this attribute at suite level or test level.  If you set this value to “<strong>true</strong>” then it will execute the tests which are mentioned in the order in testng,xml file. Means, it will now not execute the tests in alphabetical order.</p>
<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-962" data-postid="962" class="themify_builder_content themify_builder_content-962 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/preserve-order-testng/">Preserve Order in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/preserve-order-testng/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Prioritizing Tests in TestNg</title>
		<link>https://automationtesting.in/prioritizing-tests-testng/</link>
					<comments>https://automationtesting.in/prioritizing-tests-testng/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 14:21:38 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[how to prioritize tests]]></category>
		<category><![CDATA[prioritization]]></category>
		<category><![CDATA[prioritization of tests]]></category>
		<category><![CDATA[prioritization tests]]></category>
		<category><![CDATA[priority]]></category>
		<category><![CDATA[priority attribute]]></category>
		<category><![CDATA[priority tests]]></category>
		<category><![CDATA[testng priority]]></category>
		<category><![CDATA[testng tests prioritization]]></category>
		<category><![CDATA[testng.xml]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=954</guid>

					<description><![CDATA[<p>Prioritizing tests in testng will discuss about the order of execution tests in test suite. We will write test methods our own way using @Test annotation. After writing the test cases we will execute the test cases either normally or from the testng.xml file. After execution of the tests if we observe the order of [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/prioritizing-tests-testng/">Prioritizing Tests in TestNg</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Prioritizing tests in testng will discuss about the order of execution tests in test suite. We will write test methods our own way using <strong>@Test</strong> annotation. After writing the test cases we will execute the test cases either normally or from the testng.xml file. After execution of the tests if we observe the order of execution then we can find that tests executed by taking the alphabetical order. And all the tests will have the equal priority as we did not set any priority to the tests.</p>
<div class="post-video"><iframe loading="lazy" title="Prioritizing Tests in TestNG" width="1165" height="655" src="https://www.youtube.com/embed/mnlO4OrfHu0?t=25s&#038;wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>In order to set the priority to the tests then we can use one of the @Test attributes called <strong>“Priority”</strong>. By default all the tests will have the same priority called <strong>Zero</strong>(i.e. If you not set any priority then it will take the priority as Zero).<br />
If you give the priority equal to all the test cases then all the tests will execute in alphabetical order. Here we will see how the priority will work while executing the tests by taking few examples:<br />
1. In the below example we will see test case execution flow without setting any priority to the tests (i.e. all the tests will have the priority as ZERO).</p>
<pre class="brush: java; highlight: [3,9,15]; title: ; notranslate">
public class WithOutPriority
{
    @Test
    public void secondTest()
    {
        System.out.println(&quot;In secondTest method&quot;);
    }
    
    @Test
    public void thirdTest()
    {
        System.out.println(&quot;In thirdTest method&quot;);
    }
    
    @Test
    public void fourthTest()
    {
        System.out.println(&quot;In fourthTest method&quot;);
    }
}
</pre>
<p>Below is the Output for the same:</p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/1-4.png"><img decoding="async" loading="lazy" class="size-full wp-image-1020 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/1-4.png" alt="1" width="1111" height="538" srcset="https://automationtesting.in/wp-content/uploads/2016/12/1-4.png 1111w, https://automationtesting.in/wp-content/uploads/2016/12/1-4-300x145.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/1-4-768x372.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/1-4-1024x496.png 1024w" sizes="(max-width: 1111px) 100vw, 1111px" /></a></p>
<p>If we observe the above output of all the 3 methods they executed in the alphabetical order. We have the order in test class is secondTest, thirdTest and fourthTest. But after execution the output is fourthTest, secondTest and thirdTest.</p>
<p>2.In the below example we will see test case execution flow with Priority attribute. Will take three test methods and will set the priority to them like one is without priority attribute and remaining</p>
<p>with 1 and 2.</p>
<pre class="brush: java; highlight: [3,9,15]; title: ; notranslate">
public class PartialPriority
{
    @Test(priority = 1)
    public void secondTest()
    {
        System.out.println(&quot;In secondTest method&quot;);
    }
    
    @Test
    public void thirdTest()
    {
        System.out.println(&quot;In thirdTest method&quot;);
    }
    
    @Test(priority = 2)
    public void fourthTest()
    {
        System.out.println(&quot;In fourthTest method&quot;);
    }
}
</pre>
<p>Below is the Output for the same:</p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/2-2.png"><img decoding="async" loading="lazy" class="size-full wp-image-1021 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/2-2.png" alt="2" width="1110" height="501" srcset="https://automationtesting.in/wp-content/uploads/2016/12/2-2.png 1110w, https://automationtesting.in/wp-content/uploads/2016/12/2-2-300x135.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/2-2-768x347.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/2-2-1024x462.png 1024w" sizes="(max-width: 1110px) 100vw, 1110px" /></a></p>
<p>If we observe the above output of all the 3 methods they executed as per the priorities we set. The test without priority executed first as the default priority is equal to ZERO and it takes the high priority. And then priority = 1 will execute and last priority = 2 will execute.</p>
<p>3.In the below example we will see test case execution flow with Priority attribute. Will take three test methods and will set the priority to them like 1,2 and 3</p>
<pre class="brush: java; highlight: [3,9,15]; title: ; notranslate">
public class PriorityTest
{
    @Test(priority = 1)
    public void secondTest()
    {
        System.out.println(&quot;In secondTest method&quot;);
    }
    
    @Test(priority = 3)
    public void thirdTest()
    {
        System.out.println(&quot;In thirdTest method&quot;);
    }
    
    @Test(priority = 2)
    public void fourthTest()
    {
        System.out.println(&quot;In fourthTest method&quot;);
    }
}
</pre>
<p>Below is the Output for the same:</p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/3.png"><img decoding="async" loading="lazy" class="size-full wp-image-1022 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/3.png" alt="3" width="1113" height="520" srcset="https://automationtesting.in/wp-content/uploads/2016/12/3.png 1113w, https://automationtesting.in/wp-content/uploads/2016/12/3-300x140.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/3-768x359.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/3-1024x478.png 1024w" sizes="(max-width: 1113px) 100vw, 1113px" /></a></p>
<p>If we observe the above output of all the 3 methods they executed as per the priorities we set. The test with priority = 1 will execute first and priority = 2 will execute second and priority = 3 will execute last.<br />
This way we can prioritize the tests in testNG to control the execution flow.<br />
Please watch You tube video for better understanding.<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-954" data-postid="954" class="themify_builder_content themify_builder_content-954 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/prioritizing-tests-testng/">Prioritizing Tests in TestNg</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/prioritizing-tests-testng/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Execute Multiple XML files in TestNG</title>
		<link>https://automationtesting.in/execute-multiple-xml-files-testng/</link>
					<comments>https://automationtesting.in/execute-multiple-xml-files-testng/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 14:11:55 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[execute multiple suite files]]></category>
		<category><![CDATA[how to run multiple xml files]]></category>
		<category><![CDATA[multiple xml files]]></category>
		<category><![CDATA[run multiple suite files Multiple xml files]]></category>
		<category><![CDATA[suite files]]></category>
		<category><![CDATA[suite-file-path]]></category>
		<category><![CDATA[testng.xml]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=941</guid>

					<description><![CDATA[<p>Execute Multiple Xml files in TestNG will discuss about how to execute multiple xml files in TestNG at a time. For ex. You have more than one xml suite files to execute different types of test scripts in your project. Now you can execute the individual xml files simply that right click on xml file [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/execute-multiple-xml-files-testng/">Execute Multiple XML files in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Execute Multiple Xml files in TestNG will discuss about how to execute multiple xml files in TestNG at a time. For ex. You have more than one xml suite files to execute different types of test scripts in your project. Now you can execute the individual xml files simply that right click on xml file and run as testng suite. But if you have multiple files then you need to put those xml files in a separate xml file and need to execute the same way as right click on xml and run as testng suite. This way you can manage the test cases execution how we want.</p>
<div class="post-video"><iframe loading="lazy" title="Execute Multiple XML Files in TestNG" width="1165" height="655" src="https://www.youtube.com/embed/5ZOiP4bIaHU?t=25s&#038;wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>Sometimes we need to maintain separate test suite for smoke test and separate suite for sanity test and another for Regression testing. For ex, once you receive the new build then you can perform smoke test using its own xml file, same way you can perform sanity test also using its own xml file. But if you want to execute full regression then you need to include regression tests, smoke tests and sanity tests. In these kind of situation we will put all these three suite files into another xml file and then we can execute that single xml file to run all the test scripts available under these 3 suite files.<br />
We will see this functionality with an example:<br />
Let&#8217;s assume we have 3 packages called <strong>com.multiplesuite.regression, com.multiplesuite.smoke</strong> and <strong>com.multiplesuite.sanity</strong> and each package contains 2 class files and then each class will contain 1 test method.<br />
Now we will write sample xml files for each and every package which we have discussed above:</p>
<p>1. Xml file for <strong>com.multiplesuite.regression (ex: regression.xml)</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE suite SYSTEM &quot;http://testng.org/testng-1.0.dtd&quot;&gt;
&lt;suite name=&quot;Suite&quot;&gt;
  &lt;test name=&quot;Test&quot;&gt;
    &lt;classes&gt;
      &lt;class name=&quot;com.multiplesuite.regression.regressionClassOne&quot;/&gt;
      &lt;class name=&quot;com.multiplesuite.regression.regressionClassTwo&quot;/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
</pre>
<p>In the above xml file it contains two classes called regressionClassOne and regressionClassTwo and each class contains its own methods.</p>
<p>2. Xml file for <strong>com.multiplesuite.smoke (ex: smoke.xml)</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE suite SYSTEM &quot;http://testng.org/testng-1.0.dtd&quot;&gt;
&lt;suite name=&quot;Suite&quot;&gt;
  &lt;test name=&quot;Test&quot;&gt;
    &lt;classes&gt;
      &lt;class name=&quot;com.multiplesuite.smoke.smokeClassOne&quot;/&gt;
      &lt;class name=&quot;com.multiplesuite.smoke.smokeClassTwo&quot;/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
</pre>
<p>In the above xml file it contains two classes called smokeClassOne and smokeClassTwo and each class contains its own methods.<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<p>3. Xml file for <strong>com.multiplesuite.sanity (ex: sanity.xml)</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE suite SYSTEM &quot;http://testng.org/testng-1.0.dtd&quot;&gt;
&lt;suite name=&quot;Suite&quot;&gt;
  &lt;test name=&quot;Test&quot;&gt;
    &lt;classes&gt;
      &lt;class name=&quot;com.multiplesuite.sanity.sanityClassTwo&quot;/&gt;
      &lt;class name=&quot;com.multiplesuite.sanity.sanityClassOne&quot;/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
</pre>
<p>In the above xml file it contains two classes called sanityClassOne and sanityClassTwo and each class contains its own methods.<br />
If you want to execute only regression test then you can use regression.xml file to execute its specific tests and the same way we can do it for smoke test and sanity test also.<br />
But now we want to execute all the above three xml files at a time. Then you need to put these three xml file into another xml and then run the same to achieve our requirement.<br />
Below is the sample xml file to execute above 3 suite files: <strong>(ex: testng.xml)</strong></p>
<pre class="brush: xml; highlight: [4,5,6,7,8]; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE suite SYSTEM &quot;http://testng.org/testng-1.0.dtd&quot;&gt;
&lt;suite name=&quot;MultipleSuite&quot;&gt;
&lt;suite-files&gt;
    &lt;suite-file path=&quot;regression.xml&quot;&gt;&lt;/suite-file&gt;
    &lt;suite-file path=&quot;smoke.xml&quot;&gt;&lt;/suite-file&gt;
    &lt;suite-file path=&quot;sanity.xml&quot;&gt;&lt;/suite-file&gt;
&lt;/suite-files&gt;
&lt;/suite&gt;
</pre>
<p>In the above file we can observe new tags called suite-files and suite-file-path. By using suite-file-path we can mention the individual suite files and can execute the same like run as testng suite.<br />
This way we can execute multiple suite files from other xml file.<br />
Please watch the you tube video for better understanding.<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-941" data-postid="941" class="themify_builder_content themify_builder_content-941 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/execute-multiple-xml-files-testng/">Execute Multiple XML files in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/execute-multiple-xml-files-testng/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Custom Reporter in TestNG</title>
		<link>https://automationtesting.in/custom-reporter-testng/</link>
					<comments>https://automationtesting.in/custom-reporter-testng/#comments</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 14:06:08 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[create own report]]></category>
		<category><![CDATA[custom report]]></category>
		<category><![CDATA[custom reporter]]></category>
		<category><![CDATA[how to create custom report]]></category>
		<category><![CDATA[how to create custom reporter]]></category>
		<category><![CDATA[IReporter]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[listeners]]></category>
		<category><![CDATA[reporter]]></category>
		<category><![CDATA[testng.xml]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=931</guid>

					<description><![CDATA[<p>Custom reporter in testng will discuss about writing our own reporter in TestNG. Reporting is one of the most important things to remember in automation testing. Reports are used to understand the result of the test execution, point of failure, and reasons for the failure. TestNG by default generates a different type of report (i.e. [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/custom-reporter-testng/">Custom Reporter in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Custom reporter in testng will discuss about writing our own reporter in TestNG. Reporting is one of the most important things to remember in automation testing. Reports are used to understand the result of the test execution, point of failure, and reasons for the failure. TestNG by default generates a different type of report (i.e. HTML and an XML reports). TestNG also allows us to write their own reporter and use it with TestNG.</p>
<div class="post-video"><iframe loading="lazy" title="Custom Reporter in TestNG" width="1165" height="655" src="https://www.youtube.com/embed/DuuQ0hw9q3A?t=25s&#038;wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>To generate custom reports in testng we need to use Reporters. To implement reporters, need to implement the <strong>IReporter</strong> interface in your class. These classes are called when the whole suite run ends. The object containing the information of the whole test run is passed to this class when called.<br />
For this we need to have at least 2 classes. One is for actual test cases and other is for to implement the <strong>IReporter</strong>.<br />
Below is the sample program for test cases class:</p>
<pre class="brush: java; title: ; notranslate">
import org.testng.Assert;
import org.testng.annotations.Test;

public class loggerTest {
    @Test
    public void testOne() {
        Assert.assertTrue(true);
    }

    @Test
    public void testTwo() {
        Assert.assertTrue(false);
    }

    @Test(dependsOnMethods = { &quot;testTwo&quot; })
    public void testThree() {
        Assert.assertTrue(true);
    }
}
</pre>
<p>When you execute the above program, the status of the test cases should be listen by the listener class. We have three methods called testOne, testTwo and testThree in the above program one is to pass and second is to fail and third is to skip status. After execution of the suits, the listener will track the status of the each test.<br />
Below is the sample listener class which will implements the <strong>IReporter</strong></p>
<pre class="brush: java; title: ; notranslate">
import java.util.List;
import java.util.Map;
import org.testng.IReporter;
import org.testng.ISuite;
import org.testng.ISuiteResult;
import org.testng.ITestContext;
import org.testng.xml.XmlSuite;

public class CustomReporter implements IReporter {
    @Override
    public void generateReport(List&lt;XmlSuite&gt; xmlSuites, List&lt;ISuite&gt; suites, String outputDirectory) {
        // Iterating over each suite included in the test
        for (ISuite suite : suites) {
            // Following code gets the suite name
            String suiteName = suite.getName();
            // Getting the results for the said suite
            Map&lt;String, ISuiteResult&gt; suiteResults = suite.getResults();
            for (ISuiteResult sr : suiteResults.values()) {
                ITestContext tc = sr.getTestContext();
                System.out.println(
                        &quot;Passed tests for suite '&quot; + suiteName + &quot;' is:&quot; + tc.getPassedTests().getAllResults().size());
                System.out.println(
                        &quot;Failed tests for suite '&quot; + suiteName + &quot;' is:&quot; + tc.getFailedTests().getAllResults().size());
                System.out.println(&quot;Skipped tests for suite '&quot; + suiteName + &quot;' is:&quot;
                        + tc.getSkippedTests().getAllResults().size());
            }
        }
    }
}
</pre>
<p>The above class implements the <strong>IReporter</strong>. So, it has to implement all the methods which are available in that interface. And it is not mandatory to use all the methods, we can left blank some of the methods which are not relevant to the requirement.<br />
Now we have to create a testng.xml file to execute the above tests and it should have a mandatory tag called listener. It will call the listener class to listen the status of the each and every test which will execute.<br />
Below is the sample program to execute the above program:</p>
<pre class="brush: xml; highlight: [4,5,6]; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE suite SYSTEM &quot;http://testng.org/testng-1.0.dtd&quot;&gt;
&lt;suite name=&quot;Suite&quot;&gt;
&lt;listeners&gt;
&lt;listener class-name=&quot;CustomReporter&quot;&gt;&lt;/listener&gt;
&lt;/listeners&gt;
  &lt;test name=&quot;Test&quot;&gt;
    &lt;classes&gt;
      &lt;class name=&quot;loggerTest&quot;/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
</pre>
<p>Output for the above program is:</p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/1-3.png"><img decoding="async" loading="lazy" class="size-full wp-image-1013 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/1-3.png" alt="1" width="1076" height="629" srcset="https://automationtesting.in/wp-content/uploads/2016/12/1-3.png 1076w, https://automationtesting.in/wp-content/uploads/2016/12/1-3-300x175.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/1-3-768x449.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/1-3-1024x599.png 1024w" sizes="(max-width: 1076px) 100vw, 1076px" /></a></p>
<p>This way we can use custom listeners to generate the reports after execution.<br />
Please watch the you tube video for better understanding.<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-931" data-postid="931" class="themify_builder_content themify_builder_content-931 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/custom-reporter-testng/">Custom Reporter in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/custom-reporter-testng/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Custom Logger in TestNG</title>
		<link>https://automationtesting.in/custom-logger-testng/</link>
					<comments>https://automationtesting.in/custom-logger-testng/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 13:58:56 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[custom logger]]></category>
		<category><![CDATA[how to create custom logger]]></category>
		<category><![CDATA[ITestListener]]></category>
		<category><![CDATA[listener]]></category>
		<category><![CDATA[listeners]]></category>
		<category><![CDATA[logger]]></category>
		<category><![CDATA[testng.xml]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=920</guid>

					<description><![CDATA[<p>Custom logger in the TestNG will discuss about writing our own logger in TestNG. Logging is one of the most important things to remember in automation testing. Logger will keep on eye of the execution flow that where went wrong in the script or it very useful to debug the script. To generate custom loggers [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/custom-logger-testng/">Custom Logger in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
Custom logger in the TestNG will discuss about writing our own logger in TestNG. Logging is one of the most important things to remember in automation testing. Logger will keep on eye of the execution flow that where went wrong in the script or it very useful to debug the script.</p>
<div class="post-video"><iframe loading="lazy" title="Custom Logger in TestNG" width="1165" height="655" src="https://www.youtube.com/embed/B0shtLQS58k?t=25s&#038;wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>To generate custom loggers in testng we need to use Listeners. To implement listeners, need to implement the <strong>ITestListener</strong> interface in your class. These classes are notified at runtime by TestNG when the test case executes.<br />
For this we need to have at least 2 classes. One is for actual test cases and other is for to implement the <strong>ITestListener.</strong><br />
Below is the sample program for test cases class:</p>
<pre class="brush: java; title: ; notranslate">
import org.testng.Assert;
import org.testng.annotations.Test;

public class loggerTest
{
    @Test
    public void testOne()
    {
        Assert.assertTrue(true);
    }
    
    @Test
    public void testTwo()
    {
        Assert.assertTrue(false);
    }
}
</pre>
<p>When you execute the above program, the status of the test cases should be listen by the listener class. We have two methods called testOne and testTwo in the above program one is to pass and second is to fail status. While executing the tests, the listener will track the status of the each test..<br />
Below is the sample listener class which will implements the <strong>ITestListener</strong></p>
<pre class="brush: java; highlight: [8,9,14,15,20,21,26,27,31,32,37,38,43,44]; title: ; notranslate">
import org.testng.ITestContext;
import org.testng.ITestListener;
import org.testng.ITestResult;

public class listenerTest implements ITestListener {

    // It executes for on each test Start
    @Override
    public void onTestStart(ITestResult result) {
        System.out.println(&quot;Test Method Started :&quot; + result.getName());
    }

    // It executes for only Passed tests
    @Override
    public void onTestSuccess(ITestResult result) {
        System.out.println(&quot;Test Method Passed :&quot; + result.getName());
    }

    // It executes for only Failed tests
    @Override
    public void onTestFailure(ITestResult result) {
        System.out.println(&quot;Test Method Failed :&quot; + result.getName());
    }

    // It executes for only Skipped tests
    @Override
    public void onTestSkipped(ITestResult result) {
        System.out.println(&quot;Test Method Skipped :&quot; + result.getName());
    }

    @Override
    public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
        // No need to implement all the methods. Can leave empty.
    }

    // It executes for on Suite start
    @Override
    public void onStart(ITestContext context) {
        System.out.println(&quot;Test on Start :&quot; + context.getName());
    }

    // It executes for on Suite finish
    @Override
    public void onFinish(ITestContext context) {
        System.out.println(&quot;Test on Finish :&quot; + context.getName());
    }
}
</pre>
<p>The above class implements the <strong>ITestListener</strong>. So, it has to implement all the methods which are available in that interface. And it is not mandatory to use all the methods, we can left blank some of the methods which are not relevant to the requirement.<br />
Now we have to create a testng.xml file to execute the above tests and it should have a mandatory tag called listener. It will call the listener class to listen the status of the each and every test which will execute.<br />
Below is the sample program to execute the above program:</p>
<pre class="brush: xml; highlight: [4,5,6]; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE suite SYSTEM &quot;http://testng.org/testng-1.0.dtd&quot;&gt;
&lt;suite name=&quot;Suite&quot;&gt;
&lt;listeners&gt;
&lt;listener class-name=&quot;listenerTest&quot;&gt;&lt;/listener&gt;
&lt;/listeners&gt;
  &lt;test name=&quot;Test&quot;&gt;
    &lt;classes&gt;
      &lt;class name=&quot;loggerTest&quot;/&gt;
    &lt;/classes&gt;
  &lt;/test&gt;
&lt;/suite&gt;
</pre>
<p>Output for the above program is:</p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/1-2.png"><img decoding="async" loading="lazy" class="size-full wp-image-1009 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/1-2.png" alt="1" width="1074" height="629" srcset="https://automationtesting.in/wp-content/uploads/2016/12/1-2.png 1074w, https://automationtesting.in/wp-content/uploads/2016/12/1-2-300x176.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/1-2-768x450.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/1-2-1024x600.png 1024w" sizes="(max-width: 1074px) 100vw, 1074px" /></a></p>
<p>This way we can use custom listeners to log the messages while executing.<br />
Please watch the you tube video for better understanding.<br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-920" data-postid="920" class="themify_builder_content themify_builder_content-920 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/custom-logger-testng/">Custom Logger in TestNG</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/custom-logger-testng/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>TestNG Assertions</title>
		<link>https://automationtesting.in/testng-assertions/</link>
					<comments>https://automationtesting.in/testng-assertions/#respond</comments>
		
		<dc:creator><![CDATA[Krishna Sakinala]]></dc:creator>
		<pubDate>Fri, 16 Dec 2016 13:48:49 +0000</pubDate>
				<category><![CDATA[TestNG]]></category>
		<category><![CDATA[assertequal]]></category>
		<category><![CDATA[assertfalse]]></category>
		<category><![CDATA[assertions]]></category>
		<category><![CDATA[assertions in testng]]></category>
		<category><![CDATA[assertnotequal]]></category>
		<category><![CDATA[assertnotnull]]></category>
		<category><![CDATA[assertnull]]></category>
		<category><![CDATA[asserttrue]]></category>
		<category><![CDATA[how to use assertions in testng]]></category>
		<category><![CDATA[testng assertions]]></category>
		<category><![CDATA[testng.xml. assert]]></category>
		<guid isPermaLink="false">http://automationtesting.in/?p=902</guid>

					<description><![CDATA[<p>TestNG Assertions will discuss about the Assertions available in the testNG in detail. When you write a test script there should be a verification point in order to mark that test script is passed or failed or any other state. To achieve this in testNG we will user Assertions. Assertion helps you to check or [&#8230;]</p>
<p>The post <a rel="nofollow" href="https://automationtesting.in/testng-assertions/">TestNG Assertions</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script><br />
TestNG Assertions will discuss about the Assertions available in the testNG in detail. When you write a test script there should be a verification point in order to mark that test script is passed or failed or any other state. To achieve this in testNG we will user Assertions. Assertion helps you to check or verify the success of conditions in your test. If the conditions don’t satisfy, it will stop the</p>
<p>test execution of the said test and mark it as failing.</p>
<div class="post-video"><iframe loading="lazy" title="TestNG Assertions" width="1165" height="655" src="https://www.youtube.com/embed/obdOUk7rz9o?t=25s&#038;wmode=transparent&#038;fs=1"  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
<p>TestNG supports assertion of a test using the <strong>Assert</strong> class which is part of the testNG library. The following table describes few of the methods and their usage that are available with the Assert class in testng:</p>
<p>Frequently Used Assertions:</p>

<table id="tablepress-4" class="tablepress tablepress-id-4">
<thead>
<tr class="row-1">
	<th class="column-1">Assertion</th><th class="column-2">Description</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1"><strong><br />
<br />
Assert.assertTrue(condition, message)<br />
</strong></td><td class="column-2"><br />
<br />
It will check the condition is true or not. If the condition is false then it fails and prints the message. Here the message is optional.<br />
</td>
</tr>
<tr class="row-3">
	<td class="column-1"><strong>Assert.assertFalse(condition, message)</strong></td><td class="column-2">It will check the condition is false or not.If the condition is true then it fails and prints the message. Here the message is optional.</td>
</tr>
<tr class="row-4">
	<td class="column-1"><strong><br />
<br />
Assert.assertNotNull(object, message)<br />
</strong></td><td class="column-2">It will check the object is NOT Null or not. If the object is null then it fails and prints the message. Here the message is optional.</td>
</tr>
<tr class="row-5">
	<td class="column-1"><strong><br />
<br />
Assert.assertNull(object, message)<br />
</strong></td><td class="column-2">It will check the object is Null or not. If the object is NOT Null then it fails and prints the message. Here the message is optional. </td>
</tr>
<tr class="row-6">
	<td class="column-1"><strong><br />
<br />
Assert.assertEquals(actual, expected,message)<br />
</strong></td><td class="column-2"><br />
<br />
It will check the actual and expected or Equal or not. If both are NOT Equal then it fails and prints the message. Here the message is optional.<br />
</td>
</tr>
<tr class="row-7">
	<td class="column-1"><strong><br />
<br />
Assert.assertNotEquals(actual, expected,message)<br />
</strong></td><td class="column-2"><br />
<br />
It will check the actual and expected or NOT Equal or not. If both are Equal then it fails and prints the message. Here the message is optional.<br />
</td>
</tr>
</tbody>
</table>
<!-- #tablepress-4 from cache -->
<p><span style="font-weight: 400;">In the above table we have seen some of the assertions which are very frequently used. If the condition meets as expected then the assert passed otherwise it will fails the test and stops the execution of that test.</span></p>
<p><span style="font-weight: 400;">Below is the sample program where all the assertions will PASS:</span></p>
<pre class="brush: java; title: ; notranslate">
import org.testng.Assert;
import org.testng.annotations.Test;
public class PassedAssertions
{
    @Test
    public void testOne()
    {
        Assert.assertTrue(true, &quot;Assert Failed as the actual condition is False&quot;);
    }
    @Test
    public void testTwo()
    {
        Assert.assertFalse(false, &quot;Assert Failed as the actual condition is True&quot;);
    }
    
    @Test
    public void testThree()
    {
        String s = &quot;Krishna&quot;;
        Assert.assertNotNull(s,&quot;Assert Failed as the String is Null&quot;);
    }
    
    @Test
    public void testFour()
    {
        String s = null;
        Assert.assertNull(s, &quot;Assert Failed as the String is NOT NULL&quot;);
    }
    
    @Test
    public void testFive()
    {
        String s1 = &quot;Krishna&quot;;
        String s2 = &quot;Krishna&quot;;
        Assert.assertEquals(s1, s2, &quot;Assert Failed as the two string are NOT EQUAL&quot;);
    }
    
    @Test
    public void testSix()
    {
        String s1 = &quot;Krishna&quot;;
        String s2 = &quot;Sakinala&quot;;
        Assert.assertNotEquals(s1, s2, &quot;Assert Failed as the two string are EQUAL&quot;);
    }
}
</pre>
<p><span style="font-weight: 400;">Below is the output for the above Program:</span></p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/1-1.png"><img decoding="async" loading="lazy" class="size-full wp-image-1004 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/1-1.png" alt="1" width="1324" height="428" srcset="https://automationtesting.in/wp-content/uploads/2016/12/1-1.png 1324w, https://automationtesting.in/wp-content/uploads/2016/12/1-1-300x97.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/1-1-768x248.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/1-1-1024x331.png 1024w" sizes="(max-width: 1324px) 100vw, 1324px" /></a></p>
<p><span style="font-weight: 400;">Below is the sample program where all the assertions will FAIL:</span></p>
<pre class="brush: java; highlight: [9,14,21,28,36,44]; title: ; notranslate">
import org.testng.Assert;
import org.testng.annotations.Test;


public class FailedAssertions
{
    @Test
    public void testOne()
    {
        Assert.assertTrue(false, &quot;Assert Failed as the actual condition is False&quot;);
    }
    @Test
    public void testTwo()
    {
        Assert.assertFalse(true, &quot;Assert Failed as the actual condition is True&quot;);
    }
    
    @Test
    public void testThree()
    {
        String s = null;
        Assert.assertNotNull(s,&quot;Assert Failed as the String is Null&quot;);
    }
    
    @Test
    public void testFour()
    {
        String s = &quot;Krishna&quot;;
        Assert.assertNull(s, &quot;Assert Failed as the String is NOT NULL&quot;);
    }
    
    @Test
    public void testFive()
    {
        String s1 = &quot;Krishna&quot;;
        String s2 = &quot;Sakinala&quot;;
        Assert.assertEquals(s1, s2, &quot;Assert Failed as the two string are NOT EQUAL&quot;);
    }
    
    @Test
    public void testSix()
    {
        String s1 = &quot;Krishna&quot;;
        String s2 = &quot;Krishna&quot;;
        Assert.assertNotEquals(s1, s2, &quot;Assert Failed as the two string are EQUAL&quot;);
    }
}
</pre>
<p><span style="font-weight: 400;"><br />
Below is the output for the above Program:</span></p>
<p><a href="https://automationtesting.in/wp-content/uploads/2016/12/2-1.png"><img decoding="async" loading="lazy" class="size-full wp-image-1005 aligncenter" src="https://automationtesting.in/wp-content/uploads/2016/12/2-1.png" alt="2" width="1321" height="479" srcset="https://automationtesting.in/wp-content/uploads/2016/12/2-1.png 1321w, https://automationtesting.in/wp-content/uploads/2016/12/2-1-300x109.png 300w, https://automationtesting.in/wp-content/uploads/2016/12/2-1-768x278.png 768w, https://automationtesting.in/wp-content/uploads/2016/12/2-1-1024x371.png 1024w" sizes="(max-width: 1321px) 100vw, 1321px" /></a></p>
<p><span style="font-weight: 400;">This way we will use the Assertions in testNG to know the status of the tests which are executed.</span></p>
<p><span style="font-weight: 400;">Please watch the you tube video for better understanding.</span><br />
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script><br />
<!-- Responsive --><br />
<ins class="adsbygoogle" style="display: block;" data-ad-client="ca-pub-9173866185064071" data-ad-slot="6638633547" data-ad-format="auto"></ins><br />
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></p>
<div id="themify_builder_content-902" data-postid="902" class="themify_builder_content themify_builder_content-902 themify_builder themify_builder_front">

	</div>
<!-- /themify_builder_content --><p>The post <a rel="nofollow" href="https://automationtesting.in/testng-assertions/">TestNG Assertions</a> appeared first on <a rel="nofollow" href="https://automationtesting.in">Selenium Webdriver Appium Complete Tutorial</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://automationtesting.in/testng-assertions/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
