示例#1
0
def click(step):
    element = step['element']
    if isinstance(element, str):
        #element_location = locating_element(element, 'CLICK')
        element_location = locating_element(element)
        element_location.click()
    elif isinstance(element, list):
        for _e in element:
            #element_location = locating_element(_e, 'CLICK')
            element_location = locating_element(_e)
            element_location.click()
            sleep(0.5)
    sleep(0.5)

    # 获取元素其他属性
    output = step['output']
    for key in output:
        if output[key] == 'text':
            g.var[key] = element_location.text
        elif output[key] == 'tag_name':
            g.var[key] = element_location.tag_name
        elif output[key] in ('text…', 'text...'):
            if element_location.text.endswith('...'):
                g.var[key] = element_location.text[:-3]
            else:
                g.var[key] = element_location.text
        else:
            g.var[key] = element_location.get_attribute(output[key])
示例#2
0
def drag_and_drop(step):
    element = step['element']
    assert isinstance(
        element,
        list) and len(element) == 2, '元素格式或数量不对,正确格式如:origin_el|destination_el'
    origin = locating_element(element[0])
    destination = locating_element(element[1])
    g.driver.drag_and_drop(origin, destination)
示例#3
0
文件: web.py 项目: StaceyCxh/sweetest
def drag_and_drop(step):
    actions = ActionChains(g.driver)
    element = step['element']
    source = locating_element(element[0])
    target = locating_element(element[1])
    actions.drag_and_drop(source, target)
    actions.perform()
    sleep(0.5)

    # 获取元素其他属性
    get_Ouput(step, el)
示例#4
0
def tab_name(step):
    element = step['element']
    name = step['data']['text']
    # 从所有窗口中查找给定元素,如果查询到就命名,否则报错
    all_handles = g.driver.window_handles
    logger.info('All Handles: %s' % all_handles)

    flag = False
    for handle in all_handles:
        #logger.info('Page Source: %s \n%s' % (handle, g.driver.page_source))
        #logger.info('All Windows: %s' %w.windows)
        if handle not in w.windows.values():
            # 切换至此窗口
            g.driver.switch_to_window(handle)
            try:
                # 成功定位到关键元素
                element_location = locating_element(element, 'CLICK')
                # 添加到窗口资源池 g.windows
                w.windows[name] = handle
                # 把当前窗口名字改为新窗口名称
                w.current_window = name
                flag = True
                logger.info('Current Window: %s' % repr(name))
                logger.info('Current Handle: %s' % repr(handle))
            except Exception as exception:
                pass
    if not flag:
        raise Exception(
            'Tab Name Fail: the element:%s in all tab is not found' % element)
示例#5
0
def line_unlock(step):
    element = step['element']
    duration = float(step['data'].get('持续时间', 0.3))
    assert isinstance(
        element,
        list) and len(element) > 2, '坐标格式或数量不对,正确格式如:lock_pattern|1|4|7|8|9'
    _e = locating_element(element[0])
    rect = _e.rect
    w = rect['width'] / 6
    h = rect['height'] / 6

    key = {}
    key['1'] = (rect['x'] + 1 * w, rect['y'] + 1 * h)
    key['2'] = (rect['x'] + 3 * w, rect['y'] + 1 * h)
    key['3'] = (rect['x'] + 5 * w, rect['y'] + 1 * h)
    key['4'] = (rect['x'] + 1 * w, rect['y'] + 3 * h)
    key['5'] = (rect['x'] + 3 * w, rect['y'] + 3 * h)
    key['6'] = (rect['x'] + 5 * w, rect['y'] + 3 * h)
    key['7'] = (rect['x'] + 1 * w, rect['y'] + 5 * h)
    key['8'] = (rect['x'] + 3 * w, rect['y'] + 5 * h)
    key['9'] = (rect['x'] + 5 * w, rect['y'] + 5 * h)

    action = TouchAction(g.driver)
    for i in range(1, len(element)):
        k = element[i]
        if i == 1:
            action = action.press(x=key[k][0],
                                  y=key[k][1]).wait(duration * 1000)
        action.move_to(x=key[k][0], y=key[k][1]).wait(duration * 1000)
    action.release().perform()
示例#6
0
文件: web.py 项目: StaceyCxh/sweetest
def context_click(step):
    actions = ActionChains(g.driver)
    element = step['element']
    el = locating_element(element)
    actions.context_click(el)
    actions.perform()
    sleep(0.5)

    # 获取元素其他属性
    get_Ouput(step, el)
