Ejemplo n.º 1
0
def select_throttling(option):
    network_pattern = Pattern("network.png").similar(0.6)
    throttling_menu_pattern = Pattern("no_throttling.png").similar(0.6)
    region_ll = Screen.LOWER_LEFT_CORNER
    region_lr = Region.screen_regions(Screen.LOWER_RIGHT_CORNER, "RIGHT_THIRD")

    open_web_console()

    try:
        region_ll.wait(network_pattern, 30)
        region_ll.click(network_pattern)
    except FindError:
        raise APIHelperError(
            "Can't find the network menu in the page, aborting test.")

    try:
        region_lr.wait(throttling_menu_pattern, 10)
        region_lr.click(throttling_menu_pattern)
    except FindError:
        raise APIHelperError(
            "Can't find the throttling menu in the page, aborting test.")

    for i in range(option + 1):
        type(Key.DOWN)
    type(Key.ENTER)
Ejemplo n.º 2
0
class Screen(Region):
    """Class Screen is the representation for a physical monitor where the capturing process (grabbing a rectangle
    from a screenshot). It is used for further processing with find operations. For Multi Monitor Environments it
    contains features to map to the relevant monitor.
    """

    def __init__(self, screen_id: int = 0):
        self.screen_id = screen_id
        self.screen_list = DisplayCollection[screen_id]
        self._bounds = DisplayCollection[screen_id].bounds
        Region.__init__(
            self,
            self._bounds.x,
            self._bounds.y,
            self._bounds.width,
            self._bounds.height,
        )

    SCREEN_WIDTH, SCREEN_HEIGHT = pyautogui.size()
    screen_region = Region(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)

    TOP_HALF = Region.screen_regions(screen_region, "TOP_HALF")
    BOTTOM_HALF = Region.screen_regions(screen_region, "BOTTOM_HALF")

    LEFT_HALF = Region.screen_regions(screen_region, "LEFT_HALF")
    RIGHT_HALF = Region.screen_regions(screen_region, "RIGHT_HALF")

    TOP_THIRD = Region.screen_regions(screen_region, "TOP_THIRD")
    MIDDLE_THIRD_HORIZONTAL = Region.screen_regions(
        screen_region, "MIDDLE_THIRD_HORIZONTAL"
    )
    BOTTOM_THIRD = Region.screen_regions(screen_region, "BOTTOM_THIRD")

    LEFT_THIRD = Region.screen_regions(screen_region, "LEFT_THIRD")
    MIDDLE_THIRD_VERTICAL = Region.screen_regions(
        screen_region, "MIDDLE_THIRD_VERTICAL"
    )
    RIGHT_THIRD = Region.screen_regions(screen_region, "RIGHT_THIRD")

    UPPER_LEFT_CORNER = Region.screen_regions(screen_region, "UPPER_LEFT_CORNER")
    UPPER_RIGHT_CORNER = Region.screen_regions(screen_region, "UPPER_RIGHT_CORNER")
    LOWER_LEFT_CORNER = Region.screen_regions(screen_region, "LOWER_LEFT_CORNER")
    LOWER_RIGHT_CORNER = Region.screen_regions(screen_region, "LOWER_RIGHT_CORNER")

    def __repr__(self):
        return "%s(x: %r, y: %r, size: %r x %r)" % (
            self.__class__.__name__,
            self._bounds.x,
            self.y,
            self._bounds.width,
            self._bounds.height,
        )

    def get_number_screens(self) -> int:
        """Get the number of screens in a multi-monitor environment at the time the script is running."""
        return len(self.screen_list)

    def get_bounds(self) -> Rectangle:
        """Get the dimensions of monitor represented by the screen object."""
        return self._bounds