Skip to main content

Mobile Automation Testing| TestNG Annotations| Automation Testing Framework| Software Quality Assurance| QA Automation


Hello Everyone! Welcome back to MODTECHSTUFF. 
In this blog, we will talk about Java Annotations and how to Use TestNG Annotations with the help of Eclipse IDE step by step!

Modtechstuff

Table Of Contents

  • 1. What is Test Automation?
  • 2. What is TestNG?
  • 3. TestNG Annotation.
  • 3.1  Create a TestNG file
  • 3.2  Creating TestNG Test cases
  • 4. JAVA Annotations.
  • 5. Implementing Annotation in TestNG

What is Test Automation?

Automation is taking the software development industry by a tempest, particularly in the testing division. There are numerous stages associated with the product improvement procedure, and Automation is utilized in the launched stages. It is significantly utilized during testing of web applications, as it permits testers to execute various tests simultaneously on an individual machine. 
Automation testing, or all the more precisely test Automation, leads to the Automation of execution of test cases and contrasting their outcomes and the normal outcomes. That is a standard definition that you may discover wherever on the web. Thus, how about we make it all the more clear with a model. As you probably are aware, manual testing is performed by people while composing each test cases independently and afterward executing them cautiously. Automation testing is performed with the assistance of an Automation tool to run the test cases. It is generally used to automate repetitive assignments and other testing projects that can't execute by manual testing. Likewise, it underpins both functional and non-functional testing.

What is TestNG?

TestNG is a complete automation testing framework that covers all testing models, for example, unit testing, functional testing,  and an end to end testing. Motivated by JUnit and NUnit, Cedric Beust made TestNG in 2004 to make start to finish testing straightforward and simple. With comments and announcing highlights, TestNG makes it simple to code test cases. TestNG is the short type of Test Next Generation. 
The best part about TestNG is the reporting component. It offers an elaborated test report demonstrating what number of test cases failed, what number of skipped, and what number of succeeded. At the point when you run a test suite with various test cases and in the event that one test case failed, you need to run all test cases again. You can't run the failed test alone. Thus, you will be running successful tests as well. In any case, TestNG permits you to create a failed test report as an XML file. It implies you can run this XML document to run just failed test cases.

Another significant advantage is that you can group numerous test cases and run them as indicated by the pre-characterized sequence or run one case on several moments. TestNG permits equal testing which implies you can run different experiments on numerous stages while effectively incorporating it with CI/CD conditions, for example, Jenkins. 
Annotations are one of the excellent features of TestNG that permits engineers to handily exception the code automatically. While multithreaded testing is braced, runtime setup is adaptable and API comes as a module.


 TestNG Annotations.

Annotations in TestNG are an extraordinary element that permits engineers to handily comprehend the code while consequently dealing with exemptions. While multi-threaded testing is upheld, runtime design is adaptable and API comes as a plugin.

The First Step is to Create a TestNG file.

Launch Eclipse and go to Package Explorer view. Select the test project you named earlier Right-click on src and select new ->other

TestNG


Now click on TestNG and it will display TestNG Class.
TestNG Class

On the next screen, it will ask you to enter new TestNG class details.
TestNg class

After clicking on the finish button, you will see a screen like shown below
Eclipse IDE


Congratulations Eclipse will now create your TestNG template automatically and You can start writing your code!


The Second Step is Creating TestNG Test cases.

In this step, we write a simple Test case and run it in Eclipse. Below a simple code to print an element using TestNG.
package TestNGConcept;import org.testng.annotations.Test;
public class BasicTestNGTest {
@Test(enabled=false)
public static void TestM1(){
System.out.println("TestM1");
}
@Test
public static void TestM2(){
System.out.println("TestM2");
}
@Test
public static void TestM3(){
System.out.println("TestM3");
}
@Test
public static void TestM4(){
System.out.println("TestM4");
}
@Test
public static void RegisterTest(){
System.out.println("RegisterTest");
}
@Test
public static void LoginTest(){
System.out.println("LoginTest");
}
@Test
public static void ResetApp(){
System.out.println("ResetApp");
}
@Test(priority=1)
public static void TestcaseRegister(){
System.out.println("TestcaseRegister");
}
@Test(priority=2)
public static void TestcaseLogin(){
System.out.println("TestcaseLogin");
}
@Test(priority=3)
public static void TestcasePasswordChange(){
System.out.println("TestcasePasswordChange");
}
}

JAVA Annotations.

Annotations make Java code straightforward and simple to digest. An annotation is a kind of metadata that doesn't legitimately influence the Annotations code activity however gives data about a program that is excluded from the real program. They help the compiler to effortlessly distinguish bugs and mistakes while helping creators by smothering alerts. Utilizing Annotations, you can produce XML records or code. Annotations are utilized to give supplemental data about a program. 
Annotations start with '@' and don't change the action of a compiled program. 
Annotations help to relate metadata (data) to the program components for example instance variables, constructors, methods, classes, and so forth. 
Annotations are not pure remarks as they can change the manner in which a program is treated by the compiler. See the beneath code for instance.


class Blog
{
public void display()
{
System.out.println("Modtechstuff()");
}
}
class Derived extends Blog
{
@Override
public void display(int x)
{
System.out.println("Derived display(int )");
}
public static void main(String args[])
{
Derived obj = new Derived();
obj.display();
}
}
There are 5 classes of Annotations:- 

1. Marker Annotations: 
The main reason for existing is to check an assertion. These Annotations contain no individuals and don't comprise any information. Along these lines, its essence as a Annotations is adequate. Since, marker Annotations contains no individuals, basically deciding if it is available or missing is adequate. @Override is a case of Marker Annotation. 

2. Single value Annotations: 
These explanations contain just a single element and permit a shorthand type of determining the estimation of the element. We possibly need to determine the incentive for that part when the Annotations are applied and don't have to indicate the name of the part. Anyway so as to utilize this shorthand, the name of the part should be esteem. 

3. Full Annotations: 
These Annotations comprise of various information individuals/name, value, sets. 
for eg:- @TestAnnotation(owner="Modtechstfuf", value="Blog") 

4. Type Annotations: 
These Annotations can be applied to wherever where a sort is being utilized. For instance, we can comment on the return type of a method. These are proclaimed Annotations on with @Target Annotations. 

5. Repeating Annotations: 
These are the Annotations that can be applied to a separate thing more than once. For a comment to be repeatable it must be explained with the @Repeatable explanation, which is characterized in the java.lang.annotation bundle. Its worth field determines the holder type for the repeatable comment. The compartment is determined as a comment whose worth field is a variety of the repeatable comment type. Thus, to make a repeatable comment, right off the bat the compartment comment is made and afterward the comment type is indicated as a contention to the @Repeatable comment.

 Implementing Annotation in TestNG

TestNG is famous for its annotation features that are straightforward and easy to use. They are clear as crystal. Here is the available annotation in TestNG: 


Modtechstuff
Modtechstuff

Let Discuss an example of TestNG Annotations Implementation
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.*;
public class modtechstufffile {
public String baseUrl = "https://modtechstuff.blogspot.com/";
String driverPath = "C:\\chromedriver.exe";
public WebDriver driver ;
@BeforeTest
public void launchBrowser() {
System.out.println(" Chrom Launching");
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new FirefoxDriver();
driver.get(baseUrl);
}
@Test
public void verifyHomepageTitle() {
String expectedTitle = "MODTECHSTUFF";
String actualTitle = driver.getTitle();
Assert.assertEquals(actualTitle, expectedTitle);
}
@AfterTest
public void terminateBrowser(){
driver.close();
}
}
In the above Program, the main
test case about verifying the title page
of my website MODTECHSTUFF is written with the @Test annotation. Before running the main test case, you need to request the Google Chrome browser. So, the browser launching function is written in the @BeforeTest method. So, this method is executed first. After running the test case, the launched browser should be closed. This method is added in @AfterTest annotation which will be executed after the @Test method is executed. If you want to run a single test case multiple times, you can add priority values along with the @Test annotation. In that case, the lowest priority value method will be executed first.


For any query send me a message here. I will ready to help(In FREE).



Author:: HAROON

For more details please visit  MODTECHSTUFF

FOLLOW ME @

      


Comments

  1. Your content is so unique and interesting. Please make next blog on Mobile Testing Tools.

    ReplyDelete
  2. Great work Haroon, you're doing a wonderful job. Keep it up.

    ReplyDelete
  3. Its realy great content....keep sharing...

    please visit my new blog...also
    https://kidscricketcoaching.blogspot.com/2020/05/episode-15-back-foot-defense-drill.html

    ReplyDelete
  4. Thanks for delivering a good stuff, Explanation is good, Nice Article.
    software testing training in chennai

    ReplyDelete

Post a Comment

Donate Us to Keep this site Alive! With PayPal

Popular posts from this blog

How to Automate OTP using Appium and Selenium Framework ?

Hello Everyone! Welcome back to another Fresh article of MODTECHST UFF where you Learn Automation testing. In this article, we will talk about Integrating the OTP SMS reading capability with your Selenium - Appium Framework that will surely help you out. There can be three solutions to this problem. Solution 1: Ask your development team to fix the OTP check process to any static value. Solution 2: Ask your development team to provide you an API in which you can pass some parameter in response he can return you the OTP sent against that number.  Solution 3: Design two Appium scripts one is two handle Websites and one is to handle the Android message box, so after sending OTP from the web execute the second script to read a message from the message box. OTP is a 2-factor authentication mechanism that was build to avoid ROBOT / Automation SO you never find the solution direct solution for that. What is Appium? Appium is an open-source structure that permits you to lead automating test...

How to create my own blog| A complete beginner's guide| Updated(May 2020)

Hello Everyone! Welcome back to MODTECHST UFF.  In this blog, we will talk about How to create your own blog and how to earn from the blog. This guide will provide each and every possible detail about blogging. I realize that beginning a blog can appear to be overpowering and scary. This free guide is tied in with blogging for amateurs and will show you how to be a blogger with simply the most essential PC aptitudes. So whether you're a student or professional, you can make your own blog in just 1 hour!!! I am not afraid to concede that when I was first figuring out how to manufacture a blog I committed a huge amount of errors. You can profit by overtime of my experience so you don't repeat these equivalent mix-ups when you make your own blog. I made this free guide with the goal that anybody can figure out how to blog rapidly and without any problem. What's more, on the off chance that you stall out anytime if you don't mind send me a message and I will give a magnific...

Top 5 Automation Testing Tools[2020]

Hello Everyone! Welcome back to another Fresh article of MODTECHST UFF where you Learn Automation testing. In this article, we will talk about Updated Top 5 Automation Testing Tools[2020] that will surely help you out. Quality at speed is the need of great importance in the product development industry. This is the reason associations are hoping to embrace Agile, Continuous Integration (CD), and DevOps techniques to discover arrangements. Test automation is a basic part of these techniques that can empower associations to give quality at speed.  In straightforward terms, automation testing is a procedure of automated test case execution and the creation of test results with no human intercession. It extensively brings down the expense and exertion that is in any case required in manual testing. It limits the possibility of mistakes by limiting excess manual work.  To execute automation testing, associations require the help of a decent automation testing organization...

Ad

Enter your email address:

Delivered by FeedBurner