summaryrefslogtreecommitdiff
path: root/support/ui_utils/profiles/page_jump.py
blob: 2920e9a6c5d5fdf1183f7401328c9cf86fb25d1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import sys
import time

sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from support.ui_utils.element_position.profile_element_position import *
#from support.ui_utils.element_position.object_element_position import *
# sys.path.append(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
# from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
#from support.ui_utils.element_position.policy_element_position import *
import configparser
from datetime import datetime 

class PageJump:
    def __init__(self, driver):
        self.driver = driver

    def jump_sub_profile_page(self, page_jump_element_position, vsys_name=""):
        """
        vsys_name:空值时,参数来自配置文件
        """
        btn = self.driver.find_element(By.XPATH,
                                       '(//span[@class="MuiTypography-root MuiTypography-body1 MuiListItemText-primary css-1cxrtde"])[1]')
        btn = self.driver.execute_script("arguments[0].click()", btn)
        #btn = self.driver.find_element(By.XPATH, page_jump_element_position["mainPage_menu_bar_posXpath"])
        #self.driver.execute_script("arguments[0].click()", btn)  # 强制点击
        #self.change_vsys(vsys_name=vsys_name, page_jump_element_position=page_jump_element_position)
        self.driver.find_element(By.XPATH, page_jump_element_position["mainPage_leftMenu_posXpath"].format(
            page_jump_element_position["mainPage_profileFirstLevelMenu_Name"])).click()
        self.driver.find_element(By.XPATH, page_jump_element_position["mainPage_leftMenu_posXpath"].format(
            page_jump_element_position["mainPage_profileSecondLevelMenu_Name"])).click()
        """
        self.driver.find_element(By.XPATH, page_jump_element_position["mainPage_profileFirstLevelMenu_posXpath"]).click()
        self.driver.find_element(By.XPATH, page_jump_element_position["mainPage_profileSecondLevelMenu_posXpath"]).click()
        """

    def change_vsys(self, vsys_name="", page_jump_element_position=""):
        current_vsys_name = self.driver.find_element(By.XPATH, mainPage_currentPage_vsysName_posXpath).text.strip().lower()
        # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"the current vsys: {current_vsys_name}")
        current_path = os.path.dirname(__file__)   # 当前文件目录
        temp_path = os.path.dirname(os.path.dirname(os.path.dirname(current_path)))
        conf_path = os.path.join(temp_path, "configuration_file.ini")
        #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], conf_path)
        conf = configparser.ConfigParser()
        conf.read(conf_path, encoding="utf-8")
        id_for_ui = conf.get("vsys", "for_traffic_verification")
        id_vsys_format = "vsys{}".format(id_for_ui)   # 使用配置变量值
        #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], id_vsys_format)
        # 传入vsys_name值区分
        if vsys_name == "":     # 空,vsys值来自配置文件
            change_vsys_name = id_vsys_format
        else:     # 切换到指定vsys
            change_vsys_name = vsys_name
        # print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"the change_vsys_name: {change_vsys_name}")
        #if change_vsys_name != current_vsys_name:
        #    self.driver.find_element(By.XPATH,page_jump_element_position["mainPage_menu_bar_posXpath"]).click()
        self.driver.find_element(By.XPATH, page_jump_element_position["mainPage_menu_bar_posXpath"]).click()     # 点击vsys menu
        vsys_tree_name_list = self.driver.find_elements(By.XPATH, mainPage_vsysTree_vsysName_posXpath)
        time.sleep(0.5)
        flag_num = 0
        for el_vsys_item in vsys_tree_name_list:
            vsys_item_name = el_vsys_item.text.strip().lower()
            vsys_item_name_list = vsys_item_name.split("\n")
            #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], vsys_item_name_list)
            if change_vsys_name.lower() in vsys_item_name_list:
                flag_num = 1
                el_vsys_item.find_element(By.XPATH, ".//div[@class='menu-title']").click()
                #print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"Change to vsys {current_vsys_name}")
                break
        if flag_num == 0:
            print(datetime.now().strftime("%Y-%m-%d %H:%M:%S"), str(datetime.now().microsecond)[:3], f"no vsys: {change_vsys_name}", flush=True)