首页 > 解决方案 > 这是 Cucumber 中 table.raw 的当前方法

问题描述

IDEA 不允许我使用 table.raw();

我是黄瓜新手,所以在学习/练习时,我尝试通过以下代码从 DataTable 获取数据

public void iEnterTheFollowingForLogin(DataTable table) {

    List<List<String>> data = table.raw();
    System.out.println("The value is : "+ data.get(1).get(0).toString());
    System.out.println("The value is : "+ data.get(1).get(1).toString());

}

我意识到 IDEA 将原始方法输入为红色,所以我认为它可能已经过时,现在我应该使用更新的方法。

标签: seleniumintellij-ideacucumber-java

解决方案


只是想详细解释 MP 的答案以便其他人容易理解 - 是的,您将无法再使用 raw() 方法,因为黄瓜 api 不支持具有较新版本的黄瓜,即 io.cucumber。但是,仍然可以将它与旧的 info.cukes 依赖项一起使用。

因此,MP 回答了 raw() 的替代方案。

例如-假设您有以下-样品小黄瓜步骤:

 Then I should see following sections in my app detail page
   |Basic Details|Bank Details|Reconciliation|Summarised Options|Currency Code|
   
 >> The Cucumber step definition for above step should be like belwo-
   
  @Then("I should see following sections in my app detail page")
   public void verifySectionsOnDetailPageUI(List<List<String>> dTable) {

        //Create your table as below (notice- dataTable declared as- List<List<String>> in method argument above)
        DataTable data= DataTable.create(dTable); 
        
        // to get number of rows from DataTable
        int i=data.cells().size(); 
        
        // To print entire row's column (iterate via for loop using size if u have more than one row defined in data table 
        System.out.println("All Cells Data: "+data.cells());
        
        //Read cell by cell data as below, row index to be started from 1 if you have column headings provided in ur table
        
        System.out.println(data.cell(0,0));
        System.out.println(data.cell(0,1));
        System.out.println(data.cell(0,2));
        .....
        ......... so On .. to be used as per your step's objective .....
        
        O/P: 
        
        Basic Details
        Bank Details
        Reconciliation


推荐阅读