BasicPath implements Path { @Override public String toString() { if (describedBy.isPresent() && !describedBy.equals(xpathExplanation)) { return describedBy.get(); } else { Optional<String> underlyingOption = (underlying.isPresent()) ? Optional.of("under reference element " + underlying.get()) : Optional.empty(); Optional<String> xpathOption = getXpathExplanationForToString(); Optional<String> propsOption = (elementProperties.size() == 1 && (!xpathOption.orElse("").contains(", ") || xpathOption.equals(describedBy))) ? getPropertiesToStringForLength1() : (elementProperties.size() == 2 && !xpathOption.orElse("").contains(" ")) ? Optional.of(format("that %s, and %s", elementProperties.get(0), elementProperties.get(elementProperties.size() - 1))) : (elementProperties.size() > 1 || (xpathOption.orElse("").contains(" ") && !elementProperties.isEmpty())) ? getPropertiesToStringForLengthLargerThan2() : Optional.empty(); return (xpathExplanation.isPresent() && !underlyingOption.isPresent() && !propsOption.isPresent()) ? xpathExplanation.get() : Stream.of(underlyingOption, xpathOption, propsOption).filter(Optional::isPresent).map(Optional::get). collect(Collectors.joining(", ")); } } private  BasicPath(Optional<WebElement> underlying,
                      Optional<String> xpath,
                      List<ElementProperty> elementProperties,
                      Optional<String> xpathExplanation,
                      Optional<String> describedBy,
                      Optional<String> insideXpath,
                      Optional<String> alternateXpath
    ); static PathBuilder builder(); static Path textNode(String text); static BasicPath customElement(String el); static BasicPath customNameSpaceElement(String el); static ChildNumber childNumber(Integer n); static GlobalOccurrenceNumber occurrenceNumber(Integer n); static Path firstOccurrenceOf(Path path); static Path lastOccurrenceOf(Path path); @Override Optional<String> getXPath(); @Override Optional<String> getAlternateXPath(); @Override Optional<WebElement> getUnderlyingSource(); @Override Optional<String> getXpathExplanation(); @Override Optional<String> getDescribedBy(); @Override List<ElementProperty> getElementProperties(); @Override Path describedBy(String description); @Override Path or(Path path); @Override Path that(ElementProperty... prop); @Override Path and(ElementProperty... prop); @Override Path withText(String txt); @Override Path inside(final Path path); @Override Path insideTopLevel(); @Override Path afterSibling(Path path); @Override Path immediatelyAfterSibling(Path path); @Override Path after(Path path); @Override Path beforeSibling(Path path); @Override Path immediatelyBeforeSibling(Path path); @Override Path before(Path path); @Override Path childOf(Path path); @Override Path parentOf(Path path); @Override Path containing(Path path); @Override Path contains(Path path); @Override Path ancestorOf(Path path); @Override Path descendantOf(Path path); @Override Path withGlobalIndex(Integer n); @Override Path withClass(String cssClass); @Override Path withClasses(String... cssClasses); @Override Path withTextContaining(String txt); @Override String toString(); static final BasicPath element; static final BasicPath div; static final BasicPath span; static final BasicPath image; static final BasicPath listItem; static final BasicPath button; static final BasicPath unorderedList; static final BasicPath input; static final BasicPath anchor; static final BasicPath form; static final BasicPath iframe; static final BasicPath html; static final BasicPath body; static final BasicPath header1; static final BasicPath header2; static final BasicPath header3; static final BasicPath header4; static final BasicPath header5; static final BasicPath header6; static final BasicPath header; static final BasicPath title; static final BasicPath tr; static final BasicPath td; static final BasicPath th; static final BasicPath table; static final BasicPath select; static final BasicPath option; static final BasicPath label; static final BasicPath section; static final BasicPath canvas; static final BasicPath textarea; static final BasicPath svg; }
@Test public void bareboneTostring() { BasicPath path = new PathBuilder().withXpath("Johhny").build(); assertThat(path.toString(), is(equalTo("xpath: \"Johhny\""))); }
@Test public void underlyingToString() { BasicPath path = new PathBuilder().withXpath("Johhny").withUnderlying(mock(WebElement.class)).build(); assertThat(path.toString(), startsWith("under reference element Mock for WebElement")); assertThat(path.toString(), endsWith("xpath: \"Johhny\"")); }