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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Add cancellation token support #2934

Closed
markboyall opened this issue May 10, 2024 · 1 comment
Closed

[Feature]: Add cancellation token support #2934

markboyall opened this issue May 10, 2024 · 1 comment

Comments

@markboyall
Copy link

markboyall commented May 10, 2024

馃殌 Feature Request

Add CancellationToken options to page interactions, like ClickAsync.

Example

Create a CancellationTokenSource, try several actions, and cancel whichever of them is no longer needed.

           var cts = new CancellationTokenSource();
            await RunAndWaitForResponseAsync(async () =>
            {
                await page.RunAndWaitForRequestAsync(() => fileChooser.SetFilesAsync(fileName), "**/WebForms/ImportTemplate.aspx");
                FrameContents.Locator("div.popup").Locator("button:text(\"yes\")").ClickAsync(cts.Token);
            }, "**/Request.aspx");
            cts.Cancel();

Motivation

We have some actions in our application which can result in a few different responses. The Or locator seems to be intended to handle these, but not every possible response can be expressed as a locator. In this example, either a network request is sent, or, a popup is displayed which the user has to click on, then the network request is sent. There doesn't seem to be a great way to handle these actions at the moment.

The only obvious solution is to try to click on the popup button and ignore the timeout exception, but this makes the test pretty slow. Currently we are simply fire-and-forgetting the click on the popup whilst unconditionally waiting on the network request, but this could trigger later on if the popup shows again for other reasons, when it should be cancelled immediately if we observe the request. Maybe there should be some dedicated feature for various responses, but it seems more flexible to simply allow the user to cancel attempted interactions.

It may be useful in other situations where the test writer wants one of several different actions to succeed but these are not simple "one interaction on one of these locators" actions. We have a kinda similar situation where an expandable element may or may not be expanded, so we want to wait for the expanded content, or, click the button to expand. The Or locator can't quite accommodate this since we're looking for two different interactions on the different options.

@yury-s yury-s transferred this issue from microsoft/playwright May 10, 2024
@mxschmitt
Copy link
Member

Folding into #1652.

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