Showing posts with label Selenium WebDriver. Show all posts
Showing posts with label Selenium WebDriver. Show all posts

Run Selenium Webdriver Scripts using Command Line

Welcome to Selenium Tutorials, today we will learn Run Selenium Webdriver Scripts using Command Line with examples.After creating Selenium script in Eclipse,you can run easily
but it is not recommended every time because in case you want to run on client machine then it is recommended to use command prompt instead of opening eclipse and right click and run.




Before executing Selenium Test Scripts from command line then you should've selenium setup in your machine, still not done then follow the below link and complete the setup.

Selenium Webdriver Setup

Once you start designing Selenium Test cases Scripting continuously your Test Cases count will increase, so you've to manage your test cases accordingly. TestNG framework providing very helpful concept of creating testng.xml file based on requirement and put all relevant test classes inside the testng.xml file and run it as a Test Suite.

Trending Posts:

Write TestCase PASS/FAIL In Excel using Selenium
Solution - Testng Cannot Find ClassPath Error
Generate HTML Reports using Selenium
Webdriver Instance to Multiple Classes

Pre Requisites-

1- TestNG should be installed inEclipse.
2- testng xml file should be created.
3- Class-path should be set.

Run Selenium Webdriver Scripts using Command Line

Src - the .java files can be found here
Bin - the .class files will be generated here

Step 1- Create testng.xml files and store all xml into project home directory as given below.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Selenium Test Suite">
    <listeners>
        <listener class-name="org.uncommons.reportng.HTMLReporter"/>
        <listener class-name="org.uncommons.reportng.JUnitXMLReporter"/>       
    </listeners>
  <test name="SeleniumRegressionTest">
    <classes>
      <class name="com.sel.Selenium.Practise.GoogleSite"/>
    </classes>
  </test>
</suite>



Step 2- Set classpath now

Important points to remember-

1-Put all the jars (Selenium jars) into separate folder and  put that folder into project home directory.

I've created Lib folder and pasted all required jars inside a folder ,downloaded from Selenium website.

Refer below screenshot of Lib folder with required jar files.

2- Open command prompt and type E: and press enter because my project work Space in E drive.


Now go to project home directory for this type directory path and enter as below


Run Selenium Webdriver Scripts using Command Line

Now we can set classpath for this,specify bin folder.

Home Directory > set classpath=Home Directory\bin; and press enter

Specify lib folder where all jars is available

Home Directory > set classpath=Home Directory\lib\*; and press enter

Step 3-Now run xml file using below command

Home-directory > java org,testng.TestNG testng1.xml and hit enter




Other wise you can run in single step as below command.

Go to Project Folder path in Command Line.
Enter below command in command line and hit enter.


java -cp E:\QTPTutorials\Selenium_Workspace\Selenium_Tutorials\Lib\*;E:\QTPTutorials\Selenium_Workspace\Selenium_Tutorials\bin org.testng.TestNG testng.xml



Test Results:

Run Selenium Webdriver Scripts using Command Line
Test Results


Thanks for visiting my blog. If you find this post informative then please share with your friends and provide your valuable comments on this post.

Cross Browser Testing using Selenium WebDriver

Cross Browser Testing using Selenium WebDriver to run Test Scripts in different browsers like Google Chrome,Firefox ,Internet Explorer etc at a same time then we have to use TestNG Framework for Automating Cross Browser Testing using Selenium WebDriver.

What is Cross Browser Testing?

Cross Browser Testing means testing the application under test(AUT) with different browsers in order to verify all functionalities are working same in all browsers.



Problems if not done Cross Browser Testing

1.Main defect is Design issue.
2.Some functionalities not supports javascript because of browser
3.Some functionalities will not work in some browsers because of configurations.
4.Some time facing issues while uploading/Downloading file formats.
5.Faacing the problems with additional plugins like displaying grid details in applications.
6.Some functionalities will not work changing the campatability mode in browsers.

In order to over come above some problems we have to perform Cross Browser Testing for applications under test(AUT).

Pre-Requisites

1.testng.xml
2.Different browsers drivers(IE Driver,Chrome Driver etc).
3.Test Script class for test cases.
4.Declaring the browsers in a class.
5.@Parameters annotation which Describes how to pass parameters to a @Test method,where we are writing our Test Cases  i.e Test Scripts.

Example for Cross Browser Testing