示例#7
0
文件: web.py 项目: StaceyCxh/sweetest
def notcheck(step):
    data = step['data']
    if not data:
        data = step['expected']

    element = step['element']
    element_location = locating_element(element)

    if g.elements[element]['by'] == 'title':
        assert data['text'] != g.driver.title
示例#8
0
文件: web.py 项目: StaceyCxh/sweetest
def move(step):
    actions = ActionChains(g.driver)
    element = step['element']
    el = locating_element(element)

    actions.move_to_element(el)
    actions.perform()
    sleep(0.5)

    # 获取元素其他属性
    get_Ouput(step, el)
示例#9
0
文件: web.py 项目: StaceyCxh/sweetest
def click(step):
    element = step['element']
    if isinstance(element, str):
        element_location = locating_element(element, 'CLICK')
        if element_location:
            element_location.click()
    elif isinstance(element, list):
        for _e in element:
            element_location = locating_element(_e, 'CLICK')
            element_location.click()
            sleep(0.5)
    sleep(0.5)

    # 获取元素其他属性
    get_Ouput(step, element_location)

    # 判断是否打开了新的窗口,并将新窗口添加到pages映射表中
    all_handles = g.driver.window_handles
    for handle in all_handles:
        if handle not in w.pages.values():
            w.register(step, handle)
示例#10
0
def tap(step):
    action = TouchAction(g.driver)

    element = step['element']
    if isinstance(element, str):

        if ',' in element or ',' in element:
            position = element.replace(',', ',').split(',')
            x = int(position[0])
            y = int(position[1])
            position = (x, y)
            g.driver.tap([position])
        else:
            element_location = locating_element(element, 'CLICK')
            action.tap(element_location).perform()
    elif isinstance(element, list):
        if ',' in element[0] or ',' in element[0]:
            positions = [eval('(' + _e + ')') for _e in element]
            g.driver.tap([positions])
        else:
            for _e in element:
                element_location = locating_element(_e, 'CLICK')
                action.tap(element_location).perform()
                sleep(0.5)
    sleep(0.5)

    # 获取元素其他属性
    output = step['output']
    for key in output:
        if output[key] == 'text':
            g.var[key] = element_location.text
        elif output[key] == 'tag_name':
            g.var[key] = element_location.tag_name
        elif output[key] in ('text…', 'text...'):
            if element_location.text.endswith('...'):
                g.var[key] = element_location.text[:-3]
            else:
                g.var[key] = element_location.text
        else:
            g.var[key] = element_location.get_attribute(output[key])
示例#11
0
def long_press(step):
    action = TouchAction(g.driver)

    element = step['element']
    duration = step['data'].get('持续时间', 1000)
    if ',' in element or ',' in element:
        position = element.replace(',', ',').split(',')
        x = int(position[0])
        y = int(position[1])
        action.long_press(x=x, y=y, duration=duration).perform()
    else:
        element_location = locating_element(element)
        action.long_press(element_location, duration=duration).perform()
    sleep(0.5)
示例#12
0
def set_value(step):
    data = step['data']
    element = step['element']
    element_location = locating_element(element)

    if isinstance(data['text'], tuple):
        element_location.set_value(*data['text'])
    elif element_location:
        if step['data'].get('清除文本', '') == '否' or step['data'].get(
                'clear', '').lower() == 'no':
            pass
        else:
            element_location.clear()
        element_location.set_value(data['text'])
示例#13
0
文件: web.py 项目: StaceyCxh/sweetest
def swipe(step):
    actions = ActionChains(g.driver)
    element = step['element']
    data = step['data']

    source = locating_element(element)
    x = data.get('x', 0)
    y = data.get('y', 0)
    actions.drag_and_drop_by_offset(source, x, y)
    actions.perform()
    sleep(0.5)

    # 获取元素其他属性
    get_Ouput(step, el)
示例#14
0
文件: web.py 项目: StaceyCxh/sweetest
def upload(step):
    import win32com.client

    data = step['data']
    element = step['element']
    element_location = locating_element(element)
    file_path = data.get('text', '') or data.get('file', '')

    element_location.click()
    sleep(3)
    shell = win32com.client.Dispatch("WScript.Shell")
    shell.Sendkeys(file_path)
    sleep(2)
    shell.Sendkeys("{ENTER}")
    sleep(2)
示例#15
0
文件: web.py 项目: StaceyCxh/sweetest
def double_click(step):
    actions = ActionChains(g.driver)
    element = step['element']
    el = locating_element(element)
    actions.double_click(el)
    actions.perform()
    sleep(0.5)

    # 获取元素其他属性
    get_Ouput(step, el)

    # 判断是否打开了新的窗口,并将新窗口添加到pages映射表中
    all_handles = g.driver.window_handles
    for handle in all_handles:
        if handle not in w.pages.values():
            w.register(step, handle)
