1

I am trying to compare an expected list of string values with the actual string values in a list. Below is my code. Though the expList and actual list matches, boolean is returning false and the assertion throws the error. Please let me know where am I going wrong.

public void verifyFilesInFolder(String folder, String... files) {
    navigateToFolder(folder);
    List<String> expList = Arrays.asList(files);
    assertTrue("expected List did not match the actual list ", verifyTheFileNames(locator, expList));
}


public boolean verifyTheFileNames(String locator, List<String> expList) {
    List<WebElement> elements = driver.findElements(By.xpath(locator));
    ArrayList<String> actual = new ArrayList<String>();
    for (int i = 0; i < elements.size(); i++) {
        actual.add(elements.get(i).getText());
    }
    Collections.sort(actual);
    System.out.println("Actual List: " + actual);
    Collections.sort(expList);
    System.out.println("Expected List: " + expList);
    boolean flag = actual.equals(expList);
    if (flag)
        System.out.println("Actual and Expected List are same");
    return flag;

}

Output:

Actual List: [blank.html, blank.jpg, blank.mov, blank.mp3, blank.txt]
Expected List: [blank.html, blank.jpg, blank.mov, blank.mp3, blank.txt]

Bashir
  • 2,057
  • 5
  • 19
  • 44
Rahul
  • 759
  • 3
  • 21
  • 43

1 Answers1

-1

Issue resolved by changing the files from String to String[].

Before :

String files = "blank.html, blank.jpg, blank.mov, blank.mp3, blank.txt";

After :

String[] files = {"blank.html", "blank.jpg", "blank.mov", "blank.mp3", "blank.txt"};
Rahul
  • 759
  • 3
  • 21
  • 43