Skip to content

Commit c64a433

Browse files
committed
enable network capturing
Build action for start and stop
1 parent 56220e9 commit c64a433

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,8 @@ def chromeheadless():
740740
for key in _prefs:
741741
prefs[key] = _prefs[key]
742742
options.add_experimental_option('prefs', prefs)
743+
744+
options.set_capability("goog:loggingPrefs", {"performance": "ALL"})
743745

744746
if remote_host:
745747
selenium_driver = webdriver.Remote(
@@ -1625,6 +1627,39 @@ def Change_Attribute_Value(step_data):
16251627
errMsg = "Could not find your element."
16261628
return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
16271629

1630+
@logger
1631+
def capture_network_log(step_data):
1632+
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
1633+
try:
1634+
global selenium_driver
1635+
1636+
def process_browser_log_entry(entry):
1637+
response = json.loads(entry["message"])["message"]
1638+
return response
1639+
1640+
variable_name = None
1641+
mode = None
1642+
for left, _, right in step_data:
1643+
if left.lower().strip() == "capture network log":
1644+
mode = right.lower().strip()
1645+
if left.lower().strip() == "save":
1646+
variable_name = right.lower().strip()
1647+
if not mode or ( mode == 'stop' and variable_name == None):
1648+
CommonUtil.ExecLog(sModuleInfo, "Wrong data set provided.", 3)
1649+
return "zeuz_failed"
1650+
1651+
if mode == 'start':
1652+
selenium_driver.get_log("performance")
1653+
CommonUtil.ExecLog(sModuleInfo, "Started collecting network logs", 1 )
1654+
if mode == 'stop':
1655+
browser_log = selenium_driver.get_log("performance")
1656+
events = [process_browser_log_entry(entry) for entry in browser_log]
1657+
Shared_Resources.Set_Shared_Variables(variable_name, events)
1658+
return "passed"
1659+
except Exception:
1660+
errMsg = "Could not collect network logs. Make sure logging is enabled at browser startup"
1661+
return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
1662+
16281663
# Method to enter texts in a text box; step data passed on by the user
16291664
@logger
16301665
def Enter_Text_In_Text_Box(step_data):

0 commit comments

Comments
 (0)