public List<Msg> getAllMessages() {
        List<Msg> result = new ArrayList<>();
        if (!isDisplayed()) {
            return result;
        }

        List<WebElement> messagesSeverities = findElements(By.tagName("div"));
        for (WebElement messageSeverity : messagesSeverities) {

            Severity severity = Severity.toSeverity(messageSeverity.getDomAttribute("class"));

            for (WebElement message : messageSeverity.findElements(By.cssSelector("li"))) {
                Msg msg = new Msg();
                msg.setSeverity(severity);
                msg.setSummary(message.findElement(By.className("ui-messages-" + Severity.toName(severity) + "-summary")).getText());
                try {
                    msg.setDetail(message.findElement(By.className("ui-messages-" + Severity.toName(severity) + "-detail")).getText());
                }
                catch (NoSuchElementException e) {
                    // ignore, it's optional
                }

                result.add(msg);
            }
        }

        return result;
    }
Component wrapper for the PrimeFaces {@code p:messages}.
primefaces-selenium/primefaces-selenium-components/src/main/java/org/primefaces/selenium/component/Messages.java