Skip to content

Commit 28cf600

Browse files
Merge pull request #467 from AutomationSolutionz/captre-networks
Capture network traffics
2 parents d58fa24 + 6d71067 commit 28cf600

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Framework/Built_In_Automation/Sequential_Actions/action_declarations/selenium.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
{ "name": "get performance metrics", "function": "get_performance_metrics", "screenshot": "web" },
6868
{ "name": "resize window", "function": "resize_window", "screenshot": "web" },
6969
{ "name": "change attribute value", "function": "Change_Attribute_Value", "screenshot": "web" },
70+
{ "name": "capture network log", "function": "capture_network_log", "screenshot": "web" },
7071
) # yapf: disable
7172

7273
module_name = "selenium"

Framework/Built_In_Automation/Web/Selenium/BuiltInFunctions.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ def chromeheadless():
738738
for key in _prefs:
739739
prefs[key] = _prefs[key]
740740
options.add_experimental_option('prefs', prefs)
741+
742+
options.set_capability("goog:loggingPrefs", {"performance": "ALL"})
741743

742744
if remote_host:
743745
selenium_driver = webdriver.Remote(
@@ -1623,6 +1625,39 @@ def Change_Attribute_Value(step_data):
16231625
errMsg = "Could not find your element."
16241626
return CommonUtil.Exception_Handler(sys.exc_info(), None, errMsg)
16251627

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

0 commit comments

Comments
 (0)