def swipe(cls, dire: str, duration=None, num: int = 1):
        """
        封装原生 swipe 方法,指定滑动方向和位置
        :param dire: only `up` `down` `left` `right`
        :param duration: (optional) time to take the swipe, in ms.
        :param num: should bigger than 1
        :return:
        """
        x = cls.get_size()[0] / 2
        y = cls.get_size()[1] / 2
        if dire == 'up' or dire == 'down':
            y0 = cls.get_size()[1] / 10 * 6
            y1 = cls.get_size()[1] / 10 * 4
            if dire == 'down':
                y0, y1 = y1, y0
            for _ in range(num):
                BaseDriver.get_driver().swipe(x, y0, x, y1, duration)

        elif dire == 'left' or dire == 'right':
            x0 = cls.get_size()[0] / 4 * 3
            x1 = cls.get_size()[0] / 4 * 1
            if dire == 'right':
                x0, x1 = x1, x0
            for _ in range(num):
                BaseDriver.get_driver().swipe(x0, y, x1, y, duration)
        else:
            logger.error('滑动方向错误')
Beispiel #2
0
class Element:
    def __init__(self, sec: str):
        self.read_data = ReadConf()
        self.sec = sec
        self.driver = BaseDriver(ST.DEVICENAME, ST.PORT, ST.APP_PATH).driver

    def get_element(self, key: str) -> WebElement:
        data = self.read_data.get_value(self.sec, key)
        if data is not None:
            by, expr = data.split('|')
            by, expr = by.strip(), expr.strip()
            if by == 'id':
                return self.driver.find_element_by_id(expr)
            elif by == 'ac_id':
                return self.driver.find_element_by_accessibility_id(expr)
            else:
                return self.driver.find_element_by_xpath(expr)
Beispiel #3
0
def pytest_runtest_makereport(item, call):
    _driver = BaseDriver.get_driver()
    outcome = yield
    resp = outcome.get_result()
    if resp.when == 'call' and resp.failed:
        f = _driver.get_screenshot_as_png()
        allure.attach(f, '错误截图', allure.attachment_type.PNG)
        logcat = _driver.get_log('logcat')
        c = '\n'.join([i['message'] for i in logcat])
        allure.attach(c, '错误日志', allure.attachment_type.TEXT)
 def setUpClass(cls):
     driver_conf = HandleDriverConf()
     ST.DEVICENAME = driver_conf.get_value(f'user_info_{cls.ORDER}',
                                           'deviceName')
     ST.PORT = driver_conf.get_value(f'user_info_{cls.ORDER}', 'port')
     ST.APP_PATH = f'{root_path}/app/com.codemao.dan_2.0.1_11.apk'
     cls.driver = BaseDriver(ST.DEVICENAME, ST.PORT, ST.APP_PATH).driver
     cls.guide = Guide()
     cls.tab = TabBar()
     cls.user = User()
Beispiel #5
0
 def __init__(self, sec: str):
     self.read_data = ReadConf()
     self.sec = sec
     self.driver = BaseDriver(ST.DEVICENAME, ST.PORT, ST.APP_PATH).driver
Beispiel #6
0
def init_test():
    BaseDriver.init_driver(port=ST.PORT, udid=ST.UDID)
    yield init_test
    BaseDriver.quit_driver()
 def over_app(cls):
     BaseDriver.get_driver().quit_driver()
 def get_size(cls) -> tuple:
     """
     获取当前屏幕尺寸
     """
     size = BaseDriver.get_driver().get_window_size()
     return size['width'], size['height']
 def go_back(cls):
     BaseDriver.get_driver().back()
 def find_by_xml(cls, xpath):
     page_source = BaseDriver.get_driver().page_source
     xml = etree.XML(str(page_source).encode('utf-8'))
     return xml.xpath(xpath)
 def find_all(cls, locator) -> list:
     return BaseDriver.get_driver().find_elements(*locator)
 def _find_by(cls, by=MB.ID, value=None) -> WebElement:
     try:
         return BaseDriver.get_driver().find_element(by=by, value=value)
     except NoSuchElementException:
         logger.critical(f'元素未找到!\nby -> {by}\nexpression -> {value}')
 def set_implicitly_wait(cls, time_to_wait):
     BaseDriver.get_driver().implicitly_wait(time_to_wait)