diff --git a/Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py b/Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py index 61ea3025a..638c3a0f4 100644 --- a/Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py +++ b/Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py @@ -67,6 +67,7 @@ { "name": "get performance metrics", "function": "get_performance_metrics", "screenshot": "web" }, { "name": "resize window", "function": "resize_window", "screenshot": "web" }, { "name": "change attribute value", "function": "Change_Attribute_Value", "screenshot": "web" }, + { "name": "capture network log", "function": "capture_network_log", "screenshot": "web" }, ) # yapf: disable module_name = "selenium" diff --git a/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py b/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py index 7559584a0..0e80ef1e6 100644 --- a/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py +++ b/Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py @@ -740,6 +740,8 @@ def chromeheadless(): for key in _prefs: prefs[key] = _prefs[key] options.add_experimental_option('prefs', prefs) + + options.set_capability("goog:loggingPrefs", {"performance": "ALL"}) if remote_host: selenium_driver = webdriver.Remote( @@ -1625,6 +1627,39 @@ def Change_Attribute_Value(step_data): errMsg = "Could not find your element." return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) +@logger +def capture_network_log(step_data): + sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME + try: + global selenium_driver + + def process_browser_log_entry(entry): + response = json.loads(entry["message"])["message"] + return response + + variable_name = None + mode = None + for left, _, right in step_data: + if left.lower().strip() == "capture network log": + mode = right.lower().strip() + if left.lower().strip() == "save": + variable_name = right.lower().strip() + if not mode or ( mode == 'stop' and variable_name == None): + CommonUtil.ExecLog(sModuleInfo, "Wrong data set provided.", 3) + return "zeuz_failed" + + if mode == 'start': + selenium_driver.get_log("performance") + CommonUtil.ExecLog(sModuleInfo, "Started collecting network logs", 1 ) + if mode == 'stop': + browser_log = selenium_driver.get_log("performance") + events = [process_browser_log_entry(entry) for entry in browser_log] + Shared_Resources.Set_Shared_Variables(variable_name, events) + return "passed" + except Exception: + errMsg = "Could not collect network logs. Make sure logging is enabled at browser startup" + return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg) + # Method to enter texts in a text box; step data passed on by the user @logger def Enter_Text_In_Text_Box(step_data):