question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `.where` filters in Serenity/JS 3.0.0

See original GitHub issue

As per my conversation with @viper3400 on Serenity/JS Community Chat

const Dialogs = Target.all('visible modal dialogs').located(by.css('.ui-dialog'));
const DialogTitle = Target.the('dialog title').located(by.css('.ui-dialog-title'));
const DialogWithTitle = (title: string) => 
  Dialogs.where(Text.of(DialogTitle), includes(title)).first();

Serenity/JS 3.0 should support Screenplay-style .where filters for nested page elements.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
viper3400commented, Dec 29, 2021

At the moment we have a common library + 2 project libraries. By now I just migrated the common library which has just some basic tests, but the .where looks good so far. Thanks!

This is just a first feedback, as I’m not sure, when I can try a migration of one of the main projects (and they contain much more code).

1reaction
jan-molakcommented, Dec 26, 2021

This feature will land in 3.0.0-rc.3, with a new implementation of List supporting both the regular Arrays and PageElements.

For example:

        const items = [ 1, 2, 3, 4, 5 ];

        const list = List.of(items);

        const result = await list
            .where(Value, isGreaterThan(2))
            .where(Value, isLessThan(5))
            .answeredBy(actor)
        
        // [ 3, 4 ]

where:

class Value {
    static of<T>(item: T): Question<Promise<T>> {
        return Question.about('some value', actor => Promise.resolve(item));
    }
}

Another API worth mentioning is List.eachMappedTo:

        const accounts: Account[] = [
            { id: 1, name: 'Alice' },
            { id: 2, name: 'Arbnor' },
            { id: 3, name: 'Bob' },
        ];

        const list = List.of(accounts);

        const result = await list
            .where(AccountName, startsWith('A'))
            .eachMappedTo(AccountName)
            .answeredBy(actor);

        // ['Alice', 'Arbnor']

where:

class AccountName {
    static of = (account: Account) =>
        Question.about('account name', actor => account.name)
}

I will also remove filter and map methods from PageElements since they have proven to provide little value without the actor being readily available.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Serenity/JS 3.0 (RC)
To see the new PageElement and PageElements APIs in action, including using advanced element filters and mapping, have a look at the PageElements...
Read more >
Support WebdriverIO · Issue #805 · serenity-js ... - GitHub
linkContainingText is easy to replace by filter queries ( PageElements...where(Text, equals(..)) ). It is a bit of a drastic move, so I'm ...
Read more >
@serenity-js/core | Yarn - Package Manager
Serenity/JS is a framework designed to make acceptance and regression testing of modern full-stack applications faster, more collaborative and easier to ...
Read more >
serenity-js/Contributors - Gitter
@jan-molak , I'm aware that 3.0.0 is still an RC. Though, I wonder if we could have some deprecation warning first for breaking...
Read more >
Serenity-JS Select an Element from a list - Stack Overflow
I have filtered drop down list which list all tasks. When I type letters into the search box I am presented with a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found