0

Selenium を使用して、Excel シートからデータを読み取り、電子メールとパスワードを Facebook のログイン ページに入力する以下のコードを作成しました。エラーは、try/catch を使用する Unhandled 式です。どうすればこれを解決できますか?

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/");
  }
}
4

1 に答える 1

0

eclipse や intellijI などの IDE を使用している場合、IDE は「必要な例外をスローする」を追加するか、try/catch にコードのブロックを書き込むかの解決策を提示します。コードの外観から、データプロバイダー TestDataFeed1 でスロー例外を宣言する必要があるようです。

于 2015-07-07T19:04:51.873 に答える