TestNG Interview Questions in addition to Answers

TestNG is a testing framework inspired from JUnit as well as NUnit exactly introducing about novel funct TestNG Interview Questions as well as Answers
TestNG Interview Questions

1) What is TestNG?


TestNG is a testing framework inspired from JUnit as well as NUnit exactly introducing about novel functionalities that arrive to a greater extent than powerful as well as easier to use.

2) What is TestNG inwards Selenium?


Using TestNG framework inwards Selenium nosotros can,

> Generate Detailed (HTML) Test Reports.

> Group Test cases.

> Parallel Test execution.

> Parameterize Tests

> Execute multiple classes / programs using XML file etc...

3) How to install TestNG inwards Eclipse?


In Eclipse IDE,

Help bill of fare -> Install New Software -> Click Add

> Enter refer every bit "TestNG"

> Enter url as: "http://beust.com/eclipse/"

> Select "TestNG"

> Next > Next > stimulate got the Agreement > finish

4) Give a TestNG Program example?

public cast TestNGexample {

@Test   
public void verifyTitle() {
WebDriver driver = novel FirefoxDriver();
driver.get("http:\\gmail.com");
String Actual = driver.getTitle();
Assert.assertEquals(Actual, "Gmail");
}
}

Note:

> primary method is non required for TestNG programs.

> TestNG programme contains methods that incorporate @ annotations.

> If nosotros don't write @Test Annotation as well as thus the method won't endure executed.

5) What are the of import TestNG Annotations?


Important TestNG Annotations are:

@Test - Annotation for every Test (Method)

@BeforeMethod - pre-condition for every try illustration inwards a program.
@AfterMethod - Post status for every try illustration inwards a program.

@BeforeClass - pre status for all try cases inwards a program/class
@AfterClass - post status for all try cases inwards a program/class

@BeforeTest - pre status for all try cases inwards multiple classes/programs
@AfterTest - post status for all try cases inwards multiple classes / programs

6) How to practice multiple Test cases inwards a program/class?


public cast TestNGexample {

@Test   
public void testA () {
Assert.assertEquals("Gmail", "Gmail");
}

@Test       
public void testC() {
Assert.assertEquals("Gmail", "Gmail");
}

@Test       
public void testB() {
Assert.assertEquals("abc", "abc");
}
}

As per TestNG program:

A
C
B
---------------------
Execution Flow:

A
B
C
-------------------------
If yous desire to command the Test execution catamenia as well as thus utilization "priority" Attribute.

Syntax:

@Test (priority = number")

Example:

public cast TestNGexample {

@Test (priority=1)   
public void testA () {
Assert.assertEquals("Gmail", "Gmail");
}

@Test (priority=2)       
public void testC() {
Assert.assertEquals("Gmail", "Gmail");
}

@Test(priority=3)       
public void testB() {
Assert.assertEquals("abc", "abc");
}
}

7) How to execute multiple programme or classes?


Using XML file nosotros tin execute multiple Java programs or classes at a time.

8) How to practice XML file?


Create XML file

Select Java Project as well as Right click

> New
> Other
> Enter XML as well as Select XML file
> Enter File Name
> Finish

9) Give an illustration for executing multiple programs or classes?


XML File
-------------
<?xml version="1.0" encoding="UTF-8"?>
<suite refer = "Ecommerce suite">
<test refer ="Sanity Tests">
<classes>
<class name="javaExamples.Class1"/>
<class name="javaExamples.Class2"/>

</classes>
</test>
</suite>
---------------------
Class 1:

public cast Class1 {
    @BeforeClass
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterClass
    populace void logout(){
    System.out.println("Logout Successful");
    }
    @Test (priority=1)
    populace void search(){
    System.out.println("Search Successful");
    }
    @Test(priority=2)
    populace void advancedSearch(){
    System.out.println("Advanced Search Successful");
    }
    @Test(priority=3)
    populace void buyProducts(){
    System.out.println("Buying Products Successful");
    }
}
-------------------------------
Class 2:

public cast Class2 {
    @BeforeClass
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterClass
    populace void logout(){
    System.out.println("Logout Successful");
    }
    @Test
    populace void accountSummary(){
    System.out.println("Account Summary Successful");
    }
    @Test
    populace void fundTransfer(){
    System.out.println("Fund Transfer Successful");
    }
    @Test
    populace void billPayment(){
    System.out.println("Bill Payment Successful");
    }
}
--------------------------------
10) Give an illustration for parallel Test execution?


XML File

<suite refer = "Parallel Test suite" parallel = "classes" thread-count = "2">
<test refer = "Sanity Test">

