Ejemplo n.º 1
0
def window_slip(driver, element, times=1000):   # other=0.5,
    logs = element['name']
    log.mylog(logs)
    slip_conf = element['slide'].split(",")
    start = float(slip_conf[0].strip())
    end = float(slip_conf[1].strip())
    other = float(slip_conf[2].strip())            # 滑动的中心位置
    n = int(slip_conf[3].strip())
    direction = element['direction']
    wait_time(element)
    t = times                                # 滑动时间
    print(logs, start, end, other, n)
    size = driver.get_window_size()          # 获取屏幕大小,size = {u'width': 720, u'height': 1280}
    if direction == 'vertical':              # 上下滑动
        x1 = size['width'] * other
        y1 = size['height'] * start
        y2 = size['height'] * end
        for i in range(n):
            driver.swipe(x1, y1, x1, y2, t)
    elif direction == 'horizontal':          # 左右滑动
        x1 = size['width'] * start
        x2 = size['width'] * end
        y1 = size['height'] * other
        for i in range(n):
            driver.swipe(x1, y1, x2, y1, t)
Ejemplo n.º 2
0
def wait_activity(driver, element):
    name, value, value1 = find_value(element)
    va = "driver.wait_activity(%s, 13)" % value
    log.mylog(name, va)
    wait_time(element)
    print('等待指定页面出现' + va)
    driver.wait_activity(value, 30)
Ejemplo n.º 3
0
def find_toast(driver, element, timeout=10, poll_frequency=0.05):
    try:
        name, value, value1 = find_value(element)
        toast_loc = ("xpath", ".//*[contains(@text,'%s')]" % value)
        t = WebDriverWait(driver, timeout, poll_frequency).until(er.presence_of_element_located(toast_loc))
        log.mylog(name, toast_loc)
        print(t.text)
    except Exception as e:
        logs = '未检测到toast消息' + str(e)
        log.mylog(logs)
        print(logs)
Ejemplo n.º 4
0
def ids(driver, element):
    name, value, value1 = find_value(element)
    print(name, value, value1)
    wait_time(element)
    if not value1:
        driver.find_element_by_id(value).click()
        va = 'driver.find_element_by_id(%s)' % value
    else:
        driver.find_element_by_id(value).send_keys(value1)
        va = 'driver.find_element_by_id(%s).send_keys(%s)' % (value, value1)
    log.mylog(name, va)
Ejemplo n.º 5
0
def adbs(driver, element, ip):
    name, value, value1 = find_value(element)
    wait_time(element)
    if value1:
        va = 'os.system(%s)' % value
        log.mylog(name, va)
        os.system("adb -s %s shell input text '%s'" % (ip, value))
    else:
        xs, ys = public.coordinate(driver, element)
        va = ('adb -s %s shell input tap' % ip + ' ' + str(xs) + ' ' + str(ys))
        log.mylog(name, va)
        os.system(va)
Ejemplo n.º 6
0
 def run_main(self, conf, case_list):
     path = '../test_file/appiumFile/log/'
     log.logfile()  # 创建log文件
     conf_data, ip, app_package = get_config(conf)
     try:
         driver = start_up.login_app(conf_data)
         for case in case_list:
             num = go_test(case, driver, ip, path)
             if num is None:
                 break
         self.send_email.send_email(log.log_all())
     except Exception as msg:
         log.mylog('Error :  连接设备启动出错!' + str(msg))
         print('连接设备启动出错!', msg)
Ejemplo n.º 7
0
def error_attempt(i, driver, ip):
    for num in range(5):
        time.sleep(3)
        # noinspection PyBroadException
        try:
            log_text = '等待3秒,第%s次尝试!' % (num + 1)
            log.mylog(log_text)
            print(log_text)
            find_run_mode.judge_type(i, driver, ip)
            print('第%s次尝试成功!' % (num + 1))
            return True
        except Exception:
            log_text = '第%s次尝试失败!' % (num + 1)
            log.mylog(log_text)
            print(log_text)
Ejemplo n.º 8
0
def permission(driver):
    va = ''
    for i in range(5):
        loc = ("xpath", "//*[@text='允许']")
        locs = ("xpath", "//*[@text='始终允许']")                    # 关闭权限弹窗的按钮字符
        # noinspection PyBroadException
        try:
            # noinspection PyBroadException
            try:
                e = WebDriverWait(driver, 1, 0.5).until(er.presence_of_element_located(loc))
                e.click()
                logs = str(loc) + '跳过权限窗口'
                log.mylog(logs, va)
            except Exception:
                e = WebDriverWait(driver, 1, 0.5).until(er.presence_of_element_located(locs))
                e.click()
                logs = str(locs) + '跳过权限窗口'
                log.mylog(logs, va)
        except Exception:
            pass
