0

ハイブリッドフレームワークを使用したUDF(ユーザー定義関数)の新機能です。私は "ExcelUtils"クラスを作成しました。ここで私はエクセルシートを読み書きするためのコードを書いています。また、私は "Utils"クラスを作成しました。これは、テストケース名をExcelから取得した後に1つの関数名を作成しました。getRowContains私はオブジェクトを取得できません。excelSheetSelenium webdriverでUDFを使用してExcelシートを取得できません

Utilsのクラス:

public class Utils { 

    private static FirefoxDriver driver; 

    public static WebDriver openBrowser(int iTestCaseRow){ 
     String sBrowserName; 
     try{ 
      sBrowserName= ExcelUtils.getCellData(iTestCaseRow, Constant.Col_Browser); 

      if(sBrowserName.equals("Mozilla")){ 
       System.setProperty("webdriver.gecko.driver", "/Users/ileadsynapse/Desktop/CT/geckodriver"); 
       DesiredCapabilities capabilities= DesiredCapabilities.firefox(); 
       capabilities.setCapability("marionette", true); 
       driver = new FirefoxDriver(capabilities); 
       Log.info("New driver instantiated"); 
       driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
       Log.info("Implicit wait applied on the driver for 10 seconds"); 
       driver.get(Constant.URL); 
       Log.info("Web application get launched"); 
      } 
     }catch(Exception e){ 
      Log.error("Class Utils | Method OpenBrowser | Exception Desc:"+e.getMessage()); 
     } 

     return driver; 

    } 

    public static String getTestCaseName(String sTestCase){ 
     String value= sTestCase; 

     try { 
      int posi= value.indexOf("@"); 
      value = value.substring(0, posi); 
      posi= value.lastIndexOf("."); 
      value= value.substring(posi+1); 

      return value; 

     } catch (Exception e) { 
      // TODO: handle exception 
      Log.error("Class Utils | Method getTestCaseName | Exception desc : "+e.getMessage()); 
      throw(e); 
     } 

    } 

    public static int getRowContains(String sTestCaseName, int colNum){ 
       int i;  
     try{ 
      int rowCount= excelSheet. 


     }catch(Exception e){ 

     } 
    } 

} 

ExcelUtils:

public class ExcelUtils { 

    private static XSSFWorkbook excelBook; 
    private static XSSFSheet excelSheet; 
    private static XSSFCell cell; 
    private static XSSFRow row; 

    //This method is to set the File path and to open the Excel file, Pass Excel Path and Sheetname as Arguments to this method 
    public static void setExcelFile(String Path, String SheetName) throws Exception{ 
     try{ 
      //Open excel file 
      FileInputStream excelFile = new FileInputStream(Path); 
      // Access the required test data sheet 
      excelBook = new XSSFWorkbook(excelFile); 
      excelSheet = excelBook.getSheet("Sheet1"); 
     }catch(Exception e){ 
      throw(e); 
     } 
    } 

    //This method is to read the test data from the Excel cell, in this we are passing parameters as Row num and Col num 
    public static String getCellData(int RowNum, int ColNum){ 
     try { 
      cell = excelSheet.getRow(RowNum).getCell(ColNum); 
      String cellData = cell.getStringCellValue(); 
      return cellData; 
     } catch (Exception e) { 
      return ""; 
     } 
    } 

    //This method is to write in the Excel cell, Row num and Col num are the parameters 
    public static void setCellData(String Result, int RowNum, int ColNum) throws Exception{ 
     try{ 
      row = excelSheet.getRow(RowNum); 
      cell = row.getCell(ColNum, row.RETURN_BLANK_AS_NULL); 
      if(cell==null){ 
       cell = row.createCell(ColNum); 
       cell.setCellValue(Result); 
      }else{ 
       cell.setCellValue(Result); 
      } 

      // Constant variables Test Data path and Test Data file name 
      FileOutputStream fileOut = new FileOutputStream(Constant.Path_TestData+ Constant.File_TestData); 
      excelBook.write(fileOut); 
      fileOut.flush(); 
      fileOut.close(); 

     }catch(Exception e){ 
      throw(e); 
     } 
    } 

} 

いずれかは、それを解決する助けてください。私はこのチュートリアルを参照しました:http://toolsqa.com/selenium-webdriver/user-defined-functions/

+0

のすべての要素は、任意のエラーを取得しましたへのアクセスにutilsのクラスでExcelUtilsオブジェクトを作成しますか?はいの場合はそれを投稿し、正確に何をしたいですか?あなたはExcelを使って読み書きしますか? –

答えて

0

あなたはUtilsクラスのExcelシートにアクセスするためにExcelオブジェクトを作成していません。

excelsheetオブジェクトを取得するには、utilsクラスのprivate static XSSFSheet excelSheet;を宣言します。

または

ExcelUtils

+0

"ExcelUtils"クラスでExcelのパスを設定したので、なぜそれをutilsクラスで定義する必要がありますか? – SelenyanC2

+0

私の答えを編集しました。問題を解決するためのアイデアが得られれば幸いです –

関連する問題