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

Add functions to measure how long an action takes #260

Open
ElSnoMan opened this issue May 9, 2022 · 0 comments
Open

Add functions to measure how long an action takes #260

ElSnoMan opened this issue May 9, 2022 · 0 comments
Labels
beginner Small - requires some line changes and a test or two enhancement New feature or request hacktoberfest-accepted Hacktoberfest!

Comments

@ElSnoMan
Copy link
Owner

ElSnoMan commented May 9, 2022

Should we add performance.mark() and performance.measure() functions to measure an action's performance?

Filip Hric posted an article about doing this with Cypress: https://filiphric.com/testing-frontend-performance-with-cypress
This is different than our WebPerformance metrics or the Chrome DevTools Protocol performance metrics since this is based on an action and the user has the ability to set it.

This is similar to the stopwatch decorator we have (I want to change this decorator too though...), but would be based on the browser's perception instead of the current thread running the test. Is this a good idea? Would this be useful?

Filip's example would look something like this:

def add_to_cart(name: str, quantity: int)
    py.get(f"#{name}").click()
    py.get("#qty").type(quantity)
    py.get("#add-to-cart-btn").click()

def test_action_duration(py: Pylenium):
    py.visit("https://some-ecommerce-website.com")
    py.performance.mark("custom name")
    py.add_to_cart("ball", 2)
    time = py.performance.measure("custom name")
    assert time < 5, "Took longer than 5 seconds to add item to cart"

Or we could use a decorator approach as well

@performance.mark("custom name")
def add_to_cart(name: str, quantity: int):
    ...
@ElSnoMan ElSnoMan added enhancement New feature or request beginner Small - requires some line changes and a test or two labels May 9, 2022
@ElSnoMan ElSnoMan added the hacktoberfest-accepted Hacktoberfest! label Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginner Small - requires some line changes and a test or two enhancement New feature or request hacktoberfest-accepted Hacktoberfest!
Projects
None yet
Development

No branches or pull requests

1 participant