Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java在selenium中将结果输入excel文件_Java_Excel_Selenium_Selenium Webdriver - Fatal编程技术网

如何使用java在selenium中将结果输入excel文件

如何使用java在selenium中将结果输入excel文件,java,excel,selenium,selenium-webdriver,Java,Excel,Selenium,Selenium Webdriver,我已经完成了从excel读取输入数据的代码编写,现在我想将通过、失败的结果写入excel中的特定测试用例,但我不知道如何编写正确的代码。你能给我举个例子吗 请帮帮我。 这是我的密码 public static void main(String[] args) throws IOException { WebDriver driver=null; Scanner scanner = new Scanner(System.in

我已经完成了从excel读取输入数据的代码编写,现在我想将通过、失败的结果写入excel中的特定测试用例,但我不知道如何编写正确的代码。你能给我举个例子吗

请帮帮我。 这是我的密码

            public static void main(String[] args) throws IOException {
            WebDriver driver=null;
             Scanner scanner = new Scanner(System.in);
           //  prompt for the URL
            System.out.print("Enter your URL: ");
            // get their input as a String
            String URL = scanner.next();
            //System.out.println( URL );

            final FirefoxProfile firefoxProfile = new FirefoxProfile();
          driver = new FirefoxDriver(firefoxProfile);
           driver.get(URL);
          driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS);
          driver.manage().window().maximize();
            //read data from excel
                try {   
                  FileInputStream file = new FileInputStream(new File ("C:\\Documents and Settings\\Deepa\\Desktop\\AMC test cases1.xls")); 
                   HSSFWorkbook workbook = new HSSFWorkbook(file);
                   HSSFSheet sheet = workbook.getSheet("login page");

                   WebElement login=driver.findElement(By.cssSelector("a[data-target='#login-box']"));
                     login.click();
                     driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);

    //For Email ID 
       driver.findElement(By.id(sheet.getRow(1).getCell(1).getStringCellValue())).sendKeys(sheet.getRow(1).getCell(0).getStringCellValue());

    //FOR Password 

    driver.findElement(By.id(sheet.getRow(2).getCell(1).getStringCellValue())).sendKeys(sheet.getRow(2).getCell(0).getStringCellValue());

     //For Submit the form 
      driver.findElement(By.id(sheet.getRow(3).getCell(1).getStringCellValue())).click();

                   file.close();
//Else

             } catch (FileNotFoundException fnfe) {
                     fnfe.printStackTrace();
             } catch (IOException ioe) {
                      ioe.printStackTrace();
                    }

使用POI JAR使用
getXLcellValue
函数在excel中获取值使用
setXLCellValue
函数在excel中设置值

参数:-

  • xlpath->Excel文件的位置
  • Excel文件中的图纸名称->图纸名称
  • rowNum和cellNum->数据所在的行和列编号 出席


使用POI JAR使用
getXLcellValue
函数在excel中获取值使用
setXLCellValue
函数在excel中设置值

参数:-

  • xlpath->Excel文件的位置
  • Excel文件中的图纸名称->图纸名称
  • rowNum和cellNum->数据所在的行和列编号 出席


谢谢,但如果存在错误,我希望根据绑定到输入字段的错误类返回通过失败结果。如果发生错误,则结果将失败,否则结果将通过。谢谢,但我希望根据绑定到输入字段的错误类返回通过失败结果(如果存在错误)。如果发生错误,则返回通过失败结果结果将为失败,否则结果为通过。
public String getXLcellValue(String xlpath, String sheetName, int rowNum, int cellNum)

  {
     try{
            FileInputStream fis=new FileInputStream(xlpath);
        Workbook wb=WorkbookFactory.create(fis);

    Log.info("Get the value from the cell(getXLcellValue)");

        return wb.getSheet(sheetName).getRow(rowNum).getCell(cellNum).getStringCellValue();
}
catch(Exception ex)
{
    Log.info("Error in getXLcellValue ="+ ex.getMessage());
}
 return "";
}


   //set the value of the cell present in specific sheet

    void setXLCellValue(String xlpath,String sheetName,int rowNum,int cellNum, String input)
   {

     try{
         FileInputStream fis=new FileInputStream(xlpath);

         Workbook wb=WorkbookFactory.create(fis);

    wb.getSheet(sheetName).getRow(rowNum).createCell(cellNum).setCellValue(input);

    FileOutputStream fos=new FileOutputStream(xlpath);

    wb.write(fos);

    fos.close();

    Log.info("Set the value in cell(setXLCellValue)");

}
catch(Exception ex)
{
    Log.info("Error in setXLCellValue ="+ ex.getMessage());
}
}