Skip to content

Commit 542403c

Browse files
committed
Update dev version
* Add zh-TW and EN comments. * Fix type-hint
1 parent 6030c58 commit 542403c

File tree

30 files changed

+1495
-982
lines changed

30 files changed

+1495
-982
lines changed

dev_requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ build
22
twine
33
sphinx
44
je_web_runner_dev
5-
sphinx-rtd-theme
5+
sphinx-rtd-theme
6+
Pyside6

je_web_runner/__main__.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,39 +12,58 @@
1212

1313
if __name__ == "__main__":
1414
try:
15+
# 處理單一檔案的執行
16+
# Execute actions from a single JSON file
1517
def preprocess_execute_action(file_path: str):
1618
execute_action(read_action_json(file_path))
1719

1820

21+
# 處理整個資料夾的執行
22+
# Execute actions from all JSON files in a directory
1923
def preprocess_execute_files(file_path: str):
2024
execute_files(get_dir_files_as_list(file_path))
2125

2226

27+
# 處理字串輸入的 JSON 執行
28+
# Execute actions from a JSON string
2329
def preprocess_read_str_execute_action(execute_str: str):
2430
if sys.platform in ["win32", "cygwin", "msys"]:
31+
# Windows 平台可能需要兩次 json.loads
32+
# On Windows, sometimes double json.loads is required
2533
json_data = json.loads(execute_str)
2634
execute_str = json.loads(json_data)
2735
else:
2836
execute_str = json.loads(execute_str)
2937
execute_action(execute_str)
3038

3139

40+
# 對應 argparse 參數與處理函式
41+
# Mapping argparse options to handler functions
3242
argparse_event_dict = {
3343
"execute_file": preprocess_execute_action,
3444
"execute_dir": preprocess_execute_files,
3545
"execute_str": preprocess_read_str_execute_action
3646
}
47+
48+
# 建立 argparse 解析器
3749
parser = argparse.ArgumentParser()
3850
parser.add_argument("-e", "--execute_file", type=str, help="choose action file to execute")
3951
parser.add_argument("-d", "--execute_dir", type=str, help="choose dir include action file to execute")
4052
parser.add_argument("--execute_str", type=str, help="execute json str")
53+
54+
# 解析參數
4155
args = parser.parse_args()
4256
args = vars(args)
57+
58+
# 執行對應的處理函式
4359
for key, value in args.items():
4460
if value is not None:
4561
argparse_event_dict.get(key)(value)
62+
63+
# 如果沒有任何參數,拋出例外
4664
if all(value is None for value in args.values()):
4765
raise WebRunnerExecuteException(argparse_get_wrong_data)
66+
4867
except Exception as error:
4968
print(repr(error), file=sys.stderr)
50-
sys.exit(1)
69+
sys.exit(1)
Lines changed: 89 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import List, Union
22

33
from selenium.webdriver.remote.webelement import WebElement
44
from selenium.webdriver.support.ui import Select
@@ -9,15 +9,19 @@
99

1010

1111
class WebElementWrapper(object):
12-
1312
def __init__(self):
14-
self.current_web_element: [WebElement] = None
15-
self.current_web_element_list: [List[WebElement]] = None
13+
# 當前操作的單一 WebElement
14+
# Current active WebElement
15+
self.current_web_element: Union[WebElement, None] = None
16+
17+
# 當前操作的 WebElement 清單
18+
# Current list of WebElements
19+
self.current_web_element_list: Union[List[WebElement], None] = None
1620

1721
def submit(self) -> None:
1822
"""
19-
current web element submit
20-
:return: None
23+
提交當前 WebElement
24+
Submit the current WebElement
2125
"""
2226
web_runner_logger.info("WebElementWrapper submit")
2327
try:
@@ -29,8 +33,8 @@ def submit(self) -> None:
2933

3034
def clear(self) -> None:
3135
"""
32-
current web element clear
33-
:return: None
36+
清除當前 WebElement 的內容
37+
Clear the content of the current WebElement
3438
"""
3539
web_runner_logger.info("WebElementWrapper clear")
3640
try:
@@ -40,10 +44,12 @@ def clear(self) -> None:
4044
web_runner_logger.error(f"WebElementWrapper clear, failed: {repr(error)}")
4145
record_action_to_list("Web element clear", None, error)
4246

43-
def get_property(self, name: str) -> str:
47+
def get_property(self, name: str) -> None | str | bool | WebElement | dict:
4448
"""
45-
:param name: name of property
46-
:return: property value as str
49+
取得 WebElement 的屬性
50+
Get property of the WebElement
51+
:param name: 屬性名稱 / property name
52+
:return: 屬性值 / property value
4753
"""
4854
web_runner_logger.info(f"WebElementWrapper get_property, name: {name}")
4955
param = locals()
@@ -54,10 +60,12 @@ def get_property(self, name: str) -> str:
5460
web_runner_logger.error(f"WebElementWrapper get_property, name: {name}, failed: {repr(error)}")
5561
record_action_to_list("Web element get_property", param, error)
5662

