Main functions and classes

pyGATs is python3 library which combines power of pyautogui, opencv, tesseract, markdown and other staff to automate end-to-end and exploratory testing.

class pygats.pygats.Context(formatter, timeout=0)[source]

Context stores information about

exception pygats.pygats.TestException(msg)[source]

Test exception class stores msg when error occurs

pygats.pygats.alt_with_key(ctx: Context, key: str)[source]

function presses alt+key

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • key (str) – key to press ALT + key

pygats.pygats.check(ctx: Context, msg: str, func=None)[source]

Prints message as check block

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • msg (str) – message to print at the beginning of test case

  • func – pointer to function to be printed and called

  • noqa (during test #) – DAR003

Returns:

func() result or None

Return type:

type or None

pygats.pygats.check_image(ctx: Context, img_path: str, timeout: int | None = 1)[source]

Check if image is located on screen. Timeout in second waiting image to occurs

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • img_path (str) – path to image for check on screen

  • timeout (Optional[int]) – timeout in seconds to check if image occurs

pygats.pygats.click(ctx: Context, button_path: str, area: str | None = '')[source]

function clicks button in area

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • button_path (str) – path to button image to press

  • area (Optional[str]) – path to area of image to print

pygats.pygats.click_left_button(ctx: Context, clicks: int | None = 1)[source]

function clicks left button of mouse

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • clicks (Optional[int]) – number of clicks

pygats.pygats.click_right_button(ctx: Context)[source]

function clicks right mouse button

Parameters:

ctx (Context) – An object that contains information about the current context.

pygats.pygats.compare_snapshots(ctx: Context, first_img: str, second_img: str) tuple[source]

Function for comparing two images

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • first_img (str) – path to first snapshot for compare

  • second_img (str) – path to second snapshot for compare

Returns:

coordinates of the change detection area

Return type:

tupple or None

pygats.pygats.create_stm(ctx: Context, funcs: List[str])[source]

Print а software test methodology based on docstring functions.

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • funcs (List[str])

  • noqa (#) – DAR003

pygats.pygats.ctrl_with_key(ctx: Context, key: str)[source]

function presses key with ctrl key

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • key (str) – key to press CTRL + key

pygats.pygats.docstring_handler(func)[source]

Addition and modification of the docstring in case of missing elements

Parameters:

func (function) – Function for getting a docstring

Returns:

docstring of function

Return type:

dict

pygats.pygats.drag_to(ctx: Context, x: int, y: int)[source]

drag something to coordinates x, y

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • x (int) – coordinates to move mouse pointer

  • y (int) – coordinates to move mouse pointer

pygats.pygats.draw_contours(img: <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/pygats/envs/latest/lib/python3.10/site-packages/PIL/Image.py'>, cnts: ~typing.List[~numpy.ndarray]) <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/pygats/envs/latest/lib/python3.10/site-packages/PIL/Image.py'>[source]

Draw contours on a PIL.Image instance.

Parameters:
  • img (Image) – Input image on which to draw the contours.

  • cnts (List[np.ndarray]) – List of contours, represented

  • noqa (as Numpy arrays. #) – DAR003

Returns:

Output image with contours drawn.

Return type:

Image

Raises:
  • TypeError – If img is not a PIL.Image instance.

  • ValueError – If cnts is not a list of Numpy arrays.

pygats.pygats.failed(msg: str | None = 'Тест не успешен')[source]

function generates exception while error occurs

Parameters:

msg (Optional[str]) – failed text

Raises:

TestException – raise exception in case of test failed

pygats.pygats.filter_rect_sorted(cnts: List[ndarray]) List[ndarray][source]

Filter and sort contours to get rectangles

Parameters:

cnts (List[np.ndarray]) – list of contours

Returns:

list of filtered and sorted rectangles

Return type:

List[np.ndarray]

pygats.pygats.find_contours(ctx: ~pygats.pygats.Context, img_path: str, fltr=<function repeater>)[source]

Function finds contours by cv and filter them with filter

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • img_path (str) – path to image where contours will be searched

  • fltr (function, optional) – filter which will be used on contours

  • noqa (results #) – DAR003

Returns:

list of points filtered

Return type:

list of points

pygats.pygats.locate_on_screen(ctx: Context, img_path: str)[source]

Function return coord of path to image located on screen. If not found returns None

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • img_path (str) – path to image to find

Returns:

coordinates path for image on screen

Return type:

(x,y)

pygats.pygats.log_image(ctx: ~pygats.pygats.Context, img: <module 'PIL.Image' from '/home/docs/checkouts/readthedocs.org/user_builds/pygats/envs/latest/lib/python3.10/site-packages/PIL/Image.py'>, msg: str | None = 'Снимок экрана')[source]

Function log img with msg into report image is stored in output path as screenshotIndex

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • img (Image) – image to be logged

  • msg (str, optional) – description of the screenshot.

  • noqa (Defaults to 'Снимок экрана'. #) – DAR003

Returns:

input image

Return type:

PIL.Image

pygats.pygats.move(ctx: Context, x: int, y: int)[source]

function moves mouse pointer to x,y coordinates

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • x (int) – coordinates to move mouse pointer

  • y (int) – coordinates to move mouse pointer

pygats.pygats.move_to(ctx: Context, img_path: str)[source]

Function move mouse to img_path

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • img_path (str) – path to image for move to

pygats.pygats.move_to_coord(ctx: Context, x: int, y: int)[source]

Function moves mouse to coord x,y

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • x (int) – x coordinate

  • y (int) – y coordinate

pygats.pygats.passed(ctx: Context)[source]

function prints passed information after test case

Parameters:

ctx (Context) – An object that contains information about the current context.

pygats.pygats.press(ctx: Context, key: str, n: int | None = 1)[source]

Function press keys n times

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • key (str) – key to press

  • n (Optional[int]) – amount of time to press

pygats.pygats.print_test_summary(ctx: Context, list_passed: List, list_failed: List)[source]

Functions print tests summary for executed suites

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • list_passed (List) – list of test passed

  • list_failed (List) – list of test failed

pygats.pygats.random_string(string_length: int, character_set: str | None = None)[source]

Generate a randomized string of characters.

Parameters:
  • string_length (int) – The length of the generated string.

  • character_set (Optional[str]) – A string of characters to use

  • noqa (digits and the underscore. #) – DAR003

  • letters (ascii) – DAR003

  • noqa – DAR003

Returns:

A string of the specified length, consisting of characters from

the character set.

Return type:

str

Raises:

ValueError – If string_length is not a positive integer.

Examples

>>> random_string(5)
'W3t9_'
>>> random_string(5, character_set='01')
'10101'
>>> random_string(5, character_set='')
'yzbVG'
pygats.pygats.repeater(cnts: List)[source]

This function is default selector for contours

Parameters:

cnts (List) – list of points to be filtered

Returns:

unchanged list of points

Return type:

list

pygats.pygats.run(ctx: Context, funcs: List[str], counter: int | None = 1, output: str | None = 'output', screenshots_on: bool | None = True)[source]

Execute test suite (list of test cases) one by one.

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • funcs (List[str])

  • counter (Optional[int]) – amount to time test cases to be executed

  • output (Optional[str]) – path to store test results

  • screenshots_on (Optional[bool]) – create screenshots while running tests

  • noqa (#) – DAR003

pygats.pygats.run_action(ctx: Context, action=None, **kwargs)[source]

The function that determines start of the action

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • action (function) – Function that performs the necessary steps

pygats.pygats.screenshot(ctx: Context, rect: tuple | None = None)[source]

Takes a screenshot, optionally limited to the rectangle defined by rect.

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • rect (Optional[tuple]) – A tuple of four integers that defines the area of the screenshot to capture. x (int): x coordinate y (int): y coordinate width (int): width of rect height (int): height of rect

Returns:

The screenshot as a PIL.Image object.

Return type:

PIL.Image

Notes

The screenshot is also stored in the output path as screenshotIndex.

pygats.pygats.scroll(ctx: Context, clicks: int | None = 1)[source]

mouse wheel scroll function

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • clicks (Optional[int]) – number of turns of mouse wheel, if it’s positive scroll to up, if it’s negative to down

pygats.pygats.step(ctx: Context, msg: str)[source]

function prints step name and starts new screenshot index

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • msg (str) – message to print

pygats.pygats.suite(ctx: Context, module)[source]

function prints test suite name in reports

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • module (inspect.module) – module with tests

pygats.pygats.take_snapshot(ctx: Context) str[source]

Function takes a snapshot to further detect changes on the screen

Parameters:

ctx (Context) – An object that contains information about the current context.

Returns:

path to snapshot

Return type:

img_path (PosixPath)

pygats.pygats.typewrite(ctx: Context, message: str, lang: str | None = 'eng')[source]

function types keys on keyboard

Parameters:
  • ctx (Context) – An object that contains information about the current context.

  • message (str) – text to typewrite

  • lang (Optional[str]) – language in tesseract format