I've implemented this method:
@FindBy(partialLinkText = "Avocode")
List<WebElement> results;
public List<String> getSearchResults (){
List<String> text = results.stream().map(WebElement::getText).collect(Collectors.toList());
return text;
}
Then I have a test trying to find any match with 'avocode':
assertThat(find.getSearchResults(),IsCollectionContaining.hasItem("Avocode"));
My imported libraries:
import org.hamcrest.core.IsCollectionContaining;
import org.testng.Assert;
import org.testng.annotations.Test;
import pageObjects.Search;
import static org.junit.Assert.assertThat;
++ My dependencies:
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
I expect that test will run successfully, although I'm getting:
java.lang.AssertionError:
Expected: a collection containing "Avocode"but: was "Avocode \"ready to eat\" DUO pack", was "Avocode Hass, was "Avocode Fuerte", was "Avocode Bacon"
I believe I have followed all tips here in stack-overflow, but nothing is working - Avocode is there, so it should pass...
I will appreciate any help (I'm new in programming).
Thanks, Lijana