I am comparing two List of Strings, which finish comparing successfully, but then after, I get a -
java.lang.IndexOutOfBoundsException: Index: 7, Size: 7
at java.util.ArrayList.rangeCheck(ArrayList.java:653)
at java.util.ArrayList.get(ArrayList.java:429)
at java.util.Collections$UnmodifiableList.get(Collections.java:1309)
at com.cucumber.CucumberWebGui.StepDefinitions.tableHeaders(StepDefinitions.java:254)
at ✽.Then table with id "content" has header values of(tableHeader.feature:9)
The first list I pass in from a cucumber feature file. The second I collect from the table headers at this website - "http://toolsqa.com/automation-practice-table/"
I have tried changing the for loop, but it doesn't help. I have read other people's same issue on Stack Overflow, but I cannot solve it. I don't know what to do.
Here is the code and feature file -
Code -
@SuppressWarnings("deprecation")
@Then("^table with id \"([^\"]*)\" has header values of$")
public void tableHeaders(String id, DataTable table) {
java.util.List<java.util.List<String>> expectedHeaders = table.raw();
WebElement container = driver.findElement(By.id(id));
List<WebElement> allHeaders = container.findElements(By.tagName("th"));
List<String> actualHeaders = new ArrayList<String>();
for (WebElement header : allHeaders) {
actualHeaders.add(header.getText());
}
for (int i = 0; i < actualHeaders.size(); i++) {
Assert.assertEquals(expectedHeaders.get(i).get(0), actualHeaders.get(i));
}
}
Feature File -
Scenario: Test Table Header assertion
Then table with id "content" has header values of
| Structure |
| Country |
| City |
| Height |
| Built |
| Rank |
| … |