Prepare textng.xml file to set up parameters for different browsers,follow same code as below.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Cross Browser Testing" preserve-order="true" verbose="2" parallel="tests">  
<parameter name="Weburl" value="http://www.google.com"></parameter>  
<test name="Internet Explorer">
<parameter name="WebBrowser" value="ie"></parameter>
<classes>
<class name="com.wiki.wiki.Cross"/>
</classes>
</test>
<test name="Google Chrome">
<parameter name="WebBrowser" value="chrome"></parameter>
<classes>
<class name="com.wiki.wikishown.Cross"/>
</classes>
</test>
<test name="Firefox">
<parameter name="WebBrowser" value="firefox"></parameter>
<classes>
<class name="com.wiki.wikishown.Cross"/>
</classes>
</test> 
</suite> 

Now create two classes one class is for driver initialization and Browser setting and second clas is for Test Scripts under @Test anotaitions,follow below classes
Create SelDriver.java class to initialize the driver and browsers set up as below

package com.wiki.seln;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

public class SelDriver {
public static WebDriver driver;
static String baseUrl;

@BeforeTest
@Parameters("WebBrowser")
public void setup(String WebBrowser){

//Adding verfication point using IF Condition
if(WebBrowser.equalsIgnoreCase("firefox")){
driver = new FirefoxDriver();

}else if(WebBrowser.equalsIgnoreCase("ie")){

//For ie browser we have to use System.SetProperty
System.setProperty("webdriver.ie.driver", "F:\\Java_Applications\\Zip Files\\IEDriverServer.exe");
driver = new InternetExplorerDriver();

}else if(WebBrowser.equalsIgnoreCase("chrome")){
//For Google chrome browser we have to use System.setProperty and Chrome Driver
System.setProperty("webdriver.chrome.driver", "F:\\Java_Applications\\Zip Files\\chromedriver.exe");
driver = new ChromeDriver();

}
//Maximize the windows of all browsers
driver.manage().window().maximize();

}
@AfterTest
public void tearDown(){
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

}

}

Now i am using Wikishown class and using inheritance wit the help of extends keyword as below

package com.wiki.seln;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class Cross extends SelDriver {

@Test(priority=1)
@Parameters("Weburl")
public void testMethod(String Weburl){

//Navigate to URL and Weburl is taking from testng.xml file
driver.navigate().to(Weburl);
//wait until page loads
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.liknText("Manual Testing")).click();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.findElement(By.linkText("Selenium")).click();

}

}

Above in two classes i have used @Parameters annotation to call parameter name from xml file.Now run xml file as run as -- TestNG Suite then it will run all @Test methods in a class and displays test execution results in Console as well as Test NG icon.

How to Add Screenshots to TestNG Report

How to add screenshot to TestNG Report example post provides complete real time experience coding and Testing is an activity to verify expected results.While Testing application using Selenium Testing it is very important to capture screenshot of application in order to verify any error is occurred in application while selenium script execution.

Manual testers takes screenshot using print screen (PrtSc) keyboard button or using any third party tools in order to log a defect in a Test Management tools for full proof.However coming to Selenium Automation Testing or Automatino Testing taking screenshot and using already taken screenshot in test reports is different.

How to Add Screenshots to TestNG Report

In this post you'll learn exactly how to take the screenshot and save the screenshot with different name or with timestamp and add those screenshots to TestNG Report OR Results in HTML reports.

Trending Posts

Write Test Cases PASS/FAIL in Excel using Selenium
Complete XPATH Tutorial examples
Selenium Data Driven Framework
Selenium HTML Reports Generation
Read Data From Properties files


Please follow below steps to perform the task.

1.Create the method for screenshot
2.Call the method in another classes to use in @Test methods
3.Store the Screenshot in a seperate folder with different name or timestamp.


Class 1:

package com.sel.Selenium.Practise;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
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.Reporter;
import org.testng.annotations.BeforeTest;


public class SelDriver {

public static WebDriver driver;
String baseurl;
public static Properties property;

@BeforeTest
public void openBrowser() throws IOException{

//Reporter .log is a Logger given by TestNG framework.
Reporter.log("Screenshot Capture in TestNG Results Started"); 
System.setProperty("webdriver.chrome.driver", "F:\\Java_Applications\\Zip Files\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
Reporter.log("Chrome Browser is Maximized");
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);

}

public void screenCapture() throws IOException{

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
File screenshotName = new File ("E:\\Screenshots\\"+System.currentTimeMillis()+"_"+".png");
FileUtils.copyFile(scrFile, screenshotName);
Reporter.log("<br><img src='"+screenshotName+"' height='300' width='300'/><br>");

}

}


