How to pass the argument into the script while using Hashtable to store data from Excel | Selenium Training|Java|WebDriver|TestNG|Frameworks|Videos
10% April Month Discount Avail now

Selenium Training Forum

How to pass the argument into the script while using Hashtable to store data from Excel

A
Avijeet Post on 08/04/2019

I wrote the code for passing data from Excel but while passing the arguement to the script its failing. Below given the code.Kindly advise.

I have 5 column with 10 rows and i want to read data from excel and use in the script. I'm able to put the data into hashtable and read the data but unable to pass the arguement  into the script.

 

 

 

public class PPDS_Login {


@Test(dataProvider="PPD")


public void PPDS(Hashtable<String,String> myData) throws InterruptedException {


System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\Driver\\ChromeDriver.exe");

WebDriver cd=new ChromeDriver();

cd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

cd.manage().window().maximize();

cd.get("http://ppds-sit.int.thomsonreuters.com/PPDSWeb/Login.aspx?timeout=true&ReturnUrl=%2fPPDSWeb%2fPages%2fSubscriber%2fMaintSubscriber.aspx");

cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_btnSubmit\"]")).click();
cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_txtUserName\"]")).sendKeys("test.developer");
cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_txtPassword\"]")).sendKeys("Password1");
cd.findElement(By.xpath("//*[@id=\"ctl00_loginControls_btnSubmit\"]")).click();
cd.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
cd.findElement(By.xpath("//*[@id='txtPGCode']")).sendKeys(table.equals(o));
cd.findElement(By.xpath("//*[@id='cmbPCType']")).sendKeys(table.);



// for below webelement need to Read data from Excel


cd.findElement(By.xpath("//*[@id=\"txtDescription\"]")).sendKeys(myData.get(getData()));
cd.findElement(By.xpath("//*[@id=\"txtLongDescription\"]")).sendKeys(myData.get(getData()));
cd.findElement(By.xpath("//*[@id=\"txtApplicability\"]")).sendKeys(myData.get(getData()));
cd.findElement(By.xpath("//*[@id=\"txtNotes\"]")).sendKeys(myData.get(getData()));
cd.findElement(By.xpath("//*[@id=\"cmbContact\"]")).sendKeys(myData.get(getData()));



cd.findElement(By.xpath("//*[@id=\"btn_PGMaint_Apply\"]")).click();

String x=cd.findElement(By.xpath("//*[@id=\"PGMaint_Messages\"]/div")).getText();

System.out.println(x);

cd.findElement(By.xpath("//*[@id=\"dlgControl_btnOK\"]")).click();

cd.findElement(By.xpath("//*[@id=\"dlgControl_btnOK\"]")).click();
Thread.sleep(1000);
cd.findElement(By.xpath("//*[@id='ctl01_hypLogOut']")).click();


cd.quit();

//sa.assertAll();



}


@DataProvider(name="PPD")

public Object [] [] getData(){
Xls_Reader xls= new Xls_Reader("C:\\Selenium\\Test_Data.xlsx");



int rownum= xls.getRowCount("Permission_Code_Screen");

int colnum=xls.getColumnCount("Permission_Code_Screen");

System.out.println(rownum);
System.out.println(colnum);

Hashtable <String, String> table=null;

Object myData[] [] = new Object[rownum][1];


for(int i=2;i<rownum;i++) {

table= new Hashtable<String,String>();

for(int j=0;j<colnum;j++) {

String data=xls.getCellData("Permission_Code_Screen", j, i);
String key=xls.getCellData("Permission_Code_Screen", j, 1);

//System.out.println(key+ "---------->" +data);

table.put(key, data);

}

System.out.println(table);

myData[0][i]=table;

System.out.println(" ============================== ");

}

return myData;

}

}

D

Instructor

Demo Reply on 09/04/2019

Please export the project in a compressed zip file and also include all the dependent files.

A
Avijeet Reply on 10/04/2019

Added the project but unable to add all jar file as its not allowing due to its size. if you will provide me the mail id i can send all.

D

Instructor

Demo Reply on 10/04/2019

Which framework you're following?

D

Instructor

Demo Reply on 10/04/2019

Additionally, make sure that you are using the exact column names as keys

A
Avijeet Reply on 10/04/2019

its data driven. 

 

as you have mentioned that column name as keys - does this mean we have to use the column name of excel sheet?