Wednesday, 3 October 2018

TestNG-Introduction-Basic Program

TestNG-Next Generation

1)Using TestNG to test the Application as Module by Module.

2)It is not a In build Framework,need to Install Sepreately in Eclipse

3)To Test the Modules as in Priority Order.

4)It Support Data Driven Testing(To Pass a Inputs in Program Itself).

5)It Support Parallel Testing.(Run the Application in Different Browser's in Same Time).

6)It generate the Test Reports(after execute the Program Refresh the Project)-It generate the Test folder.

Note:Right Click the Project-->Press the Option Refresh.

7)There is No Main Method in TestNG.(Replace that using the Annotation Concept).

Types of Annotation:

Basic Annotation:
@BeforeClass
@BeforeMethod
@Test
@AfterMethod
@AfterClass

@BeforeTest
@AfterTest

For Data Driven Testing:

@DataProvider

For Parallel Testing:

@Parameters

Sample Program for TestNG:

Basic Annotations: 
package SampleTestNgPgm;

import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class NewTest {
@Test
public void f1() {
System.out.println("functional test");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("open url");

}

@AfterMethod
public void afterMethod() {

System.out.println("close url");

}

@BeforeClass
public void beforeClass() {
System.out.println("open browser");
}

@AfterClass
public void afterClass() {
System.out.println("close browser");
}

}

Output of the Program:



Note:Right Click the Project-->Press the Option Refresh and Open the index.html


Test a Multiple Checkbox with in Single Click

To Test a Multiple Checkbox with in Single Click.

When the Checkbox element contains with Same (Name-Locator).



WebDriver t=new ChromeDriver();

t.get("url");

List<WebElement> s=t.findElements(By.name("email_to[]")));

System.out.println(s.getSize());

for(int i=1;i<s.getSize();i++)
{
s.get(i).click(); ---->Select the Dropdown

s.get(i).click(); ---->Deselect the Dropdown
}