Class 2:

package com.sel.Selenium.Practise;
import java.io.IOException;
import org.testng.Assert;
import org.testng.Reporter;
import org.testng.annotations.Test;

public class GoogleSite extends SelDriver {

@Test//Test Case one
public void seleniumElements() throws InterruptedException, IOException{

driver.get("https://learn-selenium-automation-testing.blogspot.in");

System.out.println("Open Google site");
Reporter.log("Selenium Site is Open");

screenCapture();//Calling same method created in first class
Reporter.log("Screenshot Capture is done");  
String Title=driver.getTitle();
Assert.assertEquals(Title, "Learn Selenium Automation Testing");
Reporter.log("Verifying the Page with Page Title");
Reporter.log("Screenshot Capture in TestNG Results ended.");
}

}


Now run the second class as TestNG Test ,you'll observe screenshot will added in specific folder with time-stamp ,refresh the project and open index.html file to check screenshot is added ot not in TestNG Results under Reporter Output link of TestNG Report.

Please try above code and let me know in case you're facing any issues.In case code is working fine,Please provide your feedback on below comment box.Thank you for reading and Have a Greate Selenium WebDriver Scripting.

Trending Posts

Write Test Cases PASS/FAIL in Excel using Selenium 
Complete XPATH Tutorial examples
Selenium Data Driven Framework
Selenium HTML Reports Generation
Read Data From Properties files

How to handle UnhandledAlertException in selenium

How to handle UnhandledAlertException in selenium webdriver explains issues facing with new geckodriver versions to open Firefox Browser and issues with Alerts.In this  UnhandledAlertException in selenium lesson,you'll get clear idea to resolve the issues in selenium test scripts.

Trending Posts:



Resolution:

Please watch below video for clear explanation with example.




You'can use below code to handle Alert Exception instead of AutoIT script.

Alert alert = switch().to.alert();
alert.sendKeys(username+Keys.TAB.toString()+Password);
alert.accept();

The above script can be useful to handle proxy Authentication in Firefox Browser and
it'll not work in Google Chrome.

Java Lang NullPointerException in Selenium

Java Lang NullPointerException in Selenium,While running the selenium test scripts you'll face some challenges with the test scripts,in that challenges this is the main important exception,not able to understand why it is displaying and most of the time you'll think that it is raised because of element is not identifying by the Selenium,that is not the proper answer.

Java Lang NullPointerException in Selenium

Java Lang NullPointerException in Selenium


Also Read:


Write TestCase is PASS/FAIL In seleniumTestNG Classpath errorSession ID is null using webdriver after calling quitHow to send extent reports in email with screenshots





Java Lang NullPointerException in Selenium

When coming to Java Lang NullPointerException in Selenium,when passing single webdriver instance to multiple classes,you'll face this type of problems.Please read below instructions  to resolve the same issue in Selenium.

SelDriver Class:



package com.sel.Selenium.Practise;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeSuite;

public class SelDriver {  
 public WebDriver driver;
 String baseurl = "http://www.google.co.in";  
 
 @BeforeSuite
 public void openBrowser(){
  
  driver = new FirefoxDriver();
  //driver = new HtmlUnitDriver();
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
  
 } 
}

GoogleSite Class:



package com.sel.Selenium.Practise;
import org.testng.Assert;
import org.testng.annotations.Test; 
public class GoogleSite extends SelDriver {
 
 @Test
 public void seleniumElements() throws InterruptedException{
  
  driver.get(baseurl);
  System.out.println("Open Google site");
  
  String Title=driver.getTitle();
  Assert.assertEquals(Title, "Google");
  
  try {
        Assert.assertEquals(driver.getTitle(), "Google's");
      } catch (Error e) {
        System.out.println(e.getCause());
      }   
 } 
}

I', extending the class from SelDriver main class to use WebDriver instance,But when running the above class,you'll face same issue i.e Java.Lang.NullPointerException for some methods.In order to resolve this issue,you need to add static for WebDriver declaration as below.



package com.sel.Selenium.Practise;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeSuite;

public class SelDriver {
 
 public static WebDriver driver;
 String baseurl = "http://www.google.co.in";  
 
 @BeforeSuite
 public void openBrowser(){
  
  driver = new FirefoxDriver();
  //driver = new HtmlUnitDriver();
  driver.manage().window().maximize();
  driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
  
 } 
}


Before Static Method Test Results:




After Changes - Test Results

[TestNG] Running:
  E:\QTPTutorials\Selenium_Workspace\Selenium_Tutorials\testng.xml

