簡體   English   中英

使用POI和TestNG ..code的Selenium中的數據驅動測試出錯

[英]Data driven testing in Selenium using POI and TestNG ..code getting error

使用Selenium,我編寫了以下代碼以從Excel工作表中讀取數據,並將電子郵件和密碼鍵入Facebook的登錄頁面。 錯誤是使用try / catch的未處理表達式。 我該如何解決這個問題?

package Excelpack;

import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

 public class ClassTwo {

    WebDriver driver;

     String username;
     String password;

     @Test(dataProvider="testdata")
     public void testFireFox(String uname, String password1){

      driver.findElement(By.id("email")).clear();
      driver.findElement(By.id("email")).sendKeys(uname);
      driver.findElement(By.id("pass")).clear();
      driver.findElement(By.id("pass")).sendKeys(password1); 

     }   

    @DataProvider(name="testdata")
    public  Object[][] TestDataFeed1()  
    {

          FileInputStream fis=new FileInputStream("D:\\book3.xlsx");
          XSSFWorkbook wb=new XSSFWorkbook(fis);
          XSSFSheet sh1= wb.getSheetAt(0);
         int  numrow = sh1.getLastRowNum()-sh1.getFirstRowNum();  
           int  colnum =sh1.getRow(1).getLastCellNum()+1; 
             Object [][] facebookdata=new Object[numrow][colnum];
      for(int i=0;i<numrow;i++)
      {

         facebookdata[i][0]=sh1.getRow(0).getCell(i).getStringCellValue();
         facebookdata[i][1]=sh1.getRow(1).getCell(i).getStringCellValue();   

      }
        return facebookdata;
    }



  @BeforeTest
  public void Setup(){
  driver=new FirefoxDriver();
  driver.manage().window().maximize();
  driver.get("https://www.facebook.com/");
  }
}

如果您使用的是eclipse或intellijI之類的IDE,那么IDE會提示您解決方案,以添加“引發必要的異常”或在try / catch中編寫代碼塊。 從代碼的外觀來看,您似乎需要聲明在數據提供者TestDataFeed1上引發異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM