Best Python code snippet using SeleniumBase
image_test.py
Source:image_test.py
...8 self.open("https://xkcd.com/1117/")9 selector = "#comic"10 file_name = "comic.png"11 folder = "images_exported"12 self.save_element_as_image_file(selector, file_name, folder)13 self.assert_true(os.path.exists("%s/%s" % (folder, file_name)))14 print('\n"%s/%s" was saved!' % (folder, file_name))15 @pytest.mark.run(order=2)16 def test_add_text_overlay_to_image(self):17 """Add a text overlay to an image."""18 self.open("https://xkcd.com/1117/")19 selector = "#comic"20 file_name = "image_overlay.png"21 folder = "images_exported"22 overlay_text = 'This is an XKCD comic!\nTitle: "My Sky"'23 self.save_element_as_image_file(24 selector, file_name, folder, overlay_text25 )26 self.assert_true(os.path.exists("%s/%s" % (folder, file_name)))27 print('\n"%s/%s" was saved!' % (folder, file_name))28 @pytest.mark.run(order=3)29 def test_add_text_overlay_to_page_section(self):30 """Add a text overlay to a section of a page."""31 self.open("https://xkcd.com/2200/")32 selector = "#middleContainer"33 file_name = "section_overlay.png"34 folder = "images_exported"35 overlay_text = (36 "Welcome to %s\n"37 "This is a comment added to the image.\n"38 "Unreachable states come from logic errors."39 % self.get_current_url()40 )41 self.save_element_as_image_file(42 selector, file_name, folder, overlay_text43 )44 self.assert_true(os.path.exists("%s/%s" % (folder, file_name)))45 print('\n"%s/%s" was saved!' % (folder, file_name))46 @pytest.mark.run(order=4)47 def test_add_text_overlay_to_full_page(self):48 """Add a text overlay to a full page."""49 self.open("https://xkcd.com/1922/")50 self.remove_element("#bottom")51 selector = "body"52 file_name = "page_overlay.png"53 folder = "images_exported"54 overlay_text = "A text overlay on %s" % self.get_current_url()55 self.save_element_as_image_file(56 selector, file_name, folder, overlay_text57 )58 self.assert_true(os.path.exists("%s/%s" % (folder, file_name)))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!