Open Google site
null
driver=FirefoxDriver: firefox on WINDOWS (f2f86423-9806-4b4a-ae92-7504e3db59be)
Enter Search Keyword
Clear Enter Keyword
clear works

===============================================
GoogleTestSuite
Total tests run: 2, Failures: 0, Skips: 0
===============================================

TestNG Test Results


Please provide your valuable comments on this solution in case it is resolved your java.lang.nullpointer exception in Selenium.

How To write Test Case is PASS or FAIL using Selenium

How To write Test Case is PASS or FAIL using Selenium,you can write Test case results PASS or FAIL in Excel using J Excel API and TesNG framework with Selenium WebDriver. Most of the time we are working with Excel,Test Cases in order to verify how many test cases are pass/fail in Excel and it is useful for sending the reports to respective managers.


How To write Test Case is PASS or FAIL using Selenium


Write Test Cases PASS or FAIL in SELENIUM

In this post you will learn clear idea about How To write Test Case is PASS or FAIL using Selenium with real time examples.I have created two classes one for ExcelUtility and another for Write the Excel file for each test cases.



Popular Posts

Selenium Xpath Tutorials
Read Data from Properties File
Selenium WebDriver Methods
TestNG Classpath error
Session ID is null using webdriver after calling quit
How to send extent reports in email with screenshots

Pre-Requisites

Step 1: Using JXL jar-You Can Download from Here
Step 2: Selenium WebDriver Configurations
Step 3: xls Test-Data file.
Step 4: addCell()
Step 5: Test Case Results
Step 6: Test Cases
Step 7: Read the xls file FileInputStream
Step 8: Read Workbook from FileINputStream
Step 9: Read Sheets from Workbook
Step 10: Column,rows

ExcelUtility Class

package com.selenium.Utility;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;

public class Excelutility {

public String Testcase; 
public WritableSheet writablesh; 
public WritableWorkbook workbookcopy;

@BeforeTest
public void queryParameterization() throws BiffException,IOException,RowsExceededException,WriteException, InterruptedException{

FileInputStream testfile = new FileInputStream("E:\\AppiumTutorials\\Selenium_Practice\\Testdata\\TestData.xls");//Now get 
WorkbookWorkbook wbook = Workbook.getWorkbook(testfile);
//Now get Workbook 
SheetSheet sheets = wbook.getSheet("Query_data");
int Norows = sheets.getRows();
//Read rows and columns and save it in String Two dimensional array
String inputdata[][] = new String[sheets.getRows()][sheets.getColumns()];
System.out.println("Number of rows present in TestData xls file is -"+Norows);
//For writing the data into excel we will use 
FileoutputStream classFileOutputStream testoutput = new FileOutputStream("E:\\AppiumTutorials\\Selenium_Practice\\SeleniumYoutube\\Testdata\\TestData_results.xls");
System.out.println("creating file one");
//To Create writable workbook
workbookcopy = Workbook.createWorkbook(testoutput);
System.out.println("creating file 2");
//To Create Writable sheet in Writable workbook
writablesh = workbookcopy.createSheet("Query_data",0);
System.out.println("creating file 3");

//Using for loop to write all the data to new sheet 
for(int i=0;i<sheets.getRows();i++) { 
for(int k=0;k<sheets.getColumns();k++) {
 inputdata[i][k] = sheets.getCell(k, i).getContents(); 
Label l = new Label(k, i, inputdata[i][k]); 
Label l2 = new Label(4,0,"Results"); 
writablesh.addCell(l); 
writablesh.addCell(l2); 

            }

        }

}


@AfterTest
public void writeexcels(){ 
try { 
workbookcopy.write(); 
} catch (IOException e) { 
e.printStackTrace(); 
} 

try { 
workbookcopy.close(); 
} catch (WriteException e) { 
e.printStackTrace(); 
} catch (IOException e) { 
e.printStackTrace(); 
     } 

  }

}

WriteExcel Class

package com.selenium.elements;
import java.util.concurrent.TimeUnit;
import jxl.write.Label;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import com.selenium.Utility.Excelutility;


public class WriteexcelFile extends Excelutility {

 WebDriver driver;
 String baseUrl = "https:hploadrunnertutorial.blogspot.in/";

 @Test(priority=1,description="Test Case 1-Open Firfox Browser and open baseUrl")

