Thursday, April 22, 2021

WebDriver - Simple way to assert List values (Select List box)


Below is one of the simple and straight forward way to assert list of values. 

This is applicable when we want to validate table data or values from multiple webelements.

List<String> expectedData = new ArrayList<>(Arrays.asList("Madan","Blog"));

 List<String> optionValues = new ArrayList<>();

new Select(element).getOptions().stream().forEach(listOption -> optionValues.add(listOption.getText()));

Assert.assertEquals(optionValues,expectedData);