Best Python code snippet using playwright-python
kvm_flightrecorder
Source: kvm_flightrecorder
...44 write_file(trace_path('events', subsystem, 'enable'), '1' if enable else '0')45def start_tracing():46 enable_subsystem('kvm', True)47 write_file(trace_path('tracing_on'), '1')48def stop_tracing():49 write_file(trace_path('tracing_on'), '0')50 enable_subsystem('kvm', False)51 write_file(trace_path('events', 'enable'), '0')52 write_file(trace_path('current_tracer'), 'nop')53def dump_trace():54 tracefile = open(trace_path('trace'), 'r')55 try:56 lines = True57 while lines:58 lines = tracefile.readlines(64 * 1024)59 sys.stdout.writelines(lines)60 except KeyboardInterrupt:61 pass62def tail_trace():63 try:64 for line in open(trace_path('trace_pipe'), 'r'):65 sys.stdout.write(line)66 except KeyboardInterrupt:67 pass68def usage():69 print 'Usage: %s start [buffer_size_kb] | stop | dump | tail' % sys.argv[0]70 print 'Control the KVM flight recorder tracing.'71 sys.exit(0)72def main():73 if len(sys.argv) < 2:74 usage()75 cmd = sys.argv[1]76 if cmd == '--version':77 print 'kvm_flightrecorder version 1.0'78 sys.exit(0)79 if not os.path.isdir(tracing_dir):80 print 'Unable to tracing debugfs directory, try:'81 print 'mount -t debugfs none /sys/kernel/debug'82 sys.exit(1)83 if not os.access(tracing_dir, os.W_OK):84 print 'Unable to write to tracing debugfs directory, please run as root'85 sys.exit(1)86 if cmd == 'start':87 stop_tracing() # clean up first88 if len(sys.argv) == 3:89 try:90 buffer_size_kb = int(sys.argv[2])91 except ValueError:92 print 'Invalid per-cpu trace buffer size in KB'93 sys.exit(1)94 write_file(trace_path('buffer_size_kb'), str(buffer_size_kb))95 print 'Per-CPU ring buffer size set to %d KB' % buffer_size_kb96 start_tracing()97 print 'KVM flight recorder enabled'98 elif cmd == 'stop':99 stop_tracing()100 print 'KVM flight recorder disabled'101 elif cmd == 'dump':102 dump_trace()103 elif cmd == 'tail':104 tail_trace()105 else:106 usage()107if __name__ == '__main__':...
test_chromium_tracing.py
Source: test_chromium_tracing.py
...22):23 output_file = tmpdir / "trace.json"24 await browser.start_tracing(page=page, screenshots=True, path=output_file)25 await page.goto(server.PREFIX + "/grid.html")26 await browser.stop_tracing()27 assert os.path.getsize(output_file) > 028@pytest.mark.only_browser("chromium")29async def test_should_create_directories_as_needed(30 browser: Browser, page: Page, server, tmpdir31):32 output_file = tmpdir / "these" / "are" / "directories" / "trace.json"33 await browser.start_tracing(page=page, screenshots=True, path=output_file)34 await page.goto(server.PREFIX + "/grid.html")35 await browser.stop_tracing()36 assert os.path.getsize(output_file) > 037@pytest.mark.only_browser("chromium")38async def test_should_run_with_custom_categories_if_provided(39 browser: Browser, page: Page, tmpdir: Path40):41 output_file = tmpdir / "trace.json"42 await browser.start_tracing(43 page=page,44 screenshots=True,45 path=output_file,46 categories=["disabled-by-default-v8.cpu_profiler.hires"],47 )48 await browser.stop_tracing()49 with open(output_file, mode="r") as of:50 trace_json = json.load(of)51 assert (52 "disabled-by-default-v8.cpu_profiler.hires"53 in trace_json["metadata"]["trace-config"]54 )55@pytest.mark.only_browser("chromium")56async def test_should_throw_if_tracing_on_two_pages(57 browser: Browser, page: Page, tmpdir: Path58):59 output_file_1 = tmpdir / "trace1.json"60 await browser.start_tracing(page=page, screenshots=True, path=output_file_1)61 output_file_2 = tmpdir / "trace2.json"62 with pytest.raises(Exception):63 await browser.start_tracing(page=page, screenshots=True, path=output_file_2)64 await browser.stop_tracing()65@pytest.mark.only_browser("chromium")66async def test_should_return_a_buffer(67 browser: Browser, page: Page, server, tmpdir: Path68):69 output_file = tmpdir / "trace.json"70 await browser.start_tracing(page=page, path=output_file, screenshots=True)71 await page.goto(server.PREFIX + "/grid.html")72 value = await browser.stop_tracing()73 with open(output_file, mode="r") as trace_file:74 assert trace_file.read() == value.decode()75@pytest.mark.only_browser("chromium")76async def test_should_work_without_options(browser: Browser, page: Page, server):77 await browser.start_tracing()78 await page.goto(server.PREFIX + "/grid.html")79 trace = await browser.stop_tracing()80 assert trace81@pytest.mark.only_browser("chromium")82async def test_should_support_a_buffer_without_a_path(83 browser: Browser, page: Page, server84):85 await browser.start_tracing(page=page, screenshots=True)86 await page.goto(server.PREFIX + "/grid.html")87 trace = await browser.stop_tracing()...
tests.py
Source: tests.py
...21 # on the output of read().22 content = 'A file.'23 project.start_tracing()24 self.assertEqual(render('text.txt'), 'A file.')25 trace = project.stop_tracing()26 self.assertEqual(trace.splitlines(), [27 "calling render('text.txt')",28 ". calling read('text.txt')",29 ])30 # Second check: with more interesting content, render() will31 # also call hash().32 content = 'My hash is $HASH.'33 print(project._cache)34 t = Task(read, ('text.txt',))35 print(t)36 print(t in project._cache)37 project.invalidate(t)38 project.start_tracing()39 project.rebuild()40 trace = project.stop_tracing()41 self.assertEqual(render('text.txt'), 'My hash is 28.')42 self.assertEqual(trace.splitlines(), [43 "calling read('text.txt')",44 "calling render('text.txt')",45 ". calling hash_of('text.txt')",46 ])47 # Final check: if we then remove the interesting content, does48 # Contingent recognize the hash no longer needs to be computed?49 content = 'Simple file again.'50 print(project._cache)51 t = Task(read, ('text.txt',))52 print(t)53 print(t in project._cache)54 project.invalidate(t)55 project.start_tracing()56 project.rebuild()57 trace = project.stop_tracing()58 self.assertEqual(render('text.txt'), 'Simple file again.')59 self.assertEqual(trace.splitlines(), [60 "calling read('text.txt')",61 "calling render('text.txt')",...
Playwright error connection refused in docker
playwright-python advanced setup
How to select an input according to a parent sibling label
Error when installing Microsoft Playwright
Trouble waiting for changes to complete that are triggered by Python Playwright `select_option`
Capturing and Storing Request Data Using Playwright for Python
Can Playwright be used to launch a browser instance
Trouble in Clicking on Log in Google Button of Pop Up Menu Playwright Python
Scrapy Playwright get date by clicking button
React locator example
I solved my problem. In fact my docker container (frontend) is called "app" which is also domain name of fronend application. My application is running locally on http. Chromium and geko drivers force httpS connection for some domain names one of which is "app". So i have to change name for my docker container wich contains frontend application.
Check out the latest blogs from LambdaTest on this topic:
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
When it comes to web automation testing, there are a number of frameworks like Selenium, Cypress, PlayWright, Puppeteer, etc., that make it to the ‘preferred list’ of frameworks. The choice of test automation framework depends on a range of parameters like type, complexity, scale, along with the framework expertise available within the team. However, it’s no surprise that Selenium is still the most preferred framework among developers and QAs.
Playwright is a framework that I’ve always heard great things about but never had a chance to pick up until earlier this year. And since then, it’s become one of my favorite test automation frameworks to use when building a new automation project. It’s easy to set up, feature-packed, and one of the fastest, most reliable frameworks I’ve worked with.
The speed at which tests are executed and the “dearth of smartness” in testing are the two major problems developers and testers encounter.
With the rapidly evolving technology due to its ever-increasing demand in today’s world, Digital Security has become a major concern for the Software Industry. There are various ways through which Digital Security can be achieved, Captcha being one of them.Captcha is easy for humans to solve but hard for “bots” and other malicious software to figure out. However, Captcha has always been tricky for the testers to automate, as many of them don’t know how to handle captcha in Selenium or using any other test automation framework.
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.
Get 100 minutes of automation test minutes FREE!!