from lib.login import *


class UserAdd001:
    name = 'user_add_001'
    def teststeps(self):
        wd = GSTORE['wd']

        STEP(1, '点击新增按钮')
        user_add = WebDriverWait(wd, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//div[@class='company-edmit-right']//span[contains(text(),'新增')]"))
        )
        user_add.click()
        sleep(2)

        STEP(2, '填写登录名')
        account_input = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located((By.XPATH, "//input[@placeholder='登录名以字母开头，长度在5-18之间，只能包含字母、数字和下划线、@']"))
        )
        account_input.clear()
        account_input.send_keys("admin@test1")

        STEP(3, '填写用户名称')
        account_name_input = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located((By.XPATH, "//div[@class='el-input el-input--suffix']//input[@placeholder='请输入用户名称']"))
        )
        account_name_input.clear()
        account_name_input.send_keys("admin@test1")

        STEP(4, '填写新密码')
        passwd_input = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[@placeholder='必须包含字母（不区分大小写）、数字和特殊字符，至少8个字符']"))
        )
        passwd_input.clear()
        passwd_input.send_keys("ub@123456")

        STEP(5, '填写确认密码')
        sepasswd_input = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[@placeholder='请确认密码']"))
        )
        sepasswd_input.clear()
        sepasswd_input.send_keys("ub@123456")

        STEP(6, '点击确认')
        commit = WebDriverWait(wd, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='新增']//span[contains(text(),'确 定')]"))
        )
        commit.click()

        STEP(7, '验证是否新增成功')
        get_menu = WebDriverWait(wd, 10).until(
            EC.visibility_of_element_located((By.XPATH, "//p[@class='el-message__content']"))
        )
        get_menu1 = get_menu.text
        INFO(get_menu1)
        CHECK_POINT('检查是否出现成功提示弹窗', get_menu1 == "操作成功!")
        sleep(2)


# class UserAdd002:
#     name = 'user_add_002'
#     def teststeps(self):
#         wd = GSTORE['wd']
#
#         STEP(1, '点击新增按钮')
#         user_add = WebDriverWait(wd, 10).until(
#             EC.element_to_be_clickable((By.XPATH, "//div[@class='company-edmit-right']//span[contains(text(),'新增')]"))
#         )
#         user_add.click()
#         sleep(2)
#
#         STEP(2, '填写登录名')
#         account_input = WebDriverWait(wd, 10).until(
#             EC.presence_of_element_located((By.XPATH, "//input[@placeholder='登录名以字母开头，长度在5-18之间，只能包含字母、数字和下划线、@']"))
#         )
#         account_input.clear()
#         account_input.send_keys("admin@test1")
#
#         STEP(3, '填写用户名称')
#         account_name_input = WebDriverWait(wd, 10).until(
#             EC.presence_of_element_located((By.XPATH, "//div[@class='el-input el-input--suffix']//input[@placeholder='请输入用户名称']"))
#         )
#         account_name_input.clear()
#         account_name_input.send_keys("测试用户2")
#
#         STEP(4, '填写新密码')
#         passwd_input = WebDriverWait(wd, 10).until(
#             EC.presence_of_element_located(
#                 (By.XPATH, "//input[@placeholder='必须包含字母（不区分大小写）、数字和特殊字符，至少8个字符']"))
#         )
#         passwd_input.clear()
#         passwd_input.send_keys("ub@123456")
#
#         STEP(5, '填写确认密码')
#         sepasswd_input = WebDriverWait(wd, 10).until(
#             EC.presence_of_element_located(
#                 (By.XPATH, "//input[@placeholder='请确认密码']"))
#         )
#         sepasswd_input.clear()
#         sepasswd_input.send_keys("ub@123456")
#
#         STEP(6, '点击确认')
#         commit = WebDriverWait(wd, 10).until(
#             EC.element_to_be_clickable((By.XPATH, "//div[@aria-label='新增']//span[contains(text(),'确 定')]"))
#         )
#         commit.click()
#
#         STEP(7, '验证是否正常提示')
#         get_menu = WebDriverWait(wd, 10).until(
#             EC.presence_of_element_located((By.CSS_SELECTOR, '.el-message__content'))
#         )
#         get_menu1 = get_menu.text
#         # CHECK_POINT('检查是否出现错误提示弹窗', get_menu1 == "登录名已存在，请重新输入")
#         CHECK_POINT('检查是否出现成功提示弹窗', get_menu1 == "操作成功!")
#         sleep(2)
