finish the rest part of chrome examples and verify them on mac arm64
This commit is contained in:
@@ -16,7 +16,8 @@ from .chrome import (
|
||||
check_enabled_experiments,
|
||||
check_history_deleted,
|
||||
is_expected_search_query,
|
||||
is_expected_active_tab
|
||||
is_expected_active_tab,
|
||||
is_expected_url_pattern_match
|
||||
)
|
||||
from .docs import (
|
||||
compare_font_names,
|
||||
@@ -54,7 +55,8 @@ from .general import (
|
||||
exact_match,
|
||||
is_in_list,
|
||||
fuzzy_match,
|
||||
check_include_exclude
|
||||
check_include_exclude,
|
||||
check_direct_json_object
|
||||
)
|
||||
from .gimp import (
|
||||
check_brightness_decrease_and_structure_sim,
|
||||
|
||||
@@ -25,6 +25,27 @@ def is_expected_active_tab(active_tab_info: Dict[str, str], rule: Dict[str, Any]
|
||||
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:
|
||||
"""
|
||||
This function is used to search the expected pattern in the url using regex.
|
||||
result is the return value of function "activte_tab_info" or return value of function "get_active_url_from_accessTree"
|
||||
"""
|
||||
if type(result)== dict:
|
||||
result_url = result["url"]
|
||||
print("result url: {}".format(result_url))
|
||||
else:
|
||||
result_url = result
|
||||
# expect_regex = re.compile(rules["expected"])
|
||||
patterns = rules["expected"]
|
||||
print("expected_regex: {}".format(patterns))
|
||||
for pattern in patterns:
|
||||
match = re.search(pattern, result_url)
|
||||
print(match)
|
||||
if not match:
|
||||
return 0.
|
||||
return 1.
|
||||
|
||||
def is_expected_tabs(open_tabs: List[Dict[str, str]], rule: Dict[str, Any]) -> float:
|
||||
"""
|
||||
Checks if the expected tabs are open in Chrome.
|
||||
|
||||
@@ -44,7 +44,9 @@ def is_in_list(result, rules) -> float:
|
||||
return 1.
|
||||
else:
|
||||
return 0.
|
||||
|
||||
|
||||
|
||||
|
||||
def fuzzy_match(result, rules) -> float:
|
||||
expect = rules["expected"]
|
||||
|
||||
@@ -135,7 +137,7 @@ def check_accessibility_tree(result: str, rules: Dict[str, Any]) -> float:
|
||||
needed. If both are present, `xpath` takes the priority.
|
||||
"text": str as the expected text content of the selected element.
|
||||
"exact": bool specifying whether exact match or fuzzy match should
|
||||
be performed. defaults to True
|
||||
be performed. defaults to True.
|
||||
}
|
||||
|
||||
Returns:
|
||||
@@ -152,6 +154,7 @@ def check_accessibility_tree(result: str, rules: Dict[str, Any]) -> float:
|
||||
raise ValueError("At least one of xpath and selectors is required")
|
||||
|
||||
if len(elements) == 0:
|
||||
print("no elements")
|
||||
return 0.
|
||||
|
||||
if "text" in rules:
|
||||
@@ -217,3 +220,19 @@ def check_json(result: str, rules: Dict[str, List[Dict[str, Union[List[str], str
|
||||
value = value[k]
|
||||
metric = metric and not _match_value_to_rule(value, r)
|
||||
return metric
|
||||
|
||||
|
||||
def check_direct_json_object(result, rules)->float:
|
||||
"""
|
||||
One of the most commonly used function to evalute.
|
||||
Compare two json objects directly.
|
||||
"""
|
||||
print("result: ")
|
||||
print(result)
|
||||
print("expected: ")
|
||||
print(rules["expected"])
|
||||
expected_json = rules["expected"]
|
||||
for key in expected_json.keys():
|
||||
if expected_json[key] != result[key]:
|
||||
return 0.
|
||||
return 1.0
|
||||
Reference in New Issue
Block a user