Warning
This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.
Source code for galaxy.selenium.scripts.dump_tour
#!/usr/bin/env python
import argparse
import datetime
import os
import sys
import time
from contextlib import nullcontext
from typing import Any
from galaxy.selenium import cli
from galaxy.selenium.navigates_galaxy import TourCallbackProtocol
from galaxy.selenium.web_element_protocol import WebElementProtocol
DESCRIPTION = "Walk a Galaxy tour and dump screenshots."
[docs]
def main(argv: list[str] | None = None) -> None:
if argv is None:
argv = sys.argv[1:]
args = _arg_parser().parse_args(argv)
driver_wrapper = cli.DriverWrapper(args)
output = args.output
assert output is not None
output = output.replace("TIMESTAMP", datetime.datetime.now().strftime("%Y%m%d%H%M%s"))
if os.path.exists(output):
raise Exception("Output directory %s exists, skipping")
else:
os.makedirs(output)
callback = DumpTourCallback(driver_wrapper, output)
driver_wrapper.run_tour(args.tour, tour_callback=callback)
[docs]
class DumpTourCallback(TourCallbackProtocol):
driver_wrapper: cli.DriverWrapper
[docs]
def __init__(self, driver_wrapper: cli.DriverWrapper, output: str) -> None:
self.driver_wrapper = driver_wrapper
self.output = output
[docs]
def handle_step(self, step: dict[str, Any], step_index: int, element: WebElementProtocol | None = None) -> None:
time.sleep(0.5)
# Border the element the step is about, so the dump reads as documentation
# rather than a sequence of indistinguishable full-page screenshots.
highlight = self.driver_wrapper.highlight_element(element) if element is not None else nullcontext()
with highlight:
self.driver_wrapper.save_screenshot(f"{self.output}/{step_index}.png")
time.sleep(0.5)
def _arg_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.add_argument("tour", metavar="TOUR", help="tour to walk")
parser.add_argument("-o", "--output", default="tour_dump_TIMESTAMP", help="directory to dump tour to")
parser = cli.add_selenium_arguments(parser)
return parser
if __name__ == "__main__":
main()