How to use tracing method in Playwright Python

Best Python code snippet using playwright-python

chrome_tracing_agent_unittest.py

Source:chrome_tracing_agent_unittest.py Github

copy

Full Screen

1# Copyright 2014 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import os5import platform6import stat7import unittest8from telemetry import decorators9from telemetry.internal.platform.tracing_agent import chrome_tracing_agent10from telemetry.internal.platform.tracing_agent import (11 chrome_tracing_devtools_manager)12from telemetry.timeline import tracing_config13from telemetry.core import cros_interface14from telemetry.testing import options_for_unittests15from devil.android import device_utils16class FakeTracingControllerBackend(object):17 def __init__(self):18 self.is_tracing_running = False19class FakePlatformBackend(object):20 def __init__(self):21 self.tracing_controller_backend = FakeTracingControllerBackend()22 def GetOSName(self):23 return ''24class FakeAndroidPlatformBackend(FakePlatformBackend):25 def __init__(self):26 super(FakeAndroidPlatformBackend, self).__init__()27 devices = device_utils.DeviceUtils.HealthyDevices(None)28 self.device = devices[0]29 def GetOSName(self):30 return 'android'31class FakeCrOSPlatformBackend(FakePlatformBackend):32 def __init__(self):33 super(FakeCrOSPlatformBackend, self).__init__()34 remote = options_for_unittests.GetCopy().cros_remote35 remote_ssh_port = options_for_unittests.GetCopy().cros_remote_ssh_port36 self.cri = cros_interface.CrOSInterface(37 remote, remote_ssh_port,38 options_for_unittests.GetCopy().cros_ssh_identity)39 def GetOSName(self):40 return 'chromeos'41class FakeDesktopPlatformBackend(FakePlatformBackend):42 def GetOSName(self):43 system = platform.system()44 if system == 'Linux':45 return 'linux'46 if system == 'Darwin':47 return 'mac'48 if system == 'Windows':49 return 'win'50class FakeContextMap(object):51 def __init__(self, contexts):52 self.contexts = contexts53class FakeDevtoolsClient(object):54 def __init__(self, remote_port):55 self.is_alive = True56 self.is_tracing_running = False57 self.remote_port = remote_port58 self.will_raise_exception_in_stop_tracing = False59 self.collected = False60 def IsAlive(self):61 return self.is_alive62 def StartChromeTracing(self, trace_options, timeout=10):63 del trace_options, timeout # unused64 self.is_tracing_running = True65 def StopChromeTracing(self):66 self.is_tracing_running = False67 if self.will_raise_exception_in_stop_tracing:68 raise Exception69 def CollectChromeTracingData(self, trace_data_builder, timeout=30):70 del trace_data_builder # unused71 del timeout # unused72 self.collected = True73 def IsChromeTracingSupported(self):74 return True75 def GetUpdatedInspectableContexts(self):76 return FakeContextMap([])77class ChromeTracingAgentTest(unittest.TestCase):78 def setUp(self):79 self.platform1 = FakePlatformBackend()80 self.platform2 = FakePlatformBackend()81 self.platform3 = FakePlatformBackend()82 def StartTracing(self, platform_backend, enable_chrome_trace=True):83 assert chrome_tracing_agent.ChromeTracingAgent.IsSupported(platform_backend)84 agent = chrome_tracing_agent.ChromeTracingAgent(platform_backend)85 config = tracing_config.TracingConfig()86 config.enable_chrome_trace = enable_chrome_trace87 config.chrome_trace_config.category_filter.AddIncludedCategory('foo')88 agent._platform_backend.tracing_controller_backend.is_tracing_running = True89 agent._test_config = config90 agent.StartAgentTracing(config, 10)91 return agent92 def FlushTracing(self, agent):93 agent.FlushAgentTracing(agent._test_config, 10, None)94 def StopTracing(self, agent):95 agent._platform_backend.tracing_controller_backend.is_tracing_running = (96 False)97 agent.StopAgentTracing()98 agent.CollectAgentTraceData(None)99 def testRegisterDevtoolsClient(self):100 chrome_tracing_devtools_manager.RegisterDevToolsClient(101 FakeDevtoolsClient(1), self.platform1)102 chrome_tracing_devtools_manager.RegisterDevToolsClient(103 FakeDevtoolsClient(2), self.platform1)104 chrome_tracing_devtools_manager.RegisterDevToolsClient(105 FakeDevtoolsClient(3), self.platform1)106 tracing_agent_of_platform1 = self.StartTracing(self.platform1)107 chrome_tracing_devtools_manager.RegisterDevToolsClient(108 FakeDevtoolsClient(4), self.platform1)109 chrome_tracing_devtools_manager.RegisterDevToolsClient(110 FakeDevtoolsClient(5), self.platform2)111 self.StopTracing(tracing_agent_of_platform1)112 chrome_tracing_devtools_manager.RegisterDevToolsClient(113 FakeDevtoolsClient(6), self.platform1)114 def testIsSupportWithoutStartupTracingSupport(self):115 self.assertFalse(116 chrome_tracing_agent.ChromeTracingAgent.IsSupported(self.platform1))117 self.assertFalse(118 chrome_tracing_agent.ChromeTracingAgent.IsSupported(self.platform2))119 self.assertFalse(120 chrome_tracing_agent.ChromeTracingAgent.IsSupported(self.platform3))121 devtool1 = FakeDevtoolsClient(1)122 devtool2 = FakeDevtoolsClient(2)123 chrome_tracing_devtools_manager.RegisterDevToolsClient(124 devtool1, self.platform1)125 chrome_tracing_devtools_manager.RegisterDevToolsClient(126 devtool2, self.platform2)127 devtool2.is_alive = False128 # Chrome tracing is only supported on platform 1 since only platform 1 has129 # an alive devtool.130 self.assertTrue(131 chrome_tracing_agent.ChromeTracingAgent.IsSupported(self.platform1))132 self.assertFalse(133 chrome_tracing_agent.ChromeTracingAgent.IsSupported(self.platform2))134 self.assertFalse(135 chrome_tracing_agent.ChromeTracingAgent.IsSupported(self.platform3))136 @decorators.Enabled('linux', 'mac', 'win')137 def testIsSupportOnDesktopPlatform(self):138 # Chrome tracing is always supported on desktop platforms because of startup139 # tracing.140 desktop_platform = FakeDesktopPlatformBackend()141 self.assertTrue(142 chrome_tracing_agent.ChromeTracingAgent.IsSupported(desktop_platform))143 devtool = FakeDevtoolsClient(1)144 chrome_tracing_devtools_manager.RegisterDevToolsClient(145 devtool, desktop_platform)146 self.assertTrue(147 chrome_tracing_agent.ChromeTracingAgent.IsSupported(desktop_platform))148 def testStartAndStopTracing(self):149 devtool1 = FakeDevtoolsClient(1)150 devtool2 = FakeDevtoolsClient(2)151 devtool3 = FakeDevtoolsClient(3)152 devtool4 = FakeDevtoolsClient(2)153 # Register devtools 1, 2, 3 on platform1 and devtool 4 on platform 2154 chrome_tracing_devtools_manager.RegisterDevToolsClient(155 devtool1, self.platform1)156 chrome_tracing_devtools_manager.RegisterDevToolsClient(157 devtool2, self.platform1)158 chrome_tracing_devtools_manager.RegisterDevToolsClient(159 devtool3, self.platform1)160 chrome_tracing_devtools_manager.RegisterDevToolsClient(161 devtool4, self.platform2)162 devtool2.is_alive = False163 tracing_agent1 = self.StartTracing(self.platform1)164 with self.assertRaises(chrome_tracing_agent.ChromeTracingStartedError):165 self.StartTracing(self.platform1)166 self.assertTrue(devtool1.is_tracing_running)167 self.assertFalse(devtool2.is_tracing_running)168 self.assertTrue(devtool3.is_tracing_running)169 # Devtool 4 shouldn't have tracing started although it has the same remote170 # port as devtool 2171 self.assertFalse(devtool4.is_tracing_running)172 self.assertFalse(devtool1.collected)173 self.StopTracing(tracing_agent1)174 self.assertTrue(devtool1.collected)175 self.assertFalse(devtool1.is_tracing_running)176 self.assertFalse(devtool2.is_tracing_running)177 self.assertFalse(devtool3.is_tracing_running)178 self.assertFalse(devtool4.is_tracing_running)179 # Test that it should be ok to start & stop tracing on platform1 again.180 tracing_agent1 = self.StartTracing(self.platform1)181 self.StopTracing(tracing_agent1)182 tracing_agent2 = self.StartTracing(self.platform2)183 self.assertTrue(devtool4.is_tracing_running)184 self.assertFalse(devtool4.collected)185 self.StopTracing(tracing_agent2)186 self.assertFalse(devtool4.is_tracing_running)187 self.assertTrue(devtool4.collected)188 def testFlushTracing(self):189 devtool1 = FakeDevtoolsClient(1)190 devtool2 = FakeDevtoolsClient(2)191 devtool3 = FakeDevtoolsClient(3)192 devtool4 = FakeDevtoolsClient(2)193 # Register devtools 1, 2, 3 on platform1 and devtool 4 on platform 2.194 chrome_tracing_devtools_manager.RegisterDevToolsClient(195 devtool1, self.platform1)196 chrome_tracing_devtools_manager.RegisterDevToolsClient(197 devtool2, self.platform1)198 chrome_tracing_devtools_manager.RegisterDevToolsClient(199 devtool3, self.platform1)200 chrome_tracing_devtools_manager.RegisterDevToolsClient(201 devtool4, self.platform2)202 devtool2.is_alive = False203 tracing_agent1 = self.StartTracing(self.platform1)204 self.assertTrue(devtool1.is_tracing_running)205 self.assertFalse(devtool2.is_tracing_running)206 self.assertTrue(devtool3.is_tracing_running)207 # Devtool 4 shouldn't have tracing started although it has the same remote208 # port as devtool 2.209 self.assertFalse(devtool4.is_tracing_running)210 for _ in xrange(5):211 self.FlushTracing(tracing_agent1)212 self.assertTrue(devtool1.is_tracing_running)213 self.assertFalse(devtool2.is_tracing_running)214 self.assertTrue(devtool3.is_tracing_running)215 self.assertFalse(devtool4.is_tracing_running)216 self.StopTracing(tracing_agent1)217 self.assertFalse(devtool1.is_tracing_running)218 self.assertFalse(devtool2.is_tracing_running)219 self.assertFalse(devtool3.is_tracing_running)220 self.assertFalse(devtool4.is_tracing_running)221 # Test that it is ok to start, flush & stop tracing on platform1 again.222 tracing_agent1 = self.StartTracing(self.platform1)223 self.FlushTracing(tracing_agent1)224 self.StopTracing(tracing_agent1)225 tracing_agent2 = self.StartTracing(self.platform2)226 self.assertTrue(devtool4.is_tracing_running)227 self.FlushTracing(tracing_agent2)228 self.assertTrue(devtool4.is_tracing_running)229 self.StopTracing(tracing_agent2)230 self.assertFalse(devtool4.is_tracing_running)231 def testExceptionRaisedInStopTracing(self):232 devtool1 = FakeDevtoolsClient(1)233 devtool2 = FakeDevtoolsClient(2)234 # Register devtools 1, 2 on platform 1235 chrome_tracing_devtools_manager.RegisterDevToolsClient(236 devtool1, self.platform1)237 chrome_tracing_devtools_manager.RegisterDevToolsClient(238 devtool2, self.platform1)239 tracing_agent1 = self.StartTracing(self.platform1)240 self.assertTrue(devtool1.is_tracing_running)241 self.assertTrue(devtool2.is_tracing_running)242 devtool1.will_raise_exception_in_stop_tracing = True243 with self.assertRaises(chrome_tracing_agent.ChromeTracingStoppedError):244 self.StopTracing(tracing_agent1)245 # Tracing is stopped on both devtools clients even if there is exception.246 self.assertIsNone(tracing_agent1.trace_config)247 self.assertFalse(devtool1.is_tracing_running)248 self.assertFalse(devtool2.is_tracing_running)249 devtool1.is_alive = False250 devtool2.is_alive = False251 # Register devtools 3 on platform 1 should not raise any exception.252 devtool3 = FakeDevtoolsClient(3)253 chrome_tracing_devtools_manager.RegisterDevToolsClient(254 devtool3, self.platform1)255 # Start & Stop tracing on platform 1 should work just fine.256 tracing_agent2 = self.StartTracing(self.platform1)257 self.StopTracing(tracing_agent2)258 @decorators.Enabled('android')259 def testCreateAndRemoveTraceConfigFileOnAndroid(self):260 platform_backend = FakeAndroidPlatformBackend()261 agent = chrome_tracing_agent.ChromeTracingAgent(platform_backend)262 self.assertIsNone(agent.trace_config_file)263 config = tracing_config.TracingConfig()264 agent._CreateTraceConfigFile(config)265 self.assertIsNotNone(agent.trace_config_file)266 self.assertTrue(platform_backend.device.PathExists(agent.trace_config_file))267 config_file_str = platform_backend.device.ReadFile(agent.trace_config_file,268 as_root=True)269 self.assertEqual(agent._CreateTraceConfigFileString(config),270 config_file_str.strip())271 config_file_path = agent.trace_config_file272 agent._RemoveTraceConfigFile()273 self.assertFalse(platform_backend.device.PathExists(config_file_path))274 self.assertIsNone(agent.trace_config_file)275 # robust to multiple file removal276 agent._RemoveTraceConfigFile()277 self.assertFalse(platform_backend.device.PathExists(config_file_path))278 self.assertIsNone(agent.trace_config_file)279 @decorators.Enabled('chromeos')280 def testCreateAndRemoveTraceConfigFileOnCrOS(self):281 platform_backend = FakeCrOSPlatformBackend()282 cri = platform_backend.cri283 agent = chrome_tracing_agent.ChromeTracingAgent(platform_backend)284 self.assertIsNone(agent.trace_config_file)285 config = tracing_config.TracingConfig()286 agent._CreateTraceConfigFile(config)287 self.assertIsNotNone(agent.trace_config_file)288 self.assertTrue(cri.FileExistsOnDevice(agent.trace_config_file))289 config_file_str = cri.GetFileContents(agent.trace_config_file)290 self.assertEqual(agent._CreateTraceConfigFileString(config),291 config_file_str.strip())292 config_file_path = agent.trace_config_file293 agent._RemoveTraceConfigFile()294 self.assertFalse(cri.FileExistsOnDevice(config_file_path))295 self.assertIsNone(agent.trace_config_file)296 # robust to multiple file removal297 agent._RemoveTraceConfigFile()298 self.assertFalse(cri.FileExistsOnDevice(config_file_path))299 self.assertIsNone(agent.trace_config_file)300 @decorators.Enabled('linux', 'mac', 'win')301 def testCreateAndRemoveTraceConfigFileOnDesktop(self):302 platform_backend = FakeDesktopPlatformBackend()303 agent = chrome_tracing_agent.ChromeTracingAgent(platform_backend)304 self.assertIsNone(agent.trace_config_file)305 config = tracing_config.TracingConfig()306 agent._CreateTraceConfigFile(config)307 self.assertIsNotNone(agent.trace_config_file)308 self.assertTrue(os.path.exists(agent.trace_config_file))309 self.assertTrue(os.stat(agent.trace_config_file).st_mode & stat.S_IROTH)310 with open(agent.trace_config_file, 'r') as f:311 config_file_str = f.read()312 self.assertEqual(agent._CreateTraceConfigFileString(config),313 config_file_str.strip())314 config_file_path = agent.trace_config_file315 agent._RemoveTraceConfigFile()316 self.assertFalse(os.path.exists(config_file_path))317 self.assertIsNone(agent.trace_config_file)318 # robust to multiple file removal319 agent._RemoveTraceConfigFile()320 self.assertFalse(os.path.exists(config_file_path))...