<classes>
<class refer = "seleniumTests.Class1"/>
<class refer = "seleniumTests.Class2"/>
</classes>

</test>
</suite>
------------------------
parallel = "methods": TestNG volition run all the methods inwards split upwards threads.
parallel = "classes" : TestNG volition run all the methods inwards the same cast inwards the same thread.
parallel = "tests" : TestNG volition run all the methods inwards the same <test> tag inwards the same thread.
------------------------
Class 1

public cast Class1 {
    @BeforeTest
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterTest
    populace void logout(){
    System.out.println("Logout Successful");
    }
    @Test (priority = 1)
    populace void search(){
    System.out.println("Search Successful");
    }
    @Test (priority = 2)
    populace void advancedSearch(){
    System.out.println("Advanced Search Successful");
    }
    @Test (priority = 3)
    populace void buyProducts(){
    System.out.println("Buying Products Successful");
    }
    @Test (priority = 4)
    populace void testCase(){
    System.out.println("Test Case inwards "+getClass().getSimpleName()
    + " With Thread id: " + Thread.currentThread().getId());
    }
    }
-----------------------------------------
Class 2

public cast Class2 {
    /*@BeforeClass
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterClass
    populace void logout(){
    System.out.println("Logout Successful");
    }*/
    @Test (priority = 1)
    populace void accountSummary(){
    System.out.println("Account Summary Successful");
    }
    @Test (priority = 2)
    populace void fundTransfer(){
    System.out.println("Fund Transfer Successful");
    }
    @Test (priority = 3)
    populace void billPayment(){
    System.out.println("Bill Payment Successful");
    }
    @Test (priority = 4)
    populace void testCase(){
    System.out.println("Test Case inwards "+getClass().getSimpleName()
    + " With Thread id: " + Thread.currentThread().getId());
    }
}
---------------
11) Give an Example for grouping Test cases?


XML File

<suite refer ="suite">
<test refer ="test">

<groups>
<run>
<include refer = "sanity"/>
</run>
</groups>

<classes>
<class refer = "seleniumTests.GroupTests"/>
<class refer = "seleniumTests.GroupTests2"/>
</classes>

</test>
</suite>
-------------------------------
Java Program/Class file

@BeforeTest (groups ={"sanity","regression"})
    populace void login(){
    System.out.println("Login Successful");
    }
    @AfterTest (groups ={"sanity","regression"})
    populace void logout(){
    System.out.println("Logout Successful");
    }
   
    @Test (groups ={"sanity"})
    populace void search(){
    System.out.println("Search Successful");
    }
    @Test (groups ={"sanity","regression"})
    populace void advancedSearch(){
    System.out.println("Advanced Search Successful");
    }
    @Test (groups ={"sanity", "regression"})
    populace void buyProducts(){
    System.out.println("Buying Products Successful");
    }
    @Test (groups ={"regression"})
    populace void abcd(){
    System.out.println("Abcd Successful");
    }
    @Test (groups ={"regression"})
    populace void xyza(){
    System.out.println("Xyza Successful");
    }
    @Test (groups ={"regression"})
    populace void asdf(){
    System.out.println("Asdf Successful");
    }
}
------------
12) Give an illustration for Data Driven Testing?


If yous desire piece of employment amongst excel, as well as thus download tertiary political party jolt files

Ex: jxl

public cast DataDriven {
    @Test (dataProvider="testdata")
    populace void Addition(String val1, String val2, String val3){
        int a = Integer.parseInt(val1);
        int b = Integer.parseInt(val2);
        int c = Integer.parseInt(val3);
        int trial = a + b + c;
        System.out.println(result);
    }
   
@DataProvider(name="testdata")
    populace Object [] [] readExcel() throws BiffException, IOException {
        File f = novel File("C:/Users/gcreddy/Desktop/Input.xls");
        Workbook w = Workbook.getWorkbook(f);
        Sheet sec = w.getSheet(0);
        int rows = s.getRows();
        int columns = s.getColumns();
        //System.out.println(rows);
        //System.out.println(columns);
        String Inputdata [] [] = novel String [rows] [columns];
        for (int i = 0; i<rows; i++){
            for (int j = 0; j<columns; j++){
                Cell c = s.getCell(j, i);
                Inputdata [i] [j] = c.getContents();
                //System.out.println(Inputdata[i][j]);
            }
        }
        provide Inputdata;
        }
}

---------------------------------------------------------------
Selenium Interview Questions-1

Selenium Interview Questions-2

Selenium WebDriver Questions

TestNG Interview Questions

Sumber http://www.gcreddy.com/
Post a Comment (0)
Previous Post Next Post