add new examples for chrome

This commit is contained in:
Jason Lee
2024-02-18 22:11:16 +08:00
parent 66304b3bab
commit 17cd897780
12 changed files with 333 additions and 16 deletions

View File

@@ -15,7 +15,8 @@ from .chrome import (
check_font_size,
check_enabled_experiments,
check_history_deleted,
is_expected_search_query
is_expected_search_query,
is_expected_active_tab
)
from .docs import (
compare_font_names,
@@ -53,6 +54,7 @@ from .general import (
check_json,
check_list,
exact_match,
is_in_list,
fuzzy_match,
check_include_exclude
)

View File

@@ -9,6 +9,22 @@ from desktop_env.evaluators.metrics.utils import are_lists_equal, compare_urls
logger = logging.getLogger("desktopenv.metrics.chrome")
def is_expected_active_tab(active_tab_info: Dict[str, str], rule: Dict[str, Any]) -> float:
"""
Checks if the expected active tab is open in Chrome.
"""
match_type = rule['type']
if match_type == "url":
expected_url = rule['url']
actual_url = active_tab_info['url']
print("expected_url: {}".format(expected_url))
print("actual_url: {}".format(actual_url))
return 1 if compare_urls(expected_url, actual_url) else 0
else:
logger.error(f"Unknown type: {match_type}")
return 0
def is_expected_tabs(open_tabs: List[Dict[str, str]], rule: Dict[str, Any]) -> float:
"""
Checks if the expected tabs are open in Chrome.

View File

@@ -38,7 +38,13 @@ def exact_match(result, rules) -> float:
else:
return 0.
def is_in_list(result, rules) -> float:
expect = rules["expected"]
if expect in result:
return 1.
else:
return 0.
def fuzzy_match(result, rules) -> float:
expect = rules["expected"]