Full Screen

Full Screen

tracing_controller.py

Source:tracing_controller.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright 2016 The Chromium Authors. All rights reserved.3# Use of this source code is governed by a BSD-style license that can be4# found in the LICENSE file.5'''Tracing controller class. This class manages6multiple tracing agents and collects data from all of them. It also7manages the clock sync process.8'''9import ast10import json11import sys12import tempfile13import uuid14import py_utils15from systrace import trace_result16from systrace import tracing_agents17from py_trace_event import trace_event18TRACE_DATA_CONTROLLER_NAME = 'systraceController'19def ControllerAgentClockSync(issue_ts, name):20 """Record the clock sync marker for controller tracing agent.21 Unlike with the other tracing agents, the tracing controller should not22 call this directly. Rather, it is called via callback from the other23 tracing agents when they write a trace.24 """25 trace_event.clock_sync(name, issue_ts=issue_ts)26class TracingControllerAgent(tracing_agents.TracingAgent):27 def __init__(self):28 super(TracingControllerAgent, self).__init__()29 self._log_path = None30 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT)31 def StartAgentTracing(self, config, timeout=None):32 """Start tracing for the controller tracing agent.33 Start tracing for the controller tracing agent. Note that34 the tracing controller records the "controller side"35 of the clock sync records, and nothing else.36 """37 del config38 if not trace_event.trace_can_enable():39 raise RuntimeError, ('Cannot enable trace_event;'40 ' ensure py_utils is in PYTHONPATH')41 controller_log_file = tempfile.NamedTemporaryFile(delete=False)42 self._log_path = controller_log_file.name43 controller_log_file.close()44 trace_event.trace_enable(self._log_path)45 return True46 @py_utils.Timeout(tracing_agents.START_STOP_TIMEOUT)47 def StopAgentTracing(self, timeout=None):48 """Stops tracing for the controller tracing agent.49 """50 # pylint: disable=no-self-use51 # This function doesn't use self, but making it a member function52 # for consistency with the other TracingAgents53 trace_event.trace_disable()54 return True55 @py_utils.Timeout(tracing_agents.GET_RESULTS_TIMEOUT)56 def GetResults(self, timeout=None):57 """Gets the log output from the controller tracing agent.58 This output only contains the "controller side" of the clock sync records.59 """60 with open(self._log_path, 'r') as outfile:61 data = ast.literal_eval(outfile.read() + ']')62 # Explicitly set its own clock domain. This will stop the Systrace clock63 # domain from incorrectly being collapsed into the on device clock domain.64 formatted_data = {65 'traceEvents': data,66 'metadata': {67 'clock-domain': 'SYSTRACE',68 }69 }70 return trace_result.TraceResult(TRACE_DATA_CONTROLLER_NAME,71 json.dumps(formatted_data))72 def SupportsExplicitClockSync(self):73 """Returns whether this supports explicit clock sync.74 Although the tracing controller conceptually supports explicit clock75 sync, it is not an agent controlled by other controllers so it does not76 define RecordClockSyncMarker (rather, the recording of the "controller77 side" of the clock sync marker is done in _IssueClockSyncMarker). Thus,78 SupportsExplicitClockSync must return false.79 """80 return False81 # pylint: disable=unused-argument82 def RecordClockSyncMarker(self, sync_id, callback):83 raise NotImplementedError84class TracingController(object):85 def __init__(self, agents_with_config, controller_config):86 """Create tracing controller.87 Create a tracing controller object. Note that the tracing88 controller is also a tracing agent.89 Args:90 agents_with_config: List of tracing agents for this controller with the91 corresponding tracing configuration objects.92 controller_config: Configuration options for the tracing controller.93 """94 self._child_agents = None95 self._child_agents_with_config = agents_with_config96 self._controller_agent = TracingControllerAgent()97 self._controller_config = controller_config98 self._trace_in_progress = False99 self.all_results = None100 @property101 def get_child_agents(self):102 return self._child_agents103 def StartTracing(self):104 """Start tracing for all tracing agents.105 This function starts tracing for both the controller tracing agent106 and the child tracing agents.107 Returns:108 Boolean indicating whether or not the start tracing succeeded.109 Start tracing is considered successful if at least the110 controller tracing agent was started.111 """112 assert not self._trace_in_progress, 'Trace already in progress.'113 self._trace_in_progress = True114 # Start the controller tracing agents. Controller tracing agent115 # must be started successfully to proceed.116 if not self._controller_agent.StartAgentTracing(117 self._controller_config,118 timeout=self._controller_config.timeout):119 print 'Unable to start controller tracing agent.'120 return False121 # Start the child tracing agents.122 succ_agents = []123 for agent_and_config in self._child_agents_with_config:124 agent = agent_and_config.agent125 config = agent_and_config.config126 if agent.StartAgentTracing(config,127 timeout=self._controller_config.timeout):128 succ_agents.append(agent)129 else:130 print 'Agent %s not started.' % str(agent)131 # Print warning if all agents not started.132 na = len(self._child_agents_with_config)133 ns = len(succ_agents)134 if ns < na:135 print 'Warning: Only %d of %d tracing agents started.' % (ns, na)136 self._child_agents = succ_agents137 return True138 def StopTracing(self):139 """Issue clock sync marker and stop tracing for all tracing agents.140 This function stops both the controller tracing agent141 and the child tracing agents. It issues a clock sync marker prior142 to stopping tracing.143 Returns:144 Boolean indicating whether or not the stop tracing succeeded145 for all agents.146 """147 assert self._trace_in_progress, 'No trace in progress.'148 self._trace_in_progress = False149 # Issue the clock sync marker and stop the child tracing agents.150 self._IssueClockSyncMarker()151 succ_agents = []152 for agent in self._child_agents:153 if agent.StopAgentTracing(timeout=self._controller_config.timeout):154 succ_agents.append(agent)155 else:156 print 'Agent %s not stopped.' % str(agent)157 # Stop the controller tracing agent. Controller tracing agent158 # must be stopped successfully to proceed.159 if not self._controller_agent.StopAgentTracing(160 timeout=self._controller_config.timeout):161 print 'Unable to stop controller tracing agent.'162 return False163 # Print warning if all agents not stopped.164 na = len(self._child_agents)165 ns = len(succ_agents)166 if ns < na:167 print 'Warning: Only %d of %d tracing agents stopped.' % (ns, na)168 self._child_agents = succ_agents169 # Collect the results from all the stopped tracing agents.170 all_results = []171 for agent in self._child_agents + [self._controller_agent]:172 try:173 result = agent.GetResults(174 timeout=self._controller_config.collection_timeout)175 if not result:176 print 'Warning: Timeout when getting results from %s.' % str(agent)177 continue178 if result.source_name in [r.source_name for r in all_results]:179 print ('Warning: Duplicate tracing agents named %s.' %180 result.source_name)181 all_results.append(result)182 # Check for exceptions. If any exceptions are seen, reraise and abort.183 # Note that a timeout exception will be swalloed by the timeout184 # mechanism and will not get to that point (it will return False instead185 # of the trace result, which will be dealt with above)186 except:187 print 'Warning: Exception getting results from %s:' % str(agent)188 print sys.exc_info()[0]189 raise190 self.all_results = all_results191 return all_results192 def GetTraceType(self):193 """Return a string representing the child agents that are being traced."""194 sorted_agents = sorted(map(str, self._child_agents))195 return ' + '.join(sorted_agents)196 def _IssueClockSyncMarker(self):197 """Issue clock sync markers to all the child tracing agents."""198 for agent in self._child_agents:199 if agent.SupportsExplicitClockSync():200 sync_id = GetUniqueSyncID()201 agent.RecordClockSyncMarker(sync_id, ControllerAgentClockSync)202def GetUniqueSyncID():203 """Get a unique sync ID.204 Gets a unique sync ID by generating a UUID and converting it to a string205 (since UUIDs are not JSON serializable)206 """207 return str(uuid.uuid4())208class AgentWithConfig(object):209 def __init__(self, agent, config):210 self.agent = agent211 self.config = config212def CreateAgentsWithConfig(options, modules):213 """Create tracing agents.214 This function will determine which tracing agents are valid given the215 options and create those agents along with their corresponding configuration216 object.217 Args:218 options: The command-line options.219 modules: The modules for either Systrace or profile_chrome.220 TODO(washingtonp): After all profile_chrome agents are in221 Systrace, this parameter will no longer be valid.222 Returns:223 A list of AgentWithConfig options containing agents and their corresponding224 configuration object.225 """226 result = []227 for module in modules:228 config = module.get_config(options)229 agent = module.try_create_agent(config)230 if agent and config:231 result.append(AgentWithConfig(agent, config))232 return [x for x in result if x and x.agent]233class TracingControllerConfig(tracing_agents.TracingConfig):234 def __init__(self, output_file, trace_time, write_json,235 link_assets, asset_dir, timeout, collection_timeout,236 device_serial_number, target, trace_buf_size):237 tracing_agents.TracingConfig.__init__(self)238 self.output_file = output_file239 self.trace_time = trace_time240 self.write_json = write_json241 self.link_assets = link_assets242 self.asset_dir = asset_dir243 self.timeout = timeout244 self.collection_timeout = collection_timeout245 self.device_serial_number = device_serial_number246 self.target = target247 self.trace_buf_size = trace_buf_size248def GetControllerConfig(options):249 return TracingControllerConfig(options.output_file, options.trace_time,250 options.write_json,251 options.link_assets, options.asset_dir,252 options.timeout, options.collection_timeout,253 options.device_serial_number, options.target,254 options.trace_buf_size)255def GetChromeStartupControllerConfig(options):256 return TracingControllerConfig(None, options.trace_time,257 options.write_json, None, None, None, None,...

