async def capture_screenshot(self): if self.capture_screenshots: try: full_page = True screenshot_bytes = await self.page.screenshot({'fullPage': full_page}) screenshot_base64 = bytes_to_base64(screenshot_bytes) self.screenshots.append(screenshot_base64) except: pass
def test_run_chrome_locally(self): path_headless_shell = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' chrome = Chrome().keep_open() chrome.options['path_headless_shell'] = path_headless_shell chrome_sync = Chrome_Sync(chrome) chrome_sync.browser() chrome_sync.open('https://www.google.com') self.png_data = bytes_to_base64(chrome_sync.screenshot()) chrome_sync.close()
def test_pdf_rebuild(self,): # refactor into separate test file server = self.config.test_sdk url = f"http://{server}:8080/api/rebuild/base64" headers = { 'accept': 'application/json', 'Content-Type': 'application/json'} text = random_text("random text - ") test_pdf = Test_Data().create_test_pdf(text=text) original_bytes = file_contents_as_bytes(test_pdf) original_base64 = bytes_to_base64(original_bytes) post_data = {"Base64": original_base64} result = POST(url, data=post_data, headers=headers) rebuild_base64 = base64_to_bytes(result) assert str_to_bytes(text) in original_bytes assert b'Glasswall' not in original_bytes assert str_to_bytes(text) in rebuild_base64 assert b'Glasswall' in rebuild_base64
def test_base64_to_bytes__bytes_to_base64(self): bytes = b"\x89PNG__" bytes_base64 = "iVBOR19f" assert bytes_to_base64(bytes) == bytes_base64 assert base64_to_bytes(bytes_base64) == bytes assert base64_to_bytes(bytes_base64.encode()) == bytes
def save_png_bytes_to_file(bytes, png_file=None): png_data = bytes_to_base64(bytes) return save_png_base64_to_file(png_data, png_file)