public class ExcelDataConfig {
XSSFWorkbook wb;
XSSFSheet sheet1;
XSSFSheet sheet2;
public ExcelDataConfig (String excelPath) {
try {
File src = new File (excelPath);
FileInputStream fis = new FileInputStream (src);
wb=new XSSFWorkbook(fis);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public String getData (int sheetNumber, int row, int column)
{
sheet1=wb.getSheetAt (sheetNumber);
String data= sheet1.getRow(row).getCell(column).getStringCellValue();
return data;
}
public String getData1 (int sheetNumber, int row, int column)
{
sheet2=wb.getSheetAt (sheetNumber);
String data1= sheet2.getRow(row).getCell(column).getStringCellValue();
return data1;
}
public int getRowCount(int sheetIndex){
int row=wb.getSheetAt(sheetIndex).getLastRowNum();
row=row+1;
return row;
}
}
=============================================== ================================= 公共类AddUser {
WebDriver driver;
@Test(数据提供程序=" addUserData&#34)
public void AddUser1(String username, String password,
String firstName, String lastName, String userId, String emailId , CharSequence[] phoneNo,
String password1, String confirmPassword) throws InterruptedException{
String driverPath=System.getProperty("user.dir")+"/DriverFiles/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", driverPath);
WebDriver driver =new ChromeDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("http://qa.ipactsolutions.com/SCM/signIn");
driver.findElement(By.id("userName")).sendKeys(username);
driver.findElement(By.id("password")).sendKeys(password);
driver.findElement(By.xpath("//*[@id='submit']")).click();
Thread.sleep(5000);
System.out.println(driver.getTitle());
driver.findElement(By.xpath("//*[@id='main_nav']/ul/li[9]/a/span[2]")).click(); //Click on Administration tab;
// driver.findElement(By.xpath("//*[@id='ALL_CONTENT_ID']/div[2]/div[1]/div[2]/ul/li[1]/a")).click(); //Click on User tab in Administration ;
driver.findElement(By.xpath("//*[@id='page_content']/div[1]/div[2]/a[2]/i")).click(); //Click on Add User;
driver.findElement(By.id("firstName")).sendKeys(firstName);
driver.findElement(By.id("lastName")).sendKeys(lastName);
driver.findElement(By.id("userName")).sendKeys(userId);
driver.findElement(By.id("emailId")).sendKeys(emailId);
driver.findElement(By.id("phoneNo")).sendKeys(phoneNo);
Thread.sleep(2000);
driver.findElement(By.id("password")).sendKeys(password1);
driver.findElement(By.id("confirmPassword")).sendKeys(confirmPassword);
driver.findElement(By.xpath("//*[@id='entityId_ms']")).click(); //Click on Entity drop down;
driver.findElement(By.xpath("//*[@id='ALL_CONTENT_ID']/div[5]/ul/li[2]/label/span")).click(); //Select production check box;
driver.findElement(By.xpath("//*[@id='entityId_ms']")).click(); //close the Entity drop down
String filePath = System.getProperty("user.dir")+"/UploadFiles/Admin_M.jpg"; //Select upload image icon;
driver.findElement(By.id("file")).sendKeys(filePath); //Select uploading file;
driver.findElement(By.xpath("//*[@id='userDetailsForm']/div[4]/div/div/div/label")).click(); //click on All View Access;
driver.findElement(By.xpath("//*[@id='userDetailsForm']/div[5]/div/div/div/div/label[1]")).click(); //Select role as admin;
driver.findElement(By.xpath("//*[@id='userDetailsForm']/div[6]/input")).click(); //Click on create button;
driver.findElement(By.xpath("//*[@id='ALL_CONTENT_ID']/div[5]/div[3]/div/button")).click(); //Click on Ok button in the popup message;
driver.quit();
}
public void tearDown(){
driver.quit();
}
@DataProvider(name="addUserData")
public Object[][] passData(){
ExcelDataConfig config=new ExcelDataConfig("E:\\KetanWorkspace\\Z_Ipact\\Excel Data\\TestData.xlsx");
int rows=config.getRowCount(0);
Object[][] data=new Object[rows][2];
for(int i=0;i<rows;i++)
{
data[i][0]=config.getData(0, i, 0);
data[i][1]=config.getData(0, i, 1);
}
Object[][] data1=new Object[rows][8];
for(int i=0;i<rows;i++)
{
data1[i][0]=config.getData(1, i, 0);
data1[i][1]=config.getData(1, i, 1);
data1[i][2]=config.getData(1, i, 2);
data1[i][3]=config.getData(1, i, 3);
data1[i][4]=config.getData(1, i, 4);
data1[i][5]=config.getData(1, i, 5);
data1[i][6]=config.getData(1, i, 6);
}
return data1;
}
}