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

Store the video of the tests if the path is defined #3

Open
moylop260 opened this issue Aug 18, 2023 · 1 comment
Open

Store the video of the tests if the path is defined #3

moylop260 opened this issue Aug 18, 2023 · 1 comment

Comments

@moylop260
Copy link
Contributor

moylop260 commented Aug 18, 2023

Odoo has the following configuration parameter:

~/odoo/odoo/odoo-bin --help |grep screen
--screencasts=DIR Screencasts will go in DIR/{db_name}/screencasts.
--screenshots=DIR Screenshots will go in DIR/{db_name}/screenshots.

If the parameter screencasts is defined so selenium should enable to record a video and stored in the path

IMHO we could get something similar with screenshots but not sure if it could be auto-enabled after each step but we can discuss from another MR/issue

NOTE: Old POC https://git.islamicreliefcanada.ca/ircodoo-dev/ircanada/-/merge_requests/329/diffs

@antonag32
Copy link
Contributor

I propose a decorator, can look like this:

def screenshot_if_fail(func):
    def wrapper(self):
        try:
            func(self)
        except WebDriverException as ex:
            path = Path(environ.get("SELENIUM_SCREENSHOTS", "/home/odoo")) / f"{func.__name__}-{int(time())}.png"
            _logger.info("Saving screenshot for failed test: %s", path)
            self.driver.get_screenshot_as_file(path)
            raise ex

    return wrapper

And can be used as:

@screenshot_if_fail
def test_something(self):
    ...

This would work just for taking a screenshot when tests fails which is already very useful, to make something like a video the decorator would probably need to run concurrently and periodically take screenshots, if WebDriver supports multi-threading, it may work.

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