Best Python code snippet using playwright-python
features_bundle_test.py
Source:features_bundle_test.py
1#!/usr/bin/env python2# Copyright 2013 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.5import json6import unittest7from server_instance import ServerInstance8from test_file_system import TestFileSystem9_TEST_FILESYSTEM = {10 'api': {11 '_api_features.json': json.dumps({12 'audioCapture': {13 'channel': 'stable',14 'extension_types': ['platform_app']15 },16 'background': [17 {18 'channel': 'stable',19 'extension_types': ['extension']20 },21 {22 'channel': 'stable',23 'extension_types': ['platform_app'],24 'whitelist': ['im not here']25 }26 ],27 'omnibox': {28 'dependencies': ['manifest:omnibox'],29 'contexts': ['blessed_extension']30 },31 'syncFileSystem': {32 'dependencies': ['permission:syncFileSystem'],33 'contexts': ['blessed_extension']34 },35 'tabs': {36 'channel': 'stable',37 'extension_types': ['extension', 'legacy_packaged_app'],38 'contexts': ['blessed_extension']39 },40 'test': {41 'channel': 'stable',42 'extension_types': 'all',43 'contexts': [44 'blessed_extension', 'unblessed_extension', 'content_script']45 },46 'windows': {47 'dependencies': ['api:tabs'],48 'contexts': ['blessed_extension']49 }50 }),51 '_manifest_features.json': json.dumps({52 'app.content_security_policy': {53 'channel': 'stable',54 'extension_types': ['platform_app'],55 'min_manifest_version': 2,56 'whitelist': ['this isnt happening']57 },58 'background': {59 'channel': 'stable',60 'extension_types': ['extension', 'legacy_packaged_app', 'hosted_app']61 },62 'manifest_version': {63 'channel': 'stable',64 'extension_types': 'all'65 },66 'omnibox': {67 'channel': 'stable',68 'extension_types': ['extension']69 },70 'page_action': {71 'channel': 'stable',72 'extension_types': ['extension']73 },74 'sockets': {75 'channel': 'dev',76 'extension_types': ['platform_app']77 }78 }),79 '_permission_features.json': json.dumps({80 'bluetooth': {81 'channel': 'dev',82 'extension_types': ['platform_app']83 },84 'power': {85 'channel': 'stable',86 'extension_types': [87 'extension', 'legacy_packaged_app', 'platform_app'88 ]89 },90 'syncFileSystem': {91 'channel': 'stable',92 'extension_types': ['platform_app']93 },94 'tabs': {95 'channel': 'stable',96 'extension_types': ['extension']97 }98 })99 },100 'docs': {101 'templates': {102 'json': {103 'manifest.json': json.dumps({104 'background': {105 'documentation': 'background_pages.html'106 },107 'manifest_version': {108 'documentation': 'manifest/manifest_version.html',109 'example': 2,110 'level': 'required'111 },112 'page_action': {113 'documentation': 'pageAction.html',114 'example': {},115 'level': 'only_one'116 }117 }),118 'permissions.json': json.dumps({119 'fakeUnsupportedFeature': {},120 'syncFileSystem': {121 'partial': 'permissions/sync_file_system.html'122 },123 'tabs': {124 'partial': 'permissions/tabs.html'125 },126 })127 }128 }129 }130}131class FeaturesBundleTest(unittest.TestCase):132 def setUp(self):133 self._server = ServerInstance.ForTest(TestFileSystem(_TEST_FILESYSTEM))134 def testManifestFeatures(self):135 expected_features = {136 'background': {137 'name': 'background',138 'channel': 'stable',139 'platforms': ['extensions'],140 'documentation': 'background_pages.html'141 },142 'manifest_version': {143 'name': 'manifest_version',144 'channel': 'stable',145 'platforms': ['apps', 'extensions'],146 'documentation': 'manifest/manifest_version.html',147 'level': 'required',148 'example': 2149 },150 'omnibox': {151 'name': 'omnibox',152 'channel': 'stable',153 'platforms': ['extensions']154 },155 'page_action': {156 'name': 'page_action',157 'channel': 'stable',158 'platforms': ['extensions'],159 'documentation': 'pageAction.html',160 'level': 'only_one',161 'example': {}162 },163 'sockets': {164 'name': 'sockets',165 'channel': 'dev',166 'platforms': ['apps']167 }168 }169 self.assertEqual(170 expected_features,171 self._server.features_bundle.GetManifestFeatures().Get())172 def testPermissionFeatures(self):173 expected_features = {174 'bluetooth': {175 'name': 'bluetooth',176 'channel': 'dev',177 'platforms': ['apps'],178 },179 'fakeUnsupportedFeature': {180 'name': 'fakeUnsupportedFeature',181 'platforms': []182 },183 'power': {184 'name': 'power',185 'channel': 'stable',186 'platforms': ['apps', 'extensions'],187 },188 'syncFileSystem': {189 'name': 'syncFileSystem',190 'channel': 'stable',191 'platforms': ['apps'],192 'partial': 'permissions/sync_file_system.html'193 },194 'tabs': {195 'name': 'tabs',196 'channel': 'stable',197 'platforms': ['extensions'],198 'partial': 'permissions/tabs.html'199 }200 }201 self.assertEqual(202 expected_features,203 self._server.features_bundle.GetPermissionFeatures().Get())204 def testAPIFeatures(self):205 expected_features = {206 'audioCapture': {207 'name': 'audioCapture',208 'channel': 'stable',209 'platforms': ['apps']210 },211 'background': {212 'name': 'background',213 'channel': 'stable',214 'platforms': ['extensions']215 },216 'omnibox': {217 'name': 'omnibox',218 'platforms': ['extensions'],219 'contexts': ['blessed_extension'],220 'dependencies': ['manifest:omnibox']221 },222 'syncFileSystem': {223 'name': 'syncFileSystem',224 'platforms': ['apps'],225 'contexts': ['blessed_extension'],226 'dependencies': ['permission:syncFileSystem']227 },228 'tabs': {229 'name': 'tabs',230 'channel': 'stable',231 'platforms': ['extensions'],232 'contexts': ['blessed_extension'],233 },234 'test': {235 'name': 'test',236 'channel': 'stable',237 'platforms': ['apps', 'extensions'],238 'contexts': [239 'blessed_extension', 'unblessed_extension', 'content_script'],240 },241 'windows': {242 'name': 'windows',243 'platforms': ['extensions'],244 'contexts': ['blessed_extension'],245 'dependencies': ['api:tabs']246 }247 }248 self.assertEqual(249 expected_features,250 self._server.features_bundle.GetAPIFeatures().Get())251if __name__ == '__main__':...
test_launcher.py
Source:test_launcher.py
...81 browser.close(),82 )83 await browser.close()84@pytest.mark.only_browser("chromium")85async def test_browser_launch_should_return_background_pages(86 browser_type: BrowserType,87 tmpdir,88 browser_channel,89 assetdir,90 launch_arguments,91):92 if browser_channel:93 pytest.skip()94 extension_path = str(assetdir / "simple-extension")95 context = await browser_type.launch_persistent_context(96 str(tmpdir),97 **{98 **launch_arguments,99 "headless": False,...
pdfHExt.py
Source:pdfHExt.py
1# DEPENDENCYS: You need to install pdfrw via: pip install pdfrw2# import pdfrw3def print_Dependencies():4 print("Dependencies:")5 print(" This program uses the following python libraries:")6 print(" - sys (should be installed with python per default)")7 print(" - os (should be installed with python per default)")8 print(" - pdfrw (use 'pip install pdfrw' to install this library)")9try:10 import sys11 import os12 from pdfrw import PageMerge, PdfReader, PdfWriter, PdfDict, PdfName13except:14 print("------------------------------------------------------------------")15 print("")16 print("")17 print("ERROR : Please install the required dependencies first!")18 print("")19 print_Dependencies()20 print("")21 print("")22 print("------------------------------------------------------------------")23scripts_path = os.path.dirname(os.path.abspath(__file__))24if len(sys.argv) < 3 or len(sys.argv) > 4:25 print("------------------------------------------------------------------")26 print(" Usage:")27 print(" python pdfHExt.py input output [template]")28 print(" Parameters:")29 print(" input")30 print(" being the path/filename to the source pdf")31 print(" output")32 print(" being the path/filename to write the new generated pdf")33 print(" template (optional)")34 print(" being the path/filename for the background")35 print(" What it does:")36 print(" This program will paste each page of the pdf-file 'input'")37 print(" onto a larger sized page called template.")38 print(" If no template is given, then a default tempalte is used.")39 print(" The input pages are pasted on the left, vertically centered")40 print(" side of each page, so you have enough space on the right to")41 print(" annotate each page with your desired hand writing program")42 print(" like Xournal, Xournal++, GoodNotes, etc.")43 print_Dependencies()44 print("------------------------------------------------------------------")45 sys.exit(0)46def blankPage(template):47 x = PdfDict()48 x.Type = PdfName.Page49 x.Contents = PdfDict(stream="")50 x.MediaBox = template.inheritable.MediaBox51 return x52inFilename = sys.argv[1]53outFilename = sys.argv[2]54templateFilename = os.path.join(scripts_path,"3xDinA4.pdf")55if len(sys.argv) == 4:56 templateFilename = sys.argv[3]57background_pages = PdfReader(templateFilename)58background = background_pages.pages[0]59background_PM = PageMerge().add(background)[0]60content = PdfReader(inFilename)61pdfOut = PdfWriter(outFilename)62for i in range(len(content.pages)):63 content_page = content.pages[i]64 content_page_PM = PageMerge().add(content_page)[0]65 outPage = blankPage(background)66 outPage = PageMerge(outPage).add(background_PM, prepend=False).render()67 outPage = PageMerge(outPage).add(content_page_PM, prepend=False).render()68 69 pdfOut.addpage(outPage)70#PdfWriter(outFilename, trailer=content).write()...
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!!