Skip to content

Commit

Permalink
rc5
Browse files Browse the repository at this point in the history
  • Loading branch information
gasse committed Mar 18, 2024
1 parent 2c46918 commit 5ff3a8e
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 6 deletions.
Binary file removed banner.png
Binary file not shown.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
browsergym-core==0.1.0rc4
browsergym-core==0.1.0rc5
english-words>=2.0.1
numpy>=1.14
requests>=2.31
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/browsergym/workarena/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.1.0rc4"
__version__ = "0.1.0rc5"

from browsergym.core.registration import register_task

Expand Down
11 changes: 9 additions & 2 deletions src/browsergym/workarena/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

# Knowledge base that is included with the benchmark
KB_NAME = "General Knowledge"
KB_FILEPATH = str(resources.files(data_files).joinpath("knowledge_base.json"))
KB_FILEPATH = str(resources.files(data_files).joinpath("setup_files/knowledge_base.json"))

# Form tasks
CREATE_CHANGE_REQUEST_CONFIG_PATH = str(
Expand Down Expand Up @@ -112,6 +112,13 @@
WORKFLOWS = {
"kb_publish": {
"name": "WorkArena Auto-Publish",
"update_set": str(resources.files(data_files).joinpath("kb_autopublish_workflow.xml")),
"update_set": str(
resources.files(data_files).joinpath("setup_files/kb_autopublish_workflow.xml")
),
}
}

# Number of columns in the user list; used for setup
EXPECTED_USER_COLUMNS_PATH = str(
resources.files(data_files).joinpath("setup_files/expected_user_columns.json")
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[
"user_name",
"name",
"email",
"active",
"sys_created_on",
"sys_updated_on",
"avatar",
"building",
"phone",
"calendar_integration",
"city",
"sys_class_name",
"company",
"cost_center",
"country",
"sys_created_by",
"date_format",
"default_perspective",
"department",
"sys_domain",
"sys_domain_path",
"employee_number",
"enable_multifactor_authn",
"failed_attempts",
"first_name",
"gender",
"home_phone",
"internal_integration_user",
"ldap_server",
"preferred_language",
"last_login",
"last_login_time",
"last_name",
"location",
"locked_out",
"manager",
"middle_name",
"mobile_phone",
"notification",
"user_password",
"password_needs_reset",
"photo",
"introduction",
"roles",
"schedule",
"source",
"state",
"street",
"sys_tags",
"time_format",
"time_zone",
"title",
"sys_updated_by",
"sys_mod_count",
"vip",
"web_service_access_only",
"zip"
]
61 changes: 60 additions & 1 deletion src/browsergym/workarena/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from playwright.sync_api import sync_playwright

from .api.utils import table_api_call
from .config import KB_FILEPATH, KB_NAME, WORKFLOWS
from .config import KB_FILEPATH, KB_NAME, EXPECTED_USER_COLUMNS_PATH, WORKFLOWS
from .instance import SNowInstance
from .utils import ui_login

Expand Down Expand Up @@ -277,6 +277,60 @@ def install_workflows():
browser.close()


def display_all_columns(url: str):
"""Display all columns in a given list view."""
with sync_playwright() as playwright:
instance = SNowInstance()
browser = playwright.chromium.launch(headless=True, slow_mo=1000)
page = browser.new_page()
ui_login(instance, page)
page.goto(instance.snow_url + url)
frame = page.wait_for_selector("iframe#gsft_main").content_frame()
frame.get_by_text("Personalize List").click()
available_columns = frame.get_by_label("Available")
available_columns.get_by_role("option").first.click()
available_columns.get_by_role("option").last.click(modifiers=["Shift"])
frame.get_by_text("Add").click()
frame.click("#ok_button")


def check_all_columns_displayed(url: str, expected_columns_path: str):
"""Get the visible columns and checks that all expected columns are displayed."""
with open(expected_columns_path, "r") as f:
expected_columns = set(json.load(f))
with sync_playwright() as playwright:
instance = SNowInstance()
browser = playwright.chromium.launch(headless=True, slow_mo=1000)
page = browser.new_page()
ui_login(instance, page)
page.goto(instance.snow_url + url)
iframe = page.frame("gsft_main")
lst = iframe.locator("table.data_list_table")
lst.wait_for()

# Validate the number of lists on the page
lst = lst.nth(0)
js_selector = f"gsft_main.GlideList2.get('{lst.get_attribute('data-list_id')}')"
visible_columns = set(page.evaluate(f"{js_selector}.fields").split(","))

# check if expected columns is contained in the visible columns
if not expected_columns.issubset(visible_columns):
logging.info(
f"Error setting up list at {url} \n Expected {expected_columns} columns, but got {visible_columns}."
)
return False
logging.info(f"All columns properly displayed for {url}.")
return True


def setup_list_columns(url: str, expected_columns_path: str):
"""Setup the list view to display the expected number of columns."""
display_all_columns(url)
assert check_all_columns_displayed(
url, expected_columns_path
), f"Error setting up list columns at {url}"


def setup():
"""
Check that WorkArena is installed correctly in the instance.
Expand All @@ -285,6 +339,11 @@ def setup():
# XXX: Install workflows first because they may automate some downstream installations
setup_workflows()
setup_knowledge_base()
# Setup the user list columns by displaying all columns and checking that the expected number are displayed
setup_list_columns(
"/now/nav/ui/classic/params/target/sys_user_list.do%3Fsysparm_view%3D%26sysparm_userpref.sys_user_list.view%3D%26sysparm_userpref.sys_user.view%3D%26sysparm_query%3Dactive%253Dtrue%255Ecompany%253D81fd65ecac1d55eb42a426568fc87a63",
EXPECTED_USER_COLUMNS_PATH,
)


def main():
Expand Down
2 changes: 1 addition & 1 deletion src/browsergym/workarena/tasks/knowledge.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class KnowledgeBaseSearchTask(AbstractServiceNowTask):
def __init__(self, instance=None, fixed_config: dict = None) -> None:
super().__init__(
instance=instance,
start_rel_url="/now/nav/ui/classic/params/target/knowledge_home_launcher.do",
start_rel_url="/now/nav/ui/classic/params/target/%24knowledge.do",
)

# Load the knowledge base and check its integrity
Expand Down

0 comments on commit 5ff3a8e

Please sign in to comment.