import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', '..', '..')))
from 运维集控.项目测试.运维标准版.lib.base import *

class AreagroupMod001:
    name = 'Areagroup_modify_001'
    def teststeps(self):
        wd = GSTORE['wd']

        STEP(1, '勾选分组,点击“编辑”按钮')
        try:
            # 等待页面加载，并查找包含文本“测试”的元素旁边的复选框
            checkbox  = WebDriverWait(wd, 10).until(
                EC.presence_of_element_located((By.XPATH, "//span[contains(text(), '测试区域1')]//span[@class='el-checkbox__inner']"))
            )
            areagroup_select = checkbox.find_element(By.XPATH, "./ancestor::span[contains(@class, 'el-checkbox__input')]//input")
            # 勾选复选框
            if not areagroup_select.is_selected():
                areagroup_select.click()
        finally:
            areagroup_modify = WebDriverWait(wd, 10).until(
                EC.element_to_be_clickable((By.XPATH, "//span[contains(text(),'编辑')]"))
            )
            areagroup_modify.click()
            sleep(2)

        STEP(2, '修改分组名称')
        group_name = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located((By.XPATH, "//input[@placeholder='长度1-20个字符']"))
        )
        group_name.clear()
        group_name.send_keys("测试区域1-已修改")

        STEP(3, '修改分组地址')
        group_address = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located((By.XPATH, "//input[@placeholder='输入地址不能大于50个字符']"))
        )
        group_address.clear()
        group_address.send_keys("顺恒利大厦-已修改")

        STEP(4, '修改分组备注')
        group_remark = WebDriverWait(wd, 10).until(
            EC.presence_of_element_located(
                (By.XPATH, "//input[@placeholder='请输入备注']"))
        )
        group_remark.clear()
        group_remark.send_keys("修改测试分组")

        STEP(5, '点击确认')
        commit = WebDriverWait(wd, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//div[@class='dialog-footer']//span[contains(text(),'确 定')]"))
        )
        commit.click()

        STEP(6, '验证是否修改成功')
        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 == "操作成功!")
        sleep(2)