python之二参数校验

@allure.story('信息录入页面(终端ID输入框检查(小写字母))')
    def test_openapp_InfoPage_CilendID2(self):
        with allure.step("App_Sign_in_C17"):
            self.check_element("xpath", "abcdef", "请输入", "8", "")
 def check_element(self, type, info, element, max_len, special_char):
        """
        输入框输入不同的值进行检查
        type:元素定位的方式(ID,xpath)
        element:元素定位的名字
        info:输入框需要输入的内容
        max_len:输入框最长字符长度
        :param element:
        :return:
        """
        try:
            if type == "xpath":
                driver_base.find_element_by_xpath("//*[@text='{}']".format(element)).send_keys(info)
            if type == "id":
                driver_base.find_element_by_id(element).send_keys(info)
            time.sleep(1)
            self.source = driver_base.page_source
            print(self.source)
            if special_char == "中文" or special_char == "英文" or special_char == "特殊符号":
                if info not in self.source:
                    assert info not in self.source
                else:
                    allure.attach(driver_base.get_screenshot_as_png(), "输入框特殊字符串检查失败", allure.attachment_type.PNG)
                    assert info not in self.source
            else:
                if len(info) <= int(max_len):
                    if info in self.source:
                        assert info in self.source
                    else:
                        allure.attach(driver_base.get_screenshot_as_png(), "输入框字符串检查失败", allure.attachment_type.PNG)
                        assert info in self.source
                if len(info) > int(max_len):
                    if info not in self.source:
                        assert info not in self.source
                    else:
                        allure.attach(driver_base.get_screenshot_as_png(), "输入框字符串检查失败", allure.attachment_type.PNG)
                        assert info not in self.source
        except Exception as e:
            print(e)
            allure.attach(driver_base.get_screenshot_as_png(), "输入框字符串检查失败", allure.attachment_type.PNG)
            assert 1 > 2

你可能感兴趣的:(自动化测试,python)