How to use last_screenshot method in ATX

Best Python code snippet using ATX Github


Full Screen

1import pytest2import allure3from _pytest.nodes import Item4from _pytest.runner import CallInfo5from import browser6import project7import web_test.helpers.allure.gherkin8def pytest_addoption(parser):9 project.Config.register(parser)10@pytest.fixture11def config(request):12 if not project.config:13 project.config = project.Config(request)14 return project.config15@pytest.fixture(scope='function', autouse=True)16def browser_management(config):17 """18 Here, before yield,19 goes all "setup" code for each test case20 aka "before test function" hook21 """22 # def attach_snapshots_on_failure(error: TimeoutException) -> Exception:23 # """24 # An example of selene hook_wait_failure that attaches snapshots to failed test step.25 # It is actually not needed and optional,26 # because in the pytest_runtest_makereport hook below27 # we attach screenshots to the test body itself,28 # that is more handy during analysis of test report29 #30 # but if you need it, you can enable it by uncommenting31 # together with the following ``browser.config.hook_wait_failure =`` line;)32 #33 # otherwise, you can remove it34 # """35 # last_screenshot = browser.config.last_screenshot36 # if last_screenshot:37 # allure.attach.file(source=last_screenshot,38 # name='screenshot on failure',39 # attachment_type=allure.attachment_type.PNG)40 #41 # last_page_source = browser.config.last_page_source42 # if last_page_source:43 # allure.attach.file(source=last_page_source,44 # name='page source on failure',45 # attachment_type=allure.attachment_type.HTML)46 # return error47 # browser.config.hook_wait_failure = attach_snapshots_on_failure48 browser.config.timeout = config.timeout49 browser.config.save_page_source_on_failure \50 = config.save_page_source_on_failure51 # todo: add your before setup here...52 yield53 """54 Here, after yield,55 goes all "tear down" code for each test case56 aka "after test function" hook57 """58 # todo: add your after setup here...59 browser.quit()60prev_test_screenshot = None61prev_test_page_source = None62@pytest.hookimpl(tryfirst=True, hookwrapper=True)63def pytest_runtest_setup(item):64 yield65 global prev_test_screenshot66 prev_test_screenshot = browser.config.last_screenshot67 global prev_test_page_source68 prev_test_page_source = browser.config.last_page_source69@pytest.hookimpl(tryfirst=True, hookwrapper=True)70def pytest_runtest_makereport(item: Item, call: CallInfo):71 """72 Attach snapshots on test failure73 """74 # All code prior to yield statement would be ran prior75 # to any other of the same fixtures defined76 outcome = yield # Run all other pytest_runtest_makereport non wrapped hooks77 result = outcome.get_result()78 if web_test.helpers.allure.gherkin.when == 'call' and result.failed:79 last_screenshot = browser.config.last_screenshot80 if last_screenshot and not last_screenshot == prev_test_screenshot:81 allure.attach.file(source=last_screenshot,82 name='screenshot',83 attachment_type=allure.attachment_type.PNG)84 last_page_source = browser.config.last_page_source85 if last_page_source and not last_page_source == prev_test_page_source:86 allure.attach.file(source=last_page_source,87 name='page source',...

Full Screen

Full Screen Github


Full Screen

1import typer2from pathlib import Path3from datetime import datetime, timedelta4app = typer.Typer(add_completion=False)5def pretty_delta(delta: timedelta):6 if delta.seconds < 0:7 return "in the future"8 elif delta.seconds < 120:9 return f"{delta.seconds} seconds ago"10 elif delta.seconds < 60 * 120:11 return f"{delta.seconds // 60} minutes ago"12 else:13 return f"{delta.seconds // (60 * 60)} hours ago"14@app.command()15def main(16 destination: Path,17 markdown: bool = typer.Option(18 False,19 "-m",20 help="Print markdown to use image",21 ),22):23 pictures_path = Path.home() / "Pictures"24 screenshots = list(pictures_path.glob("Screenshot from *.png"))25 screenshots.sort()26 last_screenshot = screenshots[-1]27 last_date = datetime.strptime(28, "Screenshot from %Y-%m-%d %H-%M-%S.png"29 )30 now = delta = now - last_date32 delta_text = pretty_delta(delta)33 if destination.suffix != last_screenshot.suffix:34 destination = destination.with_suffix(last_screenshot.suffix)35 print(f"Screenshot from {delta_text}")36 print(f"Move to: {destination}")37 confirm = input("Confirm [Y/n]: ")38 if confirm.lower() in {"y", "yes", ""}:39 last_screenshot.rename(destination)40 if markdown:41 if "docs" in docs_index ="docs")43 docs_path = Path(*[: docs_index + 1])44 relative_path = destination.relative_to(docs_path)45 else:46 relative_path = destination47 print("=" * 10)48 print(f'![Screenshot](/{relative_path} "Screenshot")')49if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ATX automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?