 public void openBrowser() throws RowsExceededException, WriteException{
 driver = new FirefoxDriver();
 driver.manage().window().maximize();
 driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
 driver.get(baseUrl);
 System.out.println("baseUrl is open in Firefox Browser");
 String Title=driver.getTitle();
 System.out.println(Title);

 if(Title.equalsIgnoreCase("HP Loadrunner Tutorial")){

 Testcase="PASS";

 }else{

 Testcase = "FAIL";

 }

 Label l3=new Label(4,1,Testcase);
 writablesh.addCell(l3);
 }

 @Test(priority=2,description="Test Case 2-Submit Query in the System")
 public void submitQuery() throws InterruptedException, RowsExceededException, WriteException{
 String name = writablesh.getCell(1,3).getContents();
 System.out.println(name);
 driver.findElement(By.id("ContactForm1_contact-form-name")).sendKeys(name);
 System.out.println("System enters name field.");
 Thread.sleep(3000);
 driver.findElement(By.id("ContactForm1_contact-form-email")).clear();
 String emails = writablesh.getCell(2,3).getContents();
 driver.findElement(By.id("ContactForm1_contact-form-email")).sendKeys(emails);
 System.out.println("System clears the fields");
 driver.findElement(By.id("ContactForm1_contact-form-email-message")).clear();
 String message = writablesh.getCell(3,3).getContents();
 driver.findElement(By.id("ContactForm1_contact-form-email-message")).sendKeys(message);
 driver.findElement(By.id("ContactForm1_contact-form-submit")).click();
 Thread.sleep(3000);
 String nametext = driver.findElement(By.id("ContactForm1_contact-form-name")).getAttribute("value");
 System.out.println("Print nametext is -"+nametext);
 Thread.sleep(3000);

 if(nametext.isEmpty()){
 Testcase = "PASS";

 }else{

 Testcase = "FAIL";

 }

 Label l3=new Label(4,2,Testcase);
 writablesh.addCell(l3);

       }
}



Please watch VIDEO Tutorial:






Test Results:

How To write Test Case is PASS or FAIL using Selenium


TESTNG Results:



How To write Test Case is PASS or FAIL using Selenium



Please provide your valuable comments on this topic and Please try to practice this example and provide your feedback.For more real time examples,please Read Selenium Complete Tutorials.

Mouse hover action in Selenium Webdriver

Mouse hover action in Selenium Webdriver,While working with web application menus you will face a problem that mouse hover,once mouse hover then only remaining menus will be displayed.In this post you will learn Mouse hover action in selenium webdriver using Web elements ,Actions classes in Selenium Web Driver.Below are the way of doing this is by using Action in class.

Mouse hover action in Selenium WebDriver


Mouse hover action in Selenium Webdriver

Method 1:

Here directly using link Text to check mouse hover for main menu or sub menu to identify the elements in webpage.

WebElement element = driver.findElement(By.linkText("More.."));
Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
driver.findElement(By.linkText("SQL")).click();

Some times it will not work then we can use another method as below to select SQL link from More.. menu according to above menu.

Also Read

Datadriven Framework using selenium
Verify element is enable in Selenium
Read Data From properties file using Selenium
Launch Firefox Browser using GeckoDriver
Selenium-Testng examples to execute multiple classes
Selenium WebDriver Methods
Generate HTML Reports using Selenium

For some applications mouse over will work upto certain fraction of seconds at that situation we can go for below method easily to identify the elements.This method will work deffinately with the help of action.moveToElement(element).click().build.perform

package com.gmail.account;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.apache.tools.ant.taskdefs.Exit;
import org.openqa.selenium.By;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;

public class MouseOver{

WebDriver driver;
String baseUrl;

@Test
public void mouseHover(){

driver = new FirefoxDriver();
String baseUrl = "http://www.wikishown.com";
driver.get(baseUrl);
driver.manage().window().maximize();
//Use Action
Actions action = new Actions(driver);
//Mouse over on elements using WebElments
WebElement element = driver.findElement(By.linkText("More.."));
//Now mouse should move to particular element
action.moveToElement(element).click().build().perform();
Thread.sleep(2000);
//Identifying the SubMenu and click on Subbmenu
action = new Actions(driver);
WebElement subelement=driver.findElement(By.linkText("SQL"));
//Thread.sleep(5000);
action.moveToElement(subelement).click().build().perform();

}

}

Run above script as Right Click on Script - Run As  - TestNG Test.

Conclusion:

I am expecting method 2 is very useful in your projects,in case it is working please provide your valuable comments and suggestions and please feel free to contact me through comment.Thank you for reading.