2017-11-05 20 views
-1
의 2 개의 목록을 비교했을 때

나는 성공적으로 비교 완료 문자열, 두 개의 목록을 비교하고, 그러나 후에, 나는 얻을 -색인 - 문자열

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) 

첫 번째 목록 I을 오이 기능 파일에서 전달하십시오. 두 번째는이 웹 사이트의 표 머리글에서 수집합니다. "http://toolsqa.com/automation-practice-table/"

for 루프를 변경하려고했지만 도움이되지 않습니다. Stack Overflow에서 다른 사람들의 동일한 문제를 읽었지만 해결할 수는 없습니다. 나는 무엇을해야할지 모른다.

코드 - -

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

기능 파일 - actualHeaders 이상이

Scenario: Test Table Header assertion 
Then table with id "content" has header values of 

    | Structure | 
    | Country | 
    | City | 
    | Height | 
    | Built | 
    | Rank | 
    | … | 
+0

예외의 전체 스택 추적을 게시하십시오. – Turing85

+1

목록의 길이가 같은지 어떻게 확인할 수 있습니까? – Mike

+0

좋아, 나는 conole에서 모든 것을 추가하고, 위의 질문을 지금 편집했습니다. 필요한 것이 더 있다면, 그것을 얻는 방법을 알아야합니다. – noMoreMutants

답변

1

아마 expectedHeaders 때문에 적은 요소

는 다음 코드와 기능 파일입니다.

+0

테이블이 포함 된 페이지를 검사하는 경우 태그의 수는 7입니다. 기능 파일의 내 테이블 또한 7 – noMoreMutants

+0

입니다. 그러나 색인은 null 기반이므로 8 번째 요소 인 색인 7에 액세스합니다. – SF23

+0

당신이 옳았어요! – noMoreMutants