Exemple #1
0
    def choose_product_application(cls, prod_app=None):
        app_chooser_xpath = f'//div[@class="el-dialog"]//button/span[contains(text(), {consts.CONFIRM})]/..'
        try:
            WebDriverWait(cls.driver, config.WAIT).until(EC.element_to_be_clickable((By.XPATH, app_chooser_xpath)))
            cls.driver.find_element_by_xpath(r'//div[@class="el-dialog"]//div[@class="el-select"]').click()
            if prod_app:
                app = cls.driver.find_element_by_xpath(
                    f'//ul[@class="el-scrollbar__view el-select-dropdown__list"]/li/span[text()="{prod_app}"]/..')
            else:
                app = random.choice(
                    cls.driver.find_elements_by_xpath(r'//ul[@class="el-scrollbar__view el-select-dropdown__list"]/li'))
                prod_app = cls.get_element_attribute(app, 'text')

            app.click()
            # TODO: 检查选择产品应用之后,选择框显示与选择一致
            cls.driver.find_element_by_xpath(app_chooser_xpath).click()
            try:
                WebDriverWait(cls.driver, config.WAIT).until_not(
                    EC.element_to_be_clickable((By.XPATH, app_chooser_xpath)))
                cls.prod_app = prod_app
                logger.info("用户选择的应用为: %s", prod_app)
            except TimeoutException:
                logger.critical("用户选择产品应用并点击确定之后弹窗不消失!")
        except Exception as e:
            print('ooooooppppps')
Exemple #2
0
    def compare_with_db(self, rule_id):
        rule = self.query_rules_from_db(*self.rule_fields, id=rule_id)[0]

        mapping = {
            '规则编号': rule['rule_code'],
            '规则名称': rule['name'],
            '外部名称': rule['external_name'],
            '规则描述': rule['description'],
            '适用范围': self.query_rule_set_category(rule_id),
            '启用状态': consts.FACTOR_STATUSES[rule['status']],
            '所属应用': self.query_apps_by_rule_code(rule['rule_code'])
        }

        for key, exp in mapping.items():
            try:
                element = self.driver.find_element_by_xpath(
                    f'//label[contains(text(), "{key}")]/../div/div')
            except NoSuchElementException as ex:
                self.assertIsNone(ex, f'规则详情页中未找到属性: {key}')
            else:
                val = self.get_element_attribute(element, 'text')
                self.assertEqual(
                    val, exp,
                    f'规则({rule["rule_code"]})属性{key}不匹配!展示{val},应为{exp}')
        logger.info("规则(%s)详情页校验成功!", rule["rule_code"])
Exemple #3
0
 def login(cls, user=config.USER, pwd=config.PWD, prod_app=None):
     logger.info("登录用户%s...", user)
     cls.driver.get(config.SERVER)
     login_btn = (By.XPATH, r'//button/span[contains(text(), "登录")]/..')
     try:
         WebDriverWait(cls.driver, config.IMPLICIT_WAIT).until(EC.url_contains(f'{config.SERVER}#/login?'))
         WebDriverWait(cls.driver, config.IMPLICIT_WAIT).until(EC.element_to_be_clickable(login_btn))
         cls.driver.find_element_by_name('username').send_keys(user)
         cls.driver.find_element_by_name('password').send_keys(pwd)
         cls.driver.find_element(*login_btn).click()
         login_tip = (By.XPATH, r'//*[contains(text(), "登录成功")]')
         try:
             WebDriverWait(cls.driver, config.IMPLICIT_WAIT).until(EC.presence_of_element_located(login_tip))
             cls.user = user
             logger.info("用户%s登录成功!", user)
             cls.choose_product_application(prod_app)
         except TimeoutException:
             logger.critical("登录失败!")
     except TimeoutException:
         logger.critical("当前页面无法找到登录button!  %s", cls.driver.current_url)
Exemple #4
0
 def tearDownClass(cls) -> None:
     logger.info("测试结束!")
     cls.driver.quit()
Exemple #5
0
 def setUpClass(cls) -> None:
     cls.driver.maximize_window()
     logger.info("准备测试...")
     cls.login()