Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findAll method with lambda is not working as expected #2892

Closed
rakeshnambiar opened this issue Aug 20, 2022 · 3 comments
Closed

findAll method with lambda is not working as expected #2892

rakeshnambiar opened this issue Aug 20, 2022 · 3 comments

Comments

@rakeshnambiar
Copy link

rakeshnambiar commented Aug 20, 2022

findAll method is not working as expected as documented here https://serenity-bdd.github.io/docs/screenplay/screenplay_fundamentals#using-lambda-expressions-to-create-custom-tasks.
It's working with the @FindB approach like:

    @FindBy(css = "a.u-faux-block-link__overlay.js-headline-text")
    static List<WebElement> news_headings;

whereas it's not working with the code:

    public static Question<Integer> numberOfNewsArticles() {
        return Question.about("the number of news items")
                .answeredBy(
                        actor -> BrowseTheWeb.as(actor).findAll("a.u-faux-block-link__overlay.js-headline-text").size());
    }

The web page which I tried was: https://www.theguardian.com/tone/news
Also, I am wondering - do we have any alternative method to get the list of elements with Target instead of the css or XPath locators

@globalworming
Copy link
Collaborator

it works with "body a.u-faux-block-link__overlay.js-headline-text"
seems like one of the cases where "cssOrXpathSelector" is evaluated to xpath.

this runs successfully

@Test
  void countElements() {
    tester.attemptsTo(Open.url("https://www.theguardian.com/tone/news"));
    tester.should(seeThat(numberOfNewsArticles(), CoreMatchers.is(21)));
  }
  private static Question<Integer> numberOfNewsArticles() {
    return Question.about("the number of news articles")
        .answeredBy(
            actor -> BrowseTheWeb.as(actor).findAll("body a.u-faux-block-link__overlay.js-headline-text").size());
  }

@rakeshnambiar
Copy link
Author

@globalworming Thanks a lot for your reply. The main highlights of the latest SerenityJS version is the Target. Is there any way I can get the ListOfWebElement with the Target?

@globalworming
Copy link
Collaborator

  @Test
  void countElements() {
    tester.attemptsTo(Open.url("https://www.theguardian.com/tone/news"));
    tester.should(seeThat(numberOfNewsArticles(), CoreMatchers.is(21)));
  }

  private static Question<Integer> numberOfNewsArticles() {
    Target newsArticles =
        Target.the("news articles")
            .located(By.cssSelector("a.u-faux-block-link__overlay.js-headline-text"));
    return Question.about("the number of news articles")
        .answeredBy(actor -> newsArticles.resolveAllFor(actor).size());
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants