i
WebDriver Introduction
Selenium WebDriver Architecture
Introduction to WebDriver API
Introduction to WebDriver – Code
Handling Dropdowns and Select class
Handling Multiple Dropdown values and Links
Handling Radio buttons and Checkboxes
Capture Screenshots and Email test results
Browser Navigation Methods
Handling tabs
Capturing screenshot, Handling tabs and pop-ups – Code
Handling tabs and Pop-ups – Code
Handling Alerts
Handling User Authentication and Input alerts
HtmlUnitDriver and Handling Captchas
Handling Web Tables
Synchronization
Handling WebTables, Synchronization issues, Firefoxprofiles – Code
Actions Class
Event Listeners, Event Firing Mouse, Coordinates – Code
Handling Mouse Hover in Selenium
JavascriptExecutor
Handling Iframes
IsElementPresent, IsEnabled, IsSelected
Working with Chrome Driver - Part 1
Working with FireFox Driver - Part 2
Working with Internet Explorer Driver - Part 3
Handling SSL Certificate
Desired Capabilities
How to Encode password in WebDriver
Handling JQuery Elements - Drag and Drop, Sliders, Resizable
Handling JQuery Elements - Drag and Drop, Sliders, Resizable – Code
Working on IE Browser using Actions
TestNG, Ant & Report Generation through XSLT
Introduction to TestNG and Annotations
TestNG Parameterization
Configuring ANT, Generating TestNG & XSLT Reports
Code for generating XSLT / Surefire Reports through MAVEN
TestNG Parameterization Excel Reading
Handling Multiple data providers
TestNG XSLT Jar, Build.xml & TestNG.xml file
Frameworks Introduction
Hybrid (DATA + KEYWORD) driven Framework
Framework Architecture
Reading Excel sheets
TestNG DataProvider
Data Provider with Hashtable
Handling Multiple Test Suites
Multiple DataProviders
Setting up Run-modes at Suite Level
Setting up Runmodes at TestCase Level
Creating a common utility for Run-modes
Hybrid Framework Code
TestNG?
Test class structure without TestNG:
Test class structure with TestNG:
TestNG configuration in Project:
There are few things need to take care in order to use the TestNG in any automation project:
<dependency>
<groupId>org.testnggroupId>
<artifactId>testngartifactId>
<version>6.14.3version>
<scope>testscope>
dependency>
TestNG Annotations
There are several annotations available in TestNG. Let us discuss some of the most used annotations of the TestNG.
Let’s create a simple TestNG code consisting of two test methods with @Test,@BeforeClass, @AfterClass, @BeforeMethod, and @AfterMethod annotations.
package SeleniumTest.SeleniumTest;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.DisplayOrder;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class TestNGTest {
ExtentReports extent;
ExtentTest logger;
WebDriver driver ;
@BeforeClass
public void startReport()
{
extent=new ExtentReports(System.getProperty("user.dir")+"/test-output/ExtentReport.html",null, DisplayOrder.NEWEST_FIRST);
extent.addSystemInfo("Host Name","Software Testing blog")
.addSystemInfo("Environment","Test Envt")
.addSystemInfo("User Name","Kamal Gairola");
extent.loadConfig(new File(System.getProperty("user.dir")+"/extent-config.xml"));
}
@BeforeMethod
public void startDriver()
{
driver=new ChromeDriver();
this.driver.get("https://selflearning.io/");
}
@Test
public void passTest() {
logger=extent.startTest("passTest");
Assert.assertTrue(true);
logger.log(LogStatus.PASS, "passTest is passed");
}
@Test
public void failTest()
{
logger=extent.startTest("failTest");
Assert.assertTrue(false);
logger.log(LogStatus.PASS, "failTest is passed");
}
@AfterMethod
public void TestResult(ITestResult result) throws IOException
{
if(result.getStatus()==ITestResult.FAILURE)
{
logger.log(LogStatus.FAIL, "Test case"+result.getName());
logger.log(LogStatus.FAIL, "Test case failed is "+result.getThrowable());
String scrPath=CaptureScreenshot.getScreenshot(driver,result.getName());
logger.log(LogStatus.FAIL,logger.addScreenCapture(scrPath));
extent.endTest(logger);
}
}
@AfterClass
public void completeTest()
{
extent.flush();
SendingMail.sendMail(System.getProperty("user.dir")+"/test-output/ExtentReport.html");
}
}
We can run this test by selecting the “Run As> TestNG Test”. We can also generate the testing.xml from the TestNG suite. Follow below steps to generate the testing.xml:
Don't miss out!