Ejemplo n.º 9
0
def repeat(driver, element):
    name, value, value1 = find_value(element)
    x = element['x']
    for i in range(4):
        va = 'driver.find_elements_by_id(%s)[%s].click(), ' \
             'driver.find_element_by_id(%s)[%s].click()' % (value, i, value1, i)
        log.mylog(name, va)
        time.sleep(1)
        # noinspection PyBroadException
        try:
            # noinspection PyBroadException
            try:
                driver.find_elements_by_id(value)[i].click()
                time.sleep(1)
                driver.find_element_by_xpath("//*[@text='%s']" % x).click()
                break
            except Exception:
                window_slip(driver, element)
                time.sleep(1)
                driver.find_element_by_id(value1).click()
                break
        except Exception:
            driver.back()
Ejemplo n.º 10
0
def window_slip(driver, element, times=500):   # other=0.5,
    va = ''
    logs = element['name']
    log.mylog(logs, va)
    start = float(element['start'])
    end = float(element['end'])
    other = float(element['other'])               # 滑动的中心位置
    n = int(element['n'])                         # 滑动次数
    direction = element['direction']
    wait_time(element)
    t = times                                # 滑动时间
    size = driver.get_window_size()          # 获取屏幕大小,size = {u'width': 720, u'height': 1280}
    if direction == 'vertical':              # 上下滑动
        x1 = size['width'] * other
        y1 = size['height'] * start
        y2 = size['height'] * end
        for i in range(n):
            driver.swipe(x1, y1, x1, y2, t)
    elif direction == 'horizontal':          # 左右滑动
        x1 = size['width'] * start
        x2 = size['width'] * end
        y1 = size['height'] * other
        for i in range(n):
            driver.swipe(x1, y1, x2, y1, t)
Ejemplo n.º 11
0
def element_text(driver, element):
    logs = element['name']
    log.mylog(logs)
    wait_time(element)
    text = element['value1']
    el = driver.find_element_by_id(element['value'])
    if el.text == text:
        log_text = '显示正确,显示为:' + el.text
        print(log_text)
        log.mylog(log_text)
    else:
        log_text = '显示不正确,显示为:' + el.text
        print(log_text)
        log.mylog(log_text)
Ejemplo n.º 12
0
            log_text = '第%s次尝试失败!' % (num + 1)
            log.mylog(log_text)
            print(log_text)


def go_test(case, driver, ip, path):
    case_data = operation_csv.read_csv(case)
    for i in case_data:
        time.sleep(1)
        if i['run'] == 'y':
            try:
                find_run_mode.judge_type(i, driver, ip)
            except Exception as msg:
                public.cut_shot(driver, path, 5)  # 截图
                print(msg)
                log.mylog('Error : ' + i['name'], str(msg))
                num = error_attempt(i, driver, ip)
                if num is None:
                    return None
    return True


class RunTest:
    def __init__(self):
        self.send_email = send_mail.SendEmail()

    def run_main(self, conf, case_list):
        path = '../test_file/appiumFile/log/'
        log.logfile()  # 创建log文件
        conf_data, ip, app_package = get_config(conf)
        try:
Ejemplo n.º 13
0
def tab(element, ip):
    name, value, value1 = find_value(element)
    va = 'adb -s %s shell input keyevent %s' % (ip, value)
    log.mylog(name, va)
    wait_time(element)                          # 判断执行元素是否需要添加延时
    os.system(va)
Ejemplo n.º 14
0
def tap_type(driver, element):
    name, value, value1 = find_value(element)
    va = 'driver.tap(%s)' % value
    log.mylog(name, va)
    wait_time(element)                          # 判断执行元素是否需要添加延时
    driver.tap(value)
Ejemplo n.º 15
0
def xpath_type(driver, element):
    name, value, value1 = find_value(element)
    va = 'driver.find_element_by_xpath(%s).click(%s)' % (value, value1)
    log.mylog(name, va)
    wait_time(element)                          # 判断执行元素是否需要添加延时
    driver.find_element_by_xpath(value).click()