Example #1
0
def swipe_coordinate(from_x: int,
                     from_y: int,
                     to_x: int,
                     to_y: int,
                     speed: int = 500):
    LOGGER.debug(f"==> Swipe coordiates {from_x, from_y, to_x, to_y, speed}")
    get_driver().swipe(from_x, from_y, to_x, to_y, speed)
Example #2
0
def set_network(mode: int):
    """Sets the network connection type. Android only.
    0 // airplane mode off, wifi off, data off
    1 // airplane mode on, wifi off, data off
    2 // airplane mode off, wifi on, data off
    4 // airplane mode off, wifi off, data on
    6 // airplane mode off, wifi on, data on
    """
    LOGGER.info(f"==> Set network mode: {mode}")
    get_driver().set_network_connection(mode)
Example #3
0
    def _search_element(self) -> list:
        if not self.context:
            # if instance has no driver, fill it with current driver
            self.context = get_driver()

        results = self.context.find_elements(*self.selector)
        self.found = len(results)
        return results
Example #4
0
def find_text(text: str, inside_selector: tuple = None, raise_error=True):
    # when something is a text
    LOGGER.info(f'==> Finding text: "{text}"')
    selector = {
        "android": f"//*[@text='{text}']",
        "ios": f"//*[@label='{text}' and @visible='true']",
    }.get(configs.PLATFORM)
    context = (get_driver() if not inside_selector else
               get_driver().find_element(inside_selector))
    elements = context.find_elements(by=By.XPATH, value=selector)
    if len(elements) > 0:
        return elements[0]
    else:
        if raise_error:
            raise NoSuchElementException(
                f'Element by text "{text}" is not found')
        else:
            return False
Example #5
0
def eyes(request):
    eyes = Eyes()
    if os.environ.get("APPLITOOLS_API_KEY") is not None:
        eyes.api_key = os.getenv("APPLITOOLS_API_KEY")
        eyes.open(get_driver(),
                  app_name=configs.APP_NAME,
                  test_name=request.node.name)
    yield eyes
    eyes.abort()
Example #6
0
    def _search_element(self) -> MobileElementPatch:
        if not self.context:
            # if instance has no driver, fill it with current driver
            self.context = get_driver()

        if not self.waiter:
            self.waiter = WebDriverWait(self.context, self.wait_time)
        el = self.waiter.until(EC.presence_of_element_located(self.selector))
        el.__class__ = MobileElementPatch
        return el
Example #7
0
def swipe(direction: str, speed: str = "FAST"):
    # Perform scrolling screen, using 80:20 of the screen size
    # direction (DOWN | UP | LEFT | RIGHT)
    # start from Opposite Direction, e.g swipe UP = start from down screen to up screen
    LOGGER.info(f"==> Swiping {direction} {speed}LY")
    assert direction in ["DOWN", "UP", "LEFT", "RIGHT"]
    assert speed in ["FAST", "MEDIUM", "SLOW"]
    duration = {"FAST": 500, "MEDIUM": 1000, "SLOW": 2000}.get(speed)
    screen_size = get_driver().get_window_size()
    width, height = int(screen_size["width"]), int(screen_size["height"])
    from_x, to_x, from_y, to_y = 0, 0, 0, 0
    if direction == "UP":
        from_x = int(width * 0.5)  # center at screen 50%
        to_x = from_x
        from_y = int(height * 0.8)  # start 80% screen
        to_y = int(height * 0.2)  # end 20% screen
    elif direction == "DOWN":
        from_x = int(width * 0.5)  # center at screen 50%
        to_x = from_x
        from_y = int(height * 0.2)  # start 20% screen
        to_y = int(height * 0.8)  # end 80% screen

    # get_driver().swipe(from_x, from_y, to_x, to_y, duration)
    swipe_coordinate(from_x, from_y, to_x, to_y, duration)
Example #8
0
def go_back():
    LOGGER.info("==> Going back")
    get_driver().back()
Example #9
0
def start_activity(app_package: str, app_activity: str):
    """Start an Android activity by providing package name and activity name"""
    LOGGER.info(f"==> Start activity {app_package}-{app_activity}")
    get_driver().start_activity(app_package, app_activity)
Example #10
0
def shake_device():
    """Perform a shake action on the device"""
    LOGGER.info("==> Shake device")
    get_driver().shake()
Example #11
0
def set_orientation(orientation: str):
    # orientation ("LANDSCAPE" | "PORTRAIT")
    assert orientation in ["LANDSCAPE", "PORTRAIT"]
    get_driver().orientation = orientation
Example #12
0
def open_notification():
    """ Open Android notifications (Emulator only)"""
    LOGGER.info("==> Opening Notification")
    if configs.IS_ANDROID:
        get_driver().open_notifications()
Example #13
0
 def __init__(self):
     self.driver = get_driver()
Example #14
0
def driver():
    driver = get_driver()
    driver.implicitly_wait(10)
    yield driver
    quit_driver()