Merge branch 'main' of github.com:xlang-ai/OSWorld

This commit is contained in:
yuanmengqi
2025-07-10 22:35:42 +00:00
8 changed files with 35 additions and 10 deletions

View File

@@ -115,6 +115,11 @@ def is_expected_tabs(open_tabs: List[Dict[str, str]], rule: Dict[str, Any]) -> f
if match_type == "url":
expected_urls = rule['urls']
actual_urls = [tab['url'] for tab in open_tabs]
if not are_lists_equal(expected_urls, actual_urls, compare_urls):
logger.error("list not match")
logger.error(expected_urls)
logger.error(actual_urls)
return 0
return 1 if are_lists_equal(expected_urls, actual_urls, compare_urls) else 0
else:
logger.error(f"Unknown type: {match_type}")
@@ -343,7 +348,7 @@ def compare_archive(pred_path: str, gold_path: str, **kwargs) -> float:
return score / len(pred_files)
def compare_htmls(html_path1: str, html_path2: str) -> float:
def compare_htmls(html_path1: str, html_path2: str, **options) -> float:
"""
Compare two HTML files.
"""
@@ -351,20 +356,33 @@ def compare_htmls(html_path1: str, html_path2: str) -> float:
soup1 = BeautifulSoup(inf, 'lxml')
with open(html_path2, 'r', encoding='utf-8') as inf:
soup2 = BeautifulSoup(inf, 'lxml')
ignore_sdnum = options.get("ignore_sdnum", None)
def compare_elements(elem1, elem2):
if not (isinstance(elem1, Tag) and isinstance(elem2, Tag)):
if elem1 != elem2:
logger.info("not the same")
return elem1 == elem2
if elem1.name != elem2.name:
logger.info("html name not match")
return False
if elem1.text.strip() != elem2.text.strip():
logger.info("html text not match")
return False
if elem1.attrs != elem2.attrs:
if ignore_sdnum:
attrs1 = {k: v for k, v in elem1.attrs.items() if k != 'sdnum'}
attrs2 = {k: v for k, v in elem2.attrs.items() if k != 'sdnum'}
return attrs1 == attrs2
logger.info("html attrs not match")
logger.info(f"{elem1.attrs}")
logger.info(f"{elem2.attrs}")
return False
return True
for elem1, elem2 in zip(soup1.recursiveChildGenerator(), soup2.recursiveChildGenerator()):
if not compare_elements(elem1, elem2):
logger.info("html not match")
return .0
return 1.

View File

@@ -213,7 +213,6 @@ _accessibility_ns_map = {
}
def check_accessibility_tree(result: str, rules: List[Dict[str, Any]], osname: str = "ubuntu") -> float:
"""
Args: