fix chrome tasks (#230)

* fix chrome

* fix: fix proxy setup

* feat&fix: add proxy support in setup and remove hardcoded proxy from example

* fix tasks

* fix chrome finished

* fix

* clean chrome_fix code

* clean chrome_fix code

---------

Co-authored-by: adlsdztony <zzl0712@connect.hku.hk>
This commit is contained in:
Yuan Mengqi
2025-07-03 21:32:41 +08:00
committed by GitHub
parent bdaf37e0e5
commit b2fb8b4222
26 changed files with 444 additions and 140 deletions

View File

@@ -21,7 +21,8 @@ from .chrome import (
is_expected_url_pattern_match,
is_added_to_steam_cart,
is_expected_installed_extensions,
compare_pdf_images
compare_pdf_images,
is_expected_active_tab_approximate
)
from .docs import (
compare_font_names,

View File

@@ -37,6 +37,34 @@ def is_expected_active_tab(active_tab_info: Dict[str, str], rule: Dict[str, Any]
return 0
def is_expected_active_tab_approximate(active_tab_info: Dict[str, str], rule: Dict[str, Any]) -> float:
"""
Checks if the expected active tab is open in Chrome, ignoring query parameters in the URL.
"""
if not active_tab_info:
return 0.
match_type = rule['type']
if match_type == "url":
expected_url = rule['url']
if isinstance(active_tab_info, Dict):
actual_url = active_tab_info.get('url', None)
else:
actual_url = active_tab_info
from urllib.parse import urlparse, urlunparse
def strip_query(url):
parsed = urlparse(url)
return urlunparse(parsed._replace(query=""))
if strip_query(expected_url) == strip_query(actual_url):
return 1
else:
return 0
else:
logger.error(f"Unknown type: {match_type}")
return 0
# rules[expected] is a string-formatted regex
def is_expected_url_pattern_match(result, rules) -> float:
"""
@@ -366,7 +394,12 @@ def is_shortcut_on_desktop(shortcuts: Dict[str, str], rule):
for shortcut_path, shortcut_content in shortcuts.items():
if "Name=" + rule['name'] + "\n" in shortcut_content:
return 1.
return 0.
return 0.0
elif rule['type'] == 'exec':
for shortcut_path, shortcut_content in shortcuts.items():
if "Exec=" + rule['exec'] + "\n" in shortcut_content:
return 1.
return 0.0
elif rule['type'] == 'url':
raise TypeError(f"{rule['type']} not support yet!")
elif rule['type'] == 'id':

View File

@@ -322,8 +322,14 @@ def check_direct_json_object(result, rules) -> float:
expected_json = rules["expected"]
for key in expected_json.keys():
expected_value = expected_json.get(key)
if expected_value != result.get(key):
return 0.
if expected_json.get("ignore_list_order", False):
expected_value = sorted(expected_value)
result_value = sorted(result.get(key))
if expected_value != result_value:
return 0.
else:
if expected_value != result.get(key):
return 0.
return 1.0
else:
expected_json = rules["expected"]