2017-11-04 6 views
0

Cucumberを使用してテーブルのテーブルヘッダー(ここでは "http://toolsqa.com/automation-practice-table/")をアサートしようとしています。文字列値のアサーションが正しく機能していない

比較は起こっており、同じである必要がありますが、何らかの理由で私の主張が失敗しています。

エラー - -

junit.framework.AssertionFailedError: expected:<[Structure]> but was:<Structure> 

コード -

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

    for (int i = 0; i < actualHeaders.size(); i++) { 
     Assert.assertEquals(expectedHeaders.get(i), actualHeaders.get(i)); 
    } 
} 

特集[ファイル] -

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

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

実際の値でtoStringを呼び出してください。文字列を文字列ではない文字列と比較しています。 –

+0

あなたは精巧にできますが、私は両方とも既に文字列に設定されていると思います: リスト> expectedTitles = table.raw(); stringOfHeaders.add(header.getText()。toString()); – noMoreMutants

答えて

2

同様

私はエラー、コードおよび機能のファイルが一覧表示されます@ネイサン - ヒューズはすでにsai d:文字列のリストと文字列を比較しています。 expectedTitlesはストリングのリストであり、stringOfHeadersはストリングのリストです。したがって、

assertEquals(expectedTitles.get(i), stringOfHeaders.get(i)) 

は、ストリングのリストをストリングと比較しているため、そのために失敗します。私はあなたがしたいと思います

assertEquals(expectedTitles.get(i).get(0), stringOfHeaders.get(i)) 
+0

はいステファン、あなたの提案は助けになった、ありがとう!一つは、比較が正常に終了した後、私は次のエラーが発生します - java.lang.IndexOutOfBoundsException:Index:7、Size:7おそらく私のループが正しくないでしょうか? – noMoreMutants

関連する問題