57-
def get_dom_attribute(self, name: str) -> str:
63+
def get_dom_attribute(self, name: str) -> str | None:
5864
"""
59-
:param name: name of dom
60-
:return: dom attribute value as str
65+
取得 DOM 屬性
66+
Get DOM attribute
67+
:param name: DOM 屬性名稱 / DOM attribute name
68+
:return: 屬性值 / attribute value
6169
"""
6270
web_runner_logger.info(f"WebElementWrapper get_dom_attribute, name: {name}")
6371
param = locals()
@@ -68,10 +76,12 @@ def get_dom_attribute(self, name: str) -> str:
6876
web_runner_logger.error(f"WebElementWrapper get_dom_attribute, name: {name}, failed: {repr(error)}")
6977
record_action_to_list("Web element get_dom_attribute", param, error)
7078

71-
def get_attribute(self, name: str) -> str:
79+
def get_attribute(self, name: str) -> str | None:
7280
"""
73-
:param name: name of web element
74-
:return:web element attribute value as str
81+
取得 WebElement 的屬性
82+
Get attribute of the WebElement
83+
:param name: 屬性名稱 / attribute name
84+
:return: 屬性值 / attribute value
7585
"""
7686
web_runner_logger.info(f"WebElementWrapper get_attribute, name: {name}")
7787
param = locals()
@@ -82,23 +92,25 @@ def get_attribute(self, name: str) -> str:
8292
web_runner_logger.error(f"WebElementWrapper get_attribute, name: {name}, failed: {repr(error)}")
8393
record_action_to_list("Web element get_attribute", param, error)
8494

85-
def is_selected(self) -> bool:
95+
def is_selected(self) -> bool | None:
8696
"""
87-
check current web element is selected or not
88-
:return: True or False
97+
檢查 WebElement 是否被選取
98+
Check if WebElement is selected
99+
:return: True/False
89100
"""
90101
web_runner_logger.info("WebElementWrapper is_selected")
91102
try:
92103
record_action_to_list("Web element is_selected", None, None)
93104
return self.current_web_element.is_selected()
94105
except Exception as error:
95-
web_runner_logger.error(f"WebElementWrapper get_attribute, failed: {repr(error)}")
106+
web_runner_logger.error(f"WebElementWrapper is_selected, failed: {repr(error)}")
96107
record_action_to_list("Web element is_selected", None, error)
97108

98-
def is_enabled(self) -> bool:
109+
def is_enabled(self) -> bool | None:
99110
"""
100-
check current web element is enable or not
101-
:return: True or False
111+
檢查 WebElement 是否可用
112+
Check if WebElement is enabled
113+
:return: True/False
102114
"""
103115
web_runner_logger.info("WebElementWrapper is_enabled")
104116
try:
@@ -110,9 +122,9 @@ def is_enabled(self) -> bool:
110122

111123
def input_to_element(self, input_value: str) -> None:
112124
"""
113-
input value to current web element
114-
:param input_value: what value we want to input to current web element
115-
:return: None
125+
輸入文字到 WebElement
126+
Input text into WebElement
127+
:param input_value: 要輸入的文字 / text to input
116128
"""
117129
web_runner_logger.info(f"WebElementWrapper input_to_element, input_value: {input_value}")
118130
param = locals()
@@ -121,14 +133,13 @@ def input_to_element(self, input_value: str) -> None:
121133
record_action_to_list("Web element input_to_element", param, None)
122134
except Exception as error:
123135
web_runner_logger.error(
124-
f"WebElementWrapper input_to_element, input_value: {input_value}, "
125-
f"failed: {repr(error)}")
136+
f"WebElementWrapper input_to_element, input_value: {input_value}, failed: {repr(error)}")
126137
record_action_to_list("Web element input_to_element", param, error)
127138

128139
def click_element(self) -> None:
129140
"""
130-
click current web element
131-
:return: None
141+
點擊 WebElement
142+
Click the WebElement
132143
"""
133144
web_runner_logger.info("WebElementWrapper click_element")
134145
try:
@@ -138,10 +149,11 @@ def click_element(self) -> None:
138149
web_runner_logger.error(f"WebElementWrapper click_element, failed: {repr(error)}")
139150
record_action_to_list("Web element click_element", None, error)
140151

141-
def is_displayed(self) -> bool:
152+
def is_displayed(self) -> bool | None:
142153
"""
143-
check current web element is displayed or not
144-
:return: True or False
154+
檢查 WebElement 是否顯示
155+
Check if WebElement is displayed
156+
:return: True/False
145157
"""
146158
web_runner_logger.info("WebElementWrapper is_displayed")
147159
try:
@@ -151,10 +163,12 @@ def is_displayed(self) -> bool:
151163
web_runner_logger.error(f"WebElementWrapper is_displayed, failed: {repr(error)}")
152164
record_action_to_list("Web element is_displayed", None, error)
153165

154-
def value_of_css_property(self, property_name: str) -> str:
166+
def value_of_css_property(self, property_name: str) -> str | None:
155167
"""
156-
:param property_name: name of property
157-
:return: css property value as str
168+
取得 CSS 屬性值
169+
Get CSS property value
170+
:param property_name: 屬性名稱 / property name
171+
:return: 屬性值 / property value
158172
"""
159173
web_runner_logger.info(f"WebElementWrapper value_of_css_property, property_name: {property_name}")
160174
param = locals()
@@ -166,10 +180,12 @@ def value_of_css_property(self, property_name: str) -> str:
166180
f"WebElementWrapper value_of_css_property, property_name: {property_name}, failed: {repr(error)}")
167181
record_action_to_list("Web element value_of_css_property", param, error)
168182

169-
def screenshot(self, filename: str) -> bool:
183+
def screenshot(self, filename: str) -> bool | None:
170184
"""
171-
:param filename: full file name not need .png extension
172-
:return: Save True or not
185+
對 WebElement 截圖並存檔
186+
Take screenshot of WebElement and save
187+
:param filename: 檔名 (不需加 .png) / filename (without .png)
188+
:return: 是否成功 / True if success
173189
"""
174190
web_runner_logger.info(f"WebElementWrapper screenshot, filename: {filename}")
175191
param = locals()
@@ -180,11 +196,11 @@ def screenshot(self, filename: str) -> bool:
180196
web_runner_logger.info(f"WebElementWrapper screenshot, filename: {filename}, failed: {repr(error)}")
181197
record_action_to_list("Web element screenshot", param, error)
182198

183-
# Web element wrapper add function
184199
def change_web_element(self, element_index: int) -> None:
185200
"""
186-
:param element_index: change to web element index
187-
:return: web element list [element_index]
201+
切換當前 WebElement
202+
Change current WebElement
203+
:param element_index: WebElement 清單索引 / index in WebElement list
188204
"""
189205
web_runner_logger.info(f"WebElementWrapper change_web_element, element_index: {element_index}")
190206
param = locals()
@@ -198,33 +214,55 @@ def change_web_element(self, element_index: int) -> None:
198214

199215
def check_current_web_element(self, check_dict: dict) -> None:
200216
"""
201-
:param check_dict: check web element dict {name: should be value}
217+
檢查當前 WebElement 是否符合指定條件
218+
Check if the current WebElement matches the given conditions
219+
220+
:param check_dict: 驗證用的字典 {屬性名稱: 預期值}
221+
Dictionary for validation {attribute_name: expected_value}
202222
:return: None
203223
"""
204224
web_runner_logger.info(f"WebElementWrapper check_current_web_element, check_dict: {check_dict}")
205225
param = locals()
206226
try:
227+
# 呼叫工具函式檢查 WebElement 的屬性
228+
# Call utility function to check WebElement details
207229
check_web_element_details(self.current_web_element, check_dict)
230+
231+
# 紀錄成功動作
232+
# Record successful action
208233
record_action_to_list("Web element check_current_web_element", param, None)
209234
except Exception as error:
235+
# 錯誤處理與紀錄
236+
# Handle and log error
210237
web_runner_logger.error(
211-
f"WebElementWrapper change_web_element, check_dict: {check_dict}, "
212-
f"failed: {repr(error)}")
238+
f"WebElementWrapper check_current_web_element, check_dict: {check_dict}, failed: {repr(error)}"
239+
)
213240
record_action_to_list("Web element check_current_web_element", param, error)
214241

215-
def get_select(self) -> Select:
242+
def get_select(self) -> Select | None:
216243
"""
217-
get Select(current web element)
218-
:return: Select(current web element)
244+
取得 Select 物件 (用於操作下拉選單)
245+
Get a Select object (for handling dropdown menus)
246+
247+
:return: Select(current web element) 或 None
248+
Select(current web element) or None
219249
"""
220250
web_runner_logger.info("WebElementWrapper get_select")
221251
try:
252+
# 紀錄成功動作
253+
# Record successful action
222254
record_action_to_list("Web element get_select", None, None)
255+
256+
# 回傳 Select 包裝的 WebElement
257+
# Return Select wrapper of the WebElement
223258
return Select(self.current_web_element)
224259
except Exception as error:
260+
# 錯誤處理與紀錄
261+
# Handle and log error
225262
web_runner_logger.error(f"WebElementWrapper get_select, failed: {repr(error)}")
226263
record_action_to_list("Web element get_select", None, error)
227264

228265

229-
# use this wrapper to use web element
230-
web_element_wrapper = WebElementWrapper()
266+
# 使用此包裝器來操作 WebElement
267+
# Use this wrapper to operate on WebElement
268+
web_element_wrapper = WebElementWrapper()

je_web_runner/gui/__init__.py

Whitespace-only changes.

je_web_runner/gui/main_widget.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)