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

[Feature]: support passing timedelta objects to functions that take a timeout argument #2600

Open
DetachHead opened this issue Oct 21, 2024 · 0 comments

Comments

@DetachHead
Copy link

DetachHead commented Oct 21, 2024

🚀 Feature Request

it would be nice if playwright allowed you to pass a datetime.timedelta object to functions that take timeouts, as it more clearly describes the unit of time being used.

Example

from datetime import timedelta

page.click("div", timeout=timedelta(minutes=5))

Motivation

preventing mistakes

currently, it's easy to accidentally misuse the timeout argument for example if the user incorrectly assumes it refers to seconds instead of milliseconds:

from time import sleep

time.sleep(5) # waits 5 seconds
page.wait_for_timeout(5) # waits 5 milliseconds

(yes i know you should never use time.sleep with playwright. this example is just to illustrate that there are builtin functions that take seconds instead of milliseconds, which makes it more likely that a user could incorrectly assume that playwright does the same)

improving readability

it can also make code that waits for longer amounts of time look cleaner. currently you're forced to either write the literal number of milliseconds which is often difficult to read, or split it up into factors representing each unit:

page.click("div", timeout=300000)
page.click("div", timeout=5 * 60 * 1000)

both of these are less reradable than using a timedelta:

page.click("div", timeout=timedelta(minutes=5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants