TestNG


TestNG is a testing framework which is inspired by junit. TestNG is the latest framework of selenium. it gives to complete freedom to write the testcases in group or dependent to the other method. NG  stand for ‘NEXT GENERATION’. testing of next generation.

TestNG gives the lot of advantage over the other testing framework.

1-we  can run the parallel test cases using TestNG.

2-TestNG gives the feature of test annotation.by using annotation we can easily understand.

3-TestNG gives the feature to generate the report in HTML format and also XML format.

TestNG framework we can divide the testcases in three part.

1-@Beforemethod

2-@Test

3-@Aftermethod

@Beforemethod- In before method we launch the Firefox or chrome driver get the URL.

@Test- In test we execute the main login of our test case.its like a main method.

@Aftermethod- we can write the close or quit method.

We can install the TestNG easily. TestNG plugin easily available for ECLIPSE IDE.

Here is the code of TestNG-

package automationframework;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
public class TestNG {

public WebDriver driver;
@Test
public void main() {
driver.findElement(By.id("email")).sendKeys("write.atfconnect1@gmail.com");
driver.findElement(By.id("pass")).sendKeys("jNlWcD8s89fH");
driver.findElement(By.id("loginbutton1")).click();
System.out.println("Login Successfully, now it is the time to Log Off buddy");

}
@BeforeMethod
public void beforeMethod() {

driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://www.facebook.com");

}

@AfterMethod
public void afterMethod() {
driver.quit();

}

}

TestNG also generate the report in HTML format which are describe the your test case result which emailable-report.html.

new emailable

vd

Handle Multiple Test cases in TestNG-

In the end of test we need to execute all the test cases. these test cases dependent to each other. TestNG gives the functionality to execute these test cases simultaneously.

We need to create a testing.xml file which handle multiple test cases.

Testing.xml-

<suite name ="Test-suite">
<test name = "testng">
<classes>
<class name = "automationframework.TestNG"/>
<class name = "automationframework.Login"/>
</classes>
</test>
</suite>

its a very simple XML code first of all we make a <suite> tag where we can define the test suite name after that we write <test> tag where we define test name. we can give the any name of test suite and test case but <class> tag name is combination of package name and test name

Advertisements
This entry was posted in Scala, Test, testing, tests and tagged , , . Bookmark the permalink.

One Response to TestNG

  1. Pingback: TestNg Groups | Knoldus

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s