示例#16
0
文件: web.py 项目: StaceyCxh/sweetest
def judge(step):
    data = step['data']
    element = step['element']

    try:
        element_location = locating_element(element)
        flag = 1
    except:
        flag = 2

    logger.info('REAL:%s' % repr(flag))

    if step['data'].get('存在', '') == '否' or step['data'].get(
            'judge', '').lower() == 'no':
        logger.info('DATA:%s' % repr(2))
        assert flag == 2
    else:
        logger.info('DATA:%s' % repr(1))
        assert flag == 1
示例#17
0
文件: web.py 项目: StaceyCxh/sweetest
def input(step):
    data = step['data']
    element = step['element']
    element_location = locating_element(element)

    if step['data'].get('清除文本', '') == '否' or step['data'].get(
            'clear', '').lower() == 'no':
        pass
    else:
        #element_location.send_keys(Keys.BACK_SPACE)
        #element_location.clear()
        element_location.send_keys(Keys.CONTROL, "a")
        element_location.send_keys(Keys.DELETE)

    for key in data:
        if key.startswith('text'):
            if isinstance(data[key], tuple):
                element_location.send_keys(*data[key])
            elif element_location:
                element_location.send_keys(data[key])
            sleep(0.5)

    get_Ouput(step, element_location)
示例#18
0
文件: web.py 项目: StaceyCxh/sweetest
def check(step):
    data = step['data']
    if not data:
        data = step['expected']

    element = step['element']
    element_location = locating_element(element)
    if '#' in element:
        e_name = element.split('#')[0] + '#'
    else:
        e_name = element
    by = g.elements[e_name]['by']
    output = step['output']

    if by in ('title', 'current_url'):
        getattr(Common, by)(data, output)

    else:
        for key in data:
            # 预期结果
            expected = data[key]

            if key == 'text':
                real = element_location.text
            else:
                real = element_location.get_attribute(key)
                if real is None:
                    real = 'None'

            detail_check(expected, real)

        # 获取元素其他属性
        get_Ouput(step, element_location)

    for k in ('新窗口', '标签页名', 'tabname'):
        if step['data'].get(k):
            w.switch_window(step['data'].get(k))
示例#19
0
def check(step):
    data = step['data']
    if not data:
        data = step['expected']

    element = step['element']
    element_location = locating_element(element)
    if '#' in element:
        e_name = element.split('#')[0] + '#'
    else:
        e_name = element
    by = g.elements[e_name]['by']
    output = step['output']

    if by in ('title', 'current_url'):
        getattr(Common, by)(data, output)

    else:
        for key in data:
            # 预期结果
            expected = data[key]
            # 切片操作处理
            s = re.findall(r'\[.*?\]', key)
            if s:
                s = s[0]
                key = key.replace(s, '')

            if key == 'text':
                real = element_location.text
            else:
                real = element_location.get_attribute(key)
            if s:
                real = eval('real' + s)
            logger.info('DATA:%s' % repr(expected))
            logger.info('REAL:%s' % repr(real))
            if isinstance(expected, str):
                if expected.startswith('*'):
                    assert expected[1:] in real
                else:
                    assert expected == real
            elif isinstance(expected, int):
                real = str2int(real)
                assert real == round(expected)
            elif isinstance(expected, float):
                t, p1 = str2float(real)
                d, p2 = str2float(expected)
                p = min(p1, p2)
                assert round(t, p) == round(d, p)
            elif expected is None:
                assert real == ''

        # 获取元素其他属性
        for key in output:
            if output[key] == 'text':
                g.var[key] = element_location.text
            elif output[key] in ('text…', 'text...'):
                if element_location.text.endswith('...'):
                    g.var[key] = element_location.text[:-3]
                else:
                    g.var[key] = element_location.text
            else:
                g.var[key] = element_location.get_attribute(output[key])
示例#20
0
def zoom(step):
    element = step['element']
    element_location = locating_element(element[0])
    percent = step['data'].get('百分比', 200)
    steps = step['data'].get('步长', 50)
    g.driver.zoom(element_location, percent, steps)
示例#21
0
文件: web.py 项目: StaceyCxh/sweetest
def obtain(step):
    element = step['element']
    element_location = locating_element(element)

    # 获取元素其他属性
    get_Ouput(step, element_location)