Full Screen

Full Screen

pydevd_tracing.py

Source:pydevd_tracing.py Github

copy

Full Screen

...56 TracingFunctionHolder._warnings_shown[message] = 157 sys.stderr.write('%s\n' % (message,))58 sys.stderr.flush()59 if TracingFunctionHolder._original_tracing:60 TracingFunctionHolder._original_tracing(tracing_func)61def SetTrace(tracing_func):62 if tracing_func is not None:63 if set_trace_to_threads(tracing_func, thread_idents=[thread.get_ident()], create_dummy_thread=False) == 0:64 # If we can use our own tracer instead of the one from sys.settrace, do it (the reason65 # is that this is faster than the Python version because we don't call66 # PyFrame_FastToLocalsWithError and PyFrame_LocalsToFast at each event!67 # (the difference can be huge when checking line events on frames as the68 # time increases based on the number of local variables in the scope)69 # See: InternalCallTrampoline (on the C side) for details.70 return71 # If it didn't work (or if it was None), use the Python version.72 set_trace = TracingFunctionHolder._original_tracing or sys.settrace73 set_trace(tracing_func)74def replace_sys_set_trace_func():...

Full Screen

Full Screen

tracing_project.py

Source:tracing_project.py Github

copy

Full Screen

1# Copyright (c) 2014 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4import sys5import os6import re7def _AddToPathIfNeeded(path):8 if path not in sys.path:9 sys.path.insert(0, path)10def UpdateSysPathIfNeeded():11 for path in GetDependencyPaths():12 _AddToPathIfNeeded(path)13def GetDependencyPaths():14 # TODO(#3703): Separate the paths that are only used by the dev server into15 # another call.16 p = TracingProject()17 return [18 p.catapult_path,19 p.py_vulcanize_path,20 p.vinn_path,21 os.path.join(p.catapult_third_party_path, 'WebOb'),22 os.path.join(p.catapult_third_party_path, 'Paste'),23 os.path.join(p.catapult_third_party_path, 'six'),24 os.path.join(p.catapult_third_party_path, 'webapp2'),25 os.path.join(p.catapult_path, 'common', 'py_utils'),26 os.path.join(p.tracing_third_party_path, 'symbols')27 ]28def _FindAllFilesRecursive(source_paths):29 assert isinstance(source_paths, list)30 all_filenames = set()31 for source_path in source_paths:32 for dirpath, _, filenames in os.walk(source_path):33 for f in filenames:34 if f.startswith('.'):35 continue36 x = os.path.abspath(os.path.join(dirpath, f))37 all_filenames.add(x)38 return all_filenames39def _IsFilenameATest(x):40 if x.endswith('_test.js'):41 return True42 if x.endswith('_test.html'):43 return True44 if x.endswith('_unittest.js'):45 return True46 if x.endswith('_unittest.html'):47 return True48 # TODO(nduca): Add content test?49 return False50class TracingProject(object):51 catapult_path = os.path.abspath(52 os.path.join(os.path.dirname(__file__), os.path.pardir))53 tracing_root_path = os.path.join(catapult_path, 'tracing')54 trace_processor_root_path = os.path.join(catapult_path, 'trace_processor')55 common_root_path = os.path.join(catapult_path, 'common')56 tracing_src_path = os.path.join(tracing_root_path, 'tracing')57 extras_path = os.path.join(tracing_src_path, 'extras')58 ui_extras_path = os.path.join(tracing_src_path, 'ui', 'extras')59 catapult_third_party_path = os.path.join(catapult_path, 'third_party')60 polymer_path = os.path.join(catapult_third_party_path, 'polymer')61 tracing_third_party_path = os.path.join(tracing_root_path, 'third_party')62 py_vulcanize_path = os.path.join(common_root_path, 'py_vulcanize')63 vinn_path = os.path.join(catapult_third_party_path, 'vinn')64 jszip_path = os.path.join(tracing_third_party_path, 'jszip')65 pako_path = os.path.join(tracing_third_party_path, 'pako')66 jpegjs_path = os.path.join(tracing_third_party_path, 'jpeg-js')67 glmatrix_path = os.path.join(68 tracing_third_party_path, 'gl-matrix', 'dist')69 mannwhitneyu_path = os.path.join(70 tracing_third_party_path, 'mannwhitneyu')71 ui_path = os.path.join(tracing_src_path, 'ui')72 d3_path = os.path.join(tracing_third_party_path, 'd3')73 chai_path = os.path.join(tracing_third_party_path, 'chai')74 mocha_path = os.path.join(tracing_third_party_path, 'mocha')75 oboe_path = os.path.join(tracing_third_party_path, 'oboe')76 mre_path = os.path.join(tracing_src_path, 'mre')77 metrics_path = os.path.join(tracing_src_path, 'metrics')78 diagnostics_path = os.path.join(tracing_src_path, 'value', 'diagnostics')79 value_ui_path = os.path.join(tracing_src_path, 'value', 'ui')80 metrics_ui_path = os.path.join(tracing_src_path, 'metrics', 'ui')81 test_data_path = os.path.join(tracing_root_path, 'test_data')82 skp_data_path = os.path.join(tracing_root_path, 'skp_data')83 rjsmin_path = os.path.join(84 tracing_third_party_path, 'tvcm', 'third_party', 'rjsmin')85 rcssmin_path = os.path.join(86 tracing_third_party_path, 'tvcm', 'third_party', 'rcssmin')87 def __init__(self):88 self.source_paths = []89 self.source_paths.append(self.tracing_root_path)90 self.source_paths.append(self.polymer_path)91 self.source_paths.append(self.tracing_third_party_path)92 self.source_paths.append(self.mre_path)93 self.source_paths.append(self.jszip_path)94 self.source_paths.append(self.pako_path)95 self.source_paths.append(self.jpegjs_path)96 self.source_paths.append(self.glmatrix_path)97 self.source_paths.append(self.mannwhitneyu_path)98 self.source_paths.append(self.d3_path)99 self.source_paths.append(self.chai_path)100 self.source_paths.append(self.mocha_path)101 self.source_paths.append(self.oboe_path)102 def CreateVulcanizer(self):103 from py_vulcanize import project as project_module104 return project_module.Project(self.source_paths)105 def IsD8CompatibleFile(self, filename):106 if filename.startswith(self.ui_path):107 return False108 if filename.startswith(self.value_ui_path):109 return False110 if filename.startswith(self.metrics_ui_path):111 return False112 return True113 def FindAllTestModuleRelPaths(self, pred=None):114 if pred is None:115 pred = lambda x: True116 all_filenames = _FindAllFilesRecursive([self.tracing_src_path])117 test_module_filenames = [x for x in all_filenames if118 _IsFilenameATest(x) and pred(x)]119 test_module_filenames.sort()120 return [os.path.relpath(x, self.tracing_root_path)121 for x in test_module_filenames]122 def FindAllMetricsModuleRelPaths(self):123 all_filenames = _FindAllFilesRecursive([self.tracing_src_path])124 all_metrics_module_filenames = []125 for x in all_filenames:126 if x.startswith(self.metrics_path) and not _IsFilenameATest(x):127 all_metrics_module_filenames.append(x)128 all_metrics_module_filenames.sort()129 return [os.path.relpath(x, self.tracing_root_path)130 for x in all_metrics_module_filenames]131 def FindAllDiagnosticsModuleRelPaths(self):132 all_filenames = _FindAllFilesRecursive([self.tracing_src_path])133 all_diagnostics_module_filenames = []134 for x in all_filenames:135 if x.startswith(self.diagnostics_path) and not _IsFilenameATest(x):136 all_diagnostics_module_filenames.append(x)137 all_diagnostics_module_filenames.sort()138 return [os.path.relpath(x, self.tracing_root_path)139 for x in all_diagnostics_module_filenames]140 def FindAllD8TestModuleRelPaths(self):141 return self.FindAllTestModuleRelPaths(pred=self.IsD8CompatibleFile)142 def GetConfigNames(self):143 config_files = [144 os.path.join(self.ui_extras_path, x)145 for x in os.listdir(self.ui_extras_path)146 if x.endswith('_config.html')147 ]148 config_files = [x for x in config_files if os.path.isfile(x)]149 config_basenames = [os.path.basename(x) for x in config_files]150 config_names = [re.match('(.+)_config.html$', x).group(1)151 for x in config_basenames]152 return config_names153 def GetDefaultConfigName(self):154 assert 'full' in self.GetConfigNames()155 return 'full'156 def AddConfigNameOptionToParser(self, parser):157 choices = self.GetConfigNames()158 parser.add_argument(159 '--config', dest='config_name',160 choices=choices, default=self.GetDefaultConfigName(),161 help='Picks a browser config. Valid choices: %s' % ', '.join(choices))162 return choices163 def GetModuleNameForConfigName(self, config_name):...

Full Screen

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful