Jacobvu84 / selenium-vietnam-training-course

Questions Tracking
7 stars 5 forks source link

Using stream to create List Object #62

Open Jacobvu84 opened 5 years ago

Jacobvu84 commented 5 years ago

When you want to verify the expected item have exist in the list. This is the way to collect all items to List ( java 8+)

public class SearchResultsPage extends PageObject {

    @FindBy(css=".listing-card")
    List<WebElement> listingCards;

    public List<String> getResultTitles() {
        return listingCards.stream()
                .map(element -> element.getText())
                .collect(Collectors.toList());
    }
}

Jacob Vu khóa học Selenium WebDriver online cho cá nhân