1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4""" 5Copyright (c) 2024 Huawei Device Co., Ltd. 6Licensed under the Apache License, Version 2.0 (the "License"); 7you may not use this file except in compliance with the License. 8You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12Unless required by applicable law or agreed to in writing, software 13distributed under the License is distributed on an "AS IS" BASIS, 14WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15See the License for the specific language governing permissions and 16limitations under the License. 17 18""" 19 20import pytest 21import os 22import subprocess 23import time 24 25from selenium import webdriver 26from selenium.webdriver.common.by import By 27from selenium.webdriver.common.keys import Keys 28 29driver = webdriver.Chrome() 30root = None 31file_input = None 32script_directory = '' 33 34 35def setup(): 36 global root 37 os.chdir("..") 38 subprocess.Popen(["python", 'dist/apDumpServer.py']) 39 print("setup : Selenium opens the test page") 40 time.sleep(2) 41 driver.get("http://127.0.0.1:9001/ap/") 42 application = driver.find_element(By.TAG_NAME, "ap-application") 43 root = application.shadow_root.find_element(By.CSS_SELECTOR, ".root") 44 45 46def test_import_file(): 47 global root, file_input, script_directory 48 main_menu = root.find_element(By.TAG_NAME, "lit-main-menu") 49 menu_body = main_menu.shadow_root.find_element(By.CSS_SELECTOR, ".menu-body") 50 menu_group = menu_body.find_element(By.TAG_NAME, "lit-main-menu-group") 51 menu_item = menu_group.find_element(By.TAG_NAME, "lit-main-menu-item") 52 file_input = menu_item.shadow_root.find_element(By.CSS_SELECTOR, ".file") 53 current_script_path = os.path.abspath(__file__) 54 script_directory = os.path.dirname(current_script_path) 55 path = os.path.join(script_directory, 'test.ap') 56 file_path = os.path.normpath(path).replace("\\", "/") 57 file_input.send_keys(file_path) 58 time.sleep(2) 59 60 61def test_node_click(): 62 global root 63 app_content = root.find_element(By.CSS_SELECTOR, ".content") 64 summary_div = app_content.find_element(By.TAG_NAME, "div") 65 tab_summary = summary_div.find_element(By.TAG_NAME, "tab-ap-summary") 66 summary_head = tab_summary.shadow_root.find_element(By.CSS_SELECTOR, ".tab-summary-head") 67 expansion_div = summary_head.find_element(By.TAG_NAME, "div").find_element(By.TAG_NAME, "div") 68 expansion_div.click() 69 time.sleep(2) 70 expansion_div.click() 71 time.sleep(2) 72 labels = summary_head.find_elements(By.TAG_NAME, "label") 73 for label in labels: 74 label.click() 75 time.sleep(2) 76 77 78def test_search(): 79 global root 80 search_vessel = root.find_element(By.CSS_SELECTOR, ".search-vessel") 81 search_div = search_vessel.find_element(By.CSS_SELECTOR, ".search") 82 lit_search = search_div.find_element(By.CSS_SELECTOR, "lit-search") 83 search_input = lit_search.shadow_root.find_element(By.CSS_SELECTOR, ".root").find_element(By.TAG_NAME, "input") 84 search_input.send_keys("d") 85 time.sleep(2) 86 search_input.send_keys("w") 87 time.sleep(2) 88 current_text = search_input.get_attribute("value") 89 for _ in range(len(current_text)): 90 search_input.send_keys(Keys.BACK_SPACE) 91 time.sleep(2) 92 93 94def test_unsupported_file(): 95 global script_directory 96 driver.refresh() 97 application_node = driver.find_element(By.TAG_NAME, "ap-application") 98 root_node = application_node.shadow_root.find_element(By.CSS_SELECTOR, ".root") 99 main_menu = root_node.find_element(By.TAG_NAME, "lit-main-menu") 100 menu_body = main_menu.shadow_root.find_element(By.CSS_SELECTOR, ".menu-body") 101 menu_group = menu_body.find_element(By.TAG_NAME, "lit-main-menu-group") 102 menu_item = menu_group.find_element(By.TAG_NAME, "lit-main-menu-item") 103 file_input2 = menu_item.shadow_root.find_element(By.CSS_SELECTOR, ".file") 104 path = os.path.join(script_directory, 'test.txt') 105 file_path = os.path.normpath(path).replace("\\", "/") 106 file_input2.send_keys(file_path) 107 time.sleep(5) 108 109 110def teardown(): 111 print("teardown : Close selenium") 112 driver.close() 113