2

IDEA does not allow me to use table.raw();

I am new in cucumber so while I was learning/practising I tried to get the data from a DataTable by the following code

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());

}

I realized that IDEA type the raw method in red so I think maybe it is obsolete and now I should use a newer one.

mchawre
  • 10,744
  • 4
  • 35
  • 57
vcanopus
  • 23
  • 1
  • 5

2 Answers2

1

Rather then accessing the raw table you can address individual cells directly using cell(row, column) or use cells() to get a list of lists.

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));

    }
}
M.P. Korstanje
  • 10,426
  • 3
  • 36
  • 58
1

Just Want to explain MP's answer in detail for others easy understanding- Yes you wont be able to use raw() method anymore as, its not supported by cucumber api with newer versions of cucumber i.e. io.cucumber. However One can still still use it with older info.cukes dependencies.

So an alternative to raw() is as answered by MP.

For ex- Let's say you have below- Sample gherkin Step:

 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
Satyendra Sharma
  • 1,436
  • 13
  • 19