Monday 13 February 2017

Parallel Execution With Different Users .. using TestNG & DataProviders

Concurrent Execution with Different Browsers & Different Users.


BROWSER::

Set UP Browser to be Launched.

public WebDriver LaunchBrowser()
{
String browser = getpropvalue("Browser");
if (browser.equalsIgnoreCase("ff")) 
{
wdriver = new FirefoxDriver();
}
else if (browser.equalsIgnoreCase("chrome")) 
{
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver",
getpropvalue("chromepath"));
wdriver = new ChromeDriver(options);
wdriver.manage().window().maximize();
}
else if (browser.equalsIgnoreCase("ie")) 
{
System.setProperty("webdriver.ie.driver", "./drivers/IEDriverServer_x32_v2.47.0.exe");
wdriver = new InternetExplorerDriver();
}
else if (browser.equalsIgnoreCase("safari")) 
{
wdriver = new SafariDriver();
}
else if (browser.equalsIgnoreCase("opera")) 
{
wdriver = new OperaDriver();
}
launchBrowser();
return wdriver;
} 


Naviagte URL::

public void navigateurl()
{
              wdriver.get("URL");
}

Login Setup::

public void enterCredentials_For_multiple(String email)
{

             wdriver.findElement(By.xpath("//Login")).click();
      wdriver.findElement(By.xpath("")).sendKeys(email);
wdriver.findElement(By.xpath("Password")).sendKeys("");

}

Data Providers ::

This will help to provide different set of Data.

1.First Approach

@DataProvider(parallel = true)
public Object[][] getdata() throws EncryptedDocumentException, InvalidFormatException, IOException
{
Object[][] data = {{"harikrishna@gmail.com"},{"test@gmail.com"},{"test2@gmail.com"}};
return data;
}

2.Second Approach ::

Read From Excel File with Passing Different Set of Data

public String getLoginData(String uName) throws IOException, InvalidFormatException
{
String pass = null;
FileInputStream fis=new FileInputStream("../testdata/securityTestData.xls");
Workbook wb=WorkbookFactory.create(fis);
Sheet sh=wb.getSheet("concurrentLogin");
int noOfRows=sh.getLastRowNum();
for(int i=1;i<=noOfRows;i++)
{
Row row=sh.getRow(i);
if(row.getCell(0).getStringCellValue()==uName)
pass=row.getCell(1).getStringCellValue();
}
return pass;
}



Now Set testNg.xml ::







No comments:

Post a Comment