66from playwright .sync_api import sync_playwright
77
88from .api .utils import table_api_call
9- from .config import KB_FILEPATH , KB_NAME , WORKFLOWS
9+ from .config import KB_FILEPATH , KB_NAME , EXPECTED_USER_COLUMNS_PATH , WORKFLOWS
1010from .instance import SNowInstance
1111from .utils import ui_login
1212
@@ -277,6 +277,60 @@ def install_workflows():
277277 browser .close ()
278278
279279
280+ def display_all_columns (url : str ):
281+ """Display all columns in a given list view."""
282+ with sync_playwright () as playwright :
283+ instance = SNowInstance ()
284+ browser = playwright .chromium .launch (headless = True , slow_mo = 1000 )
285+ page = browser .new_page ()
286+ ui_login (instance , page )
287+ page .goto (instance .snow_url + url )
288+ frame = page .wait_for_selector ("iframe#gsft_main" ).content_frame ()
289+ frame .get_by_text ("Personalize List" ).click ()
290+ available_columns = frame .get_by_label ("Available" )
291+ available_columns .get_by_role ("option" ).first .click ()
292+ available_columns .get_by_role ("option" ).last .click (modifiers = ["Shift" ])
293+ frame .get_by_text ("Add" ).click ()
294+ frame .click ("#ok_button" )
295+
296+
297+ def check_all_columns_displayed (url : str , expected_columns_path : str ):
298+ """Get the visible columns and checks that all expected columns are displayed."""
299+ with open (expected_columns_path , "r" ) as f :
300+ expected_columns = set (json .load (f ))
301+ with sync_playwright () as playwright :
302+ instance = SNowInstance ()
303+ browser = playwright .chromium .launch (headless = True , slow_mo = 1000 )
304+ page = browser .new_page ()
305+ ui_login (instance , page )
306+ page .goto (instance .snow_url + url )
307+ iframe = page .frame ("gsft_main" )
308+ lst = iframe .locator ("table.data_list_table" )
309+ lst .wait_for ()
310+
311+ # Validate the number of lists on the page
312+ lst = lst .nth (0 )
313+ js_selector = f"gsft_main.GlideList2.get('{ lst .get_attribute ('data-list_id' )} ')"
314+ visible_columns = set (page .evaluate (f"{ js_selector } .fields" ).split ("," ))
315+
316+ # check if expected columns is contained in the visible columns
317+ if not expected_columns .issubset (visible_columns ):
318+ logging .info (
319+ f"Error setting up list at { url } \n Expected { expected_columns } columns, but got { visible_columns } ."
320+ )
321+ return False
322+ logging .info (f"All columns properly displayed for { url } ." )
323+ return True
324+
325+
326+ def setup_list_columns (url : str , expected_columns_path : str ):
327+ """Setup the list view to display the expected number of columns."""
328+ display_all_columns (url )
329+ assert check_all_columns_displayed (
330+ url , expected_columns_path
331+ ), f"Error setting up list columns at { url } "
332+
333+
280334def setup ():
281335 """
282336 Check that WorkArena is installed correctly in the instance.
@@ -285,6 +339,11 @@ def setup():
285339 # XXX: Install workflows first because they may automate some downstream installations
286340 setup_workflows ()
287341 setup_knowledge_base ()
342+ # Setup the user list columns by displaying all columns and checking that the expected number are displayed
343+ setup_list_columns (
344+ "/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" ,
345+ EXPECTED_USER_COLUMNS_PATH ,
346+ )
288347
289348
290349def main ():
0 commit comments