Exemple #1
0
 def __init__(self, driver, case_info, log, path):
     self.driver = driver
     self.log = log
     self.case_info = case_info
     self.path = path
     self.ele_util = ElementUtils(self.driver)
     self.btn_completed["element_info"] = path + "//div[contains(@class,'wfm-btn-group')]/div[2]"
     self.old_div["element_info"] = path + "//div[contains(@class,'picker-selected')]"
     self.option_divs["element_info"] = path + "//div[contains(@class,'picker-slot-wrapper')]/div"
     self.parent_div["element_info"] = path + "//div[contains(@class,'picker-slot-wrapper')]"
def is_error_code_show(self, case_info):
    # undefined_check = {'element_info': "//*[contains(text(),'undefined')]",
    #                  'find_type': 'xpath',
    #                  'check': 'default_check',
    #                  'txt': '验证是否有undefined乱码'
    #                  }
    #
    ele_util = ElementUtils(self.driver)
    # #验证是否有undefined乱码
    # return ele_util.check(undefined_check, case_info, self.test_log)
    sleep(0.2)
    ele_util.screen_shot(case_info["desc"])
    return False
def log_out(self, case_info):
    """默认当前页在首页"""
    home_page = {
        'element_info': "//*[contains(@class,'icon-shouye')]",
        'find_type': 'xpath',
        'txt': '首页',
        'operate_type': 'click'
    }
    user_info = {
        'element_info': "avatar",
        'find_type': 'class_name',
        'txt': '我',
        'operate_type': 'click'
    }
    btn_log_out = {
        'element_info': "//div[contains(@class,'wfm-btn-wrap')]/div",
        'find_type': 'xpath',
        'txt': '退出登录按钮',
        'tag_name': 'button',
        'operate_type': 'click'
    }
    ele_util = ElementUtils(self.driver)
    # 点击首页
    ele_util.operate(home_page, case_info, self.test_log)
    # 点击我
    ele_util.operate(user_info, case_info, self.test_log)
    # 点击退出登录
    ele_util.operate(btn_log_out, case_info, self.test_log)
def log_in(self, case_info, use_name, pwd):
    """登录"""
    user_input = {
        'element_info': "//input[@type='text']",
        'find_type': 'xpath',
        'txt': '用户名文本框',
        'operate_type': 'set_value',
        'tag_name': 'input',
        'value': use_name
    }
    pwd_input = {
        'element_info': "//*[@type='password']",
        'find_type': 'xpath',
        'txt': '密码文本框',
        'operate_type': 'set_value',
        'tag_name': 'input',
        'value': pwd
    }
    btn_login = {
        'element_info':
        "//div[contains(@class,'login') and contains(@class,'wfm-btn')]",
        'find_type': 'xpath',
        'txt': '登录按钮',
        'operate_type': 'click'
    }

    success_check = {
        'element_info': "notice",
        'find_type': 'class_name',
        'check': 'default_check',
        'txt': '验证是否登录成功'
    }

    ele_util = ElementUtils(self.driver)
    self.driver.implicitly_wait(5)
    # 输入用户名
    ele_util.operate(user_input, case_info, self.test_log, isclear=True)
    # 输入密码
    ele_util.operate(pwd_input, case_info, self.test_log, isclear=True)
    # 点击登录
    ele_util.operate(btn_login, case_info, self.test_log)

    # 验证是否登录成功
    return ele_util.check(success_check, case_info, self.test_log)
def set_app_server(self, case_info):
    """设置服务器"""
    btn_skip = {
        'element_info':
        "//div[contains(@class,'active')]//div[contains(@class,'skip')]",
        'find_type': 'xpath',
        'txt': '跳过',
        'operate_type': 'click'
    }
    btn_set = {
        'element_info': "//img[contains(@class,'wf-setting-btn')]",
        'find_type': 'xpath',
        'txt': '设置服务器',
        'operate_type': 'click'
    }
    input_server = {
        'element_info':
        "//div[contains(@class,'wf-left-shift')]/div[2]//input",
        'find_type': 'xpath',
        'txt': '服务器文本框',
        'operate_type': 'set_value',
        'tag_name': 'input',
        'value': global_param.app_server
    }

    language_href = {
        'element_info':
        "//div[contains(@class,'wf-left-shift')]/div[3]/div[1]",
        'find_type': 'xpath',
        'txt': '选择语言',
        'operate_type': 'click'
    }

    btn_save = {
        'element_info': "//div[contains(@class,'wfm-setting-button')]",
        'find_type': 'xpath',
        'txt': '保存配置信息',
        'operate_type': 'click'
    }
    ele_util = ElementUtils(self.driver)
    temp1 = ele_util.operate(btn_skip, case_info, self.test_log)
    # 点击设置
    temp2 = ele_util.operate(btn_set, case_info, self.test_log)
    # 输入服务器地址
    temp3 = ele_util.operate(input_server,
                             case_info,
                             self.test_log,
                             isclear=True)
    # 选择语言
    ele_util.operate(language_href, case_info, self.test_log)
    wfm_picker = WFMPickerControlPage(
        self.driver, case_info, self.test_log,
        "//div[contains(@class,'wf-left-shift')]/div[3]")
    lan = '简体中文'
    if global_param.language == 'chinese':
        lan = '简体中文'
    elif global_param.language == 'english':
        lan = 'English'
    elif global_param.language == 'traditional':
        lan = '繁體中文'
    wfm_picker.select(lan)
    # 点击保存
    temp4 = ele_util.operate(btn_save, case_info, self.test_log)
    return (temp1["result"] and temp2["result"] and temp3["result"]
            and temp4["result"])
Exemple #6
0
class LoginPage:

    user_input = {
        'element_info': "//*[@type='text']",
        'find_type': 'xpath',
        'txt': '用户名文本框',
        'operate_type': 'set_value',
        'tag_name': 'input',
        'value': ''
    }
    pwd_input = {
        'element_info': "//*[@type='password']",
        'find_type': 'xpath',
        'txt': '密码文本框',
        'operate_type': 'set_value',
        'tag_name': 'input',
        'value': ''
    }
    btn_login = {
        'element_info':
        "//div[contains(@class,'login') and contains(@class,'wfm-btn')]",
        'find_type': 'xpath',
        'txt': '登录按钮',
        'operate_type': 'click'
    }

    success_check = {
        'element_info': "notice",
        'find_type': 'class_name',
        'check': 'default_check',
        'txt': '验证是否登录成功'
    }

    def __init__(self, driver, case_info, log):
        self.driver = driver
        self.log = log
        self.case_info = case_info
        self.ele_util = ElementUtils(self.driver)

    def iuput_user_name(self, value):
        self.user_input["value"] = value
        return self.ele_util.operate(self.user_input,
                                     self.case_info,
                                     self.log,
                                     isclear=True)

    def iuput_pwd(self, value):
        self.pwd_input["value"] = value
        return self.ele_util.operate(self.pwd_input,
                                     self.case_info,
                                     self.log,
                                     isclear=True)

    def login_click(self):
        return self.ele_util.operate(self.btn_login, self.case_info, self.log)

    def check(self, id):
        if id == '002':
            return self.ele_util.check(self.user_input, self.case_info,
                                       self.log)
        elif id == '001':
            return self.ele_util.check(self.success_check, self.case_info,
                                       self.log)
Exemple #7
0
 def __init__(self, driver, case_info, log):
     self.driver = driver
     self.log = log
     self.case_info = case_info
     self.ele_util = ElementUtils(self.driver)
Exemple #8
0
class WFMPickerControlPage:

    btn_completed = {
        'element_info': " ",
        'find_type': 'xpath',
        'txt': '点击完成',
        'operate_type': 'click'
    }

    old_div = {
        'element_info': "",
        'find_type': 'xpath',
        'txt': '当前old选中值',
        'operate_type': 'get_value',
        'tag_name': 'div'
    }

    target_div = {
        'element_info': "",
        'find_type': 'xpath',
        'txt': '目标值',
        'operate_type': 'click'
    }

    option_divs = {
        'element_info': "",
        'find_type': 'xpaths',
        'txt': '同级div列表',
        'operate_type': 'click'
    }

    parent_div = {
        'element_info': "",
        'find_type': 'xpath',
        'txt': 'div父级节点',
        'operate_type': 'click'
    }

    def __init__(self, driver, case_info, log, path):
        self.driver = driver
        self.log = log
        self.case_info = case_info
        self.path = path
        self.ele_util = ElementUtils(self.driver)
        self.btn_completed["element_info"] = path + "//div[contains(@class,'wfm-btn-group')]/div[2]"
        self.old_div["element_info"] = path + "//div[contains(@class,'picker-selected')]"
        self.option_divs["element_info"] = path + "//div[contains(@class,'picker-slot-wrapper')]/div"
        self.parent_div["element_info"] = path + "//div[contains(@class,'picker-slot-wrapper')]"

    def select(self, new):
        """
        滑动选择
        :param new: 目标值如 进
        :return:
        """
        info = "滑动选择"
        self.log.build_start_line(self.case_info["id"] + "-" + self.case_info["desc"] + "_" + info)
        self.select_operate(new)
        # 点击完成
        self.btn_completed_click()

    def select_operate(self, new):
        old = self.get_picker_selected_value(self.old_div, '')
        if old != new:
            old_ele = self.ele_util.elements_by(self.old_div)
            parent_div_ele = self.ele_util.elements_by(self.parent_div)
            option_lst = self.ele_util.elements_by(self.option_divs)
            new_indx = [index for index, value in enumerate(option_lst) if value.get_attribute('innerText').find(new) >= 0]

            self.driver.execute_script("""
                    function getComputedTranslateY(obj)
                    {
                        if(!window.getComputedStyle) return;
                        var style = getComputedStyle(obj),
                            transform = style.transform || style.webkitTransform || style.mozTransform;
                        var mat = transform.match(/^matrix3d\((.+)\)$/);
                        if(mat) return parseFloat(mat[1].split(', ')[13]);
                        mat = transform.match(/^matrix\((.+)\)$/);
                        return mat ? parseFloat(mat[1].split(', ')[5]) : 0;
                    }
    
                    old_inx = Array.prototype.slice.call(arguments[1].parentNode.children).indexOf(arguments[1]);
                    var tranY = getComputedTranslateY(arguments[0]);
                    arguments[0].style.transform = "translate(0px, " + (tranY- (arguments[2] - old_inx)*arguments[3]) + "px) translateZ(0px)"
                    """, parent_div_ele, old_ele, new_indx, int(sel_row_height))

            # 点击目标节点
            sleep(0.2)
            self.target_div[
                "element_info"] = self.path + "//div[contains(@class,'picker-slot-wrapper')]/div[contains(text(), '" + new + "')]"
            self.ele_util.operate(self.target_div, self.case_info, self.log)

    def btn_completed_click(self):
        self.ele_util.operate(self.btn_completed, self.case_info, self.log)

    def get_picker_selected_value(self, item, defalut_value):
        """
        获取选中的值
        :return:
        """
        result = defalut_value
        res = self.ele_util.operate(item, self.case_info, self.log)
        if res["result"]:
            result = res["text"]
        return result