这是黄瓜中表.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 用红色键入原始方法,所以我认为它可能已经过时了,现在我应该使用更新的方法。

您可以使用

cell(row, column)直接对单个单元格进行寻址,或使用cells()获取列表列表,而不是访问原始表。

import io.cucumber.datatable.DataTable;
import java.util.List;
class Scratch {
    public static void main(String[] args) {
        DataTable data = //...create data table here
        System.out.println("The value is : " + data.cell(1, 0));
        System.out.println("The value is : " + data.cell(1, 1));
        List<List<String>> cells = data.cells();
        System.out.println("The value is : " + cells.get(1).get(0));
        System.out.println("The value is : " + cells.get(1).get(1));
    }
}
只想详细

解释一下 MP 的回答,让别人容易理解——是的,您将无法再使用 raw(( 方法,因为使用较新版本的黄瓜(即 io.cucumber(的黄瓜 api 不支持它。但是,仍然可以将其与较旧的info.cukes依赖项一起使用。

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

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

 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

最新更新