Best Python code snippet using toolium_python
test_example.py
Source:test_example.py
...12 """13 # Navigate to web page14 needle.driver.get('https://www.example.com')15 # Take a entire page screen diff16 needle.assert_screenshot('static_page', threshold=80)17@pytest.mark.mask18def test_example_page_with_mask(needle):19 """Example for comparing page with a mask20 :param NeedleDriver needle: NeedleDriver instance21 :return:22 """23 # Navigate to web page24 needle.driver.get('https://www.google.com')25 # Ensure the cursor does not appear in the screenshot26 footer = needle.driver.find_elements_by_xpath('//div[@class="fbar"]')27 if footer:28 footer[0].click()29 # Take a entire page screen diff, ignore the doodle banner30 needle.assert_screenshot('search_page', exclude=[31 (By.ID, 'hplogo'),32 (By.ID, 'prm'),33 (By.XPATH, '//div[@jsmodel]/div/div[//input[@title="Search"] and @jsname and not(@jscontroller)]')34 ], threshold=80)35@pytest.mark.element36def test_example_element(needle):37 """Example for comparing individual elements38 :param NeedleDriver needle: NeedleDriver instance39 :return:40 """41 # Navigate to web page42 needle.driver.get('https://www.google.com')43 # Ensure the cursor does not appear in the screenshot44 footer = needle.driver.find_elements_by_xpath('//div[@class="fbar"]')45 if footer:46 footer[0].click()47 # Take an element screen diff48 needle.assert_screenshot('search_field', (By.ID, 'tsf'), threshold=80)49@pytest.mark.cleanup50def test_cleanup_on_success(needle):51 """Verify that the --needle-cleanup-on-success removes the newly generated file52 :param NeedleDriver needle: NeedleDriver instance53 :return:54 """55 screenshot_path = os.path.join(needle.output_dir, "cleanup_test.png")56 # Set cleanup on success to true57 needle.cleanup_on_success = True58 # Navigate to web page59 needle.driver.get('https://www.example.com')60 # Take a entire page screen diff61 needle.assert_screenshot('cleanup_test', threshold=80)62 assert not os.path.exists(screenshot_path)63@pytest.mark.output_dir64def test_output_dir(needle):65 """Verify that the --needle-output-dir saves the fresh image in the specified directory66 :param NeedleDriver needle: NeedleDriver instance67 :return:68 """69 # Reassign output_dir70 needle.output_dir = os.path.join(needle.output_dir, 'extra')71 needle._create_dir(needle.output_dir)72 screenshot_path = os.path.join(needle.output_dir, "output_dir_test.png")73 # Navigate to web page74 needle.driver.get('https://www.example.com')75 # Take a entire page screen diff76 needle.assert_screenshot('output_dir_test', threshold=80)77 if not needle.save_baseline:78 assert os.path.exists(screenshot_path)79@pytest.mark.baseline_dir80def test_baseline_dir(needle):81 """Verify that the --needle-baseline-dir saves the fresh image in the specified directory82 :param NeedleDriver needle: NeedleDriver instance83 :return:84 """85 # Reassign output_dir86 needle.baseline_dir = os.path.join(needle.baseline_dir, 'default')87 needle._create_dir(needle.baseline_dir)88 screenshot_path = os.path.join(needle.baseline_dir, "baseline_dir_test.png")89 # Navigate to web page90 needle.driver.get('https://www.example.com')91 # Take a entire page screen diff92 needle.assert_screenshot('baseline_dir_test', threshold=80)93 assert os.path.exists(screenshot_path)94@pytest.mark.viewport95def test_viewport_size(needle):96 """Verify that viewport size can be97 :param NeedleDriver needle: NeedleDriver instance98 :return:99 """100 original_size = needle.driver.get_window_size()101 needle.viewport_size = "900x600"102 needle.set_viewport()103 assert needle.driver.get_window_size() != original_size104@pytest.mark.engine105@pytest.mark.parametrize('engine', ('pil', 'perceptualdiff', 'imagemagick'))106def test_image_engine(needle, engine):107 """Verify all image engines can be set108 :param NeedleDriver needle: NeedleDriver instance109 :param engine: Image engine class110 :return:111 """112 needle.engine_class = engine113 assert needle.engine_class == needle.ENGINES[engine]114 # Navigate to web page115 needle.driver.get('https://www.example.com')116 # Take a entire page screen diff...
example01.py
Source:example01.py
...6 def test_button_login_with_background_green_and_font_white(self):7 login = Login(self.driver)8 login.open_url()9 10 self.assert_screenshot(login.button_login, 'btnLogin')11 def test_image_on_the_fail_page(self):12 login = Login(self.driver)13 login_fail = LoginFail(self.driver)14 login.open_url()15 login.click_login()16 17 self.assert_screenshot(login_fail.image_fail, 'image-fail')18 def test_image_on_the_ok_page(self):19 login = Login(self.driver)20 login_ok = LoginOk(self.driver)21 login.open_url()22 login.fill_user('robson')23 login.fill_pass('agapito') 24 login.click_login()25 26 self.assert_screenshot(login_ok.image_ok, 'image-ok')27 def test_page_with_hide_element(self):28 login = Login(self.driver)29 30 login.open_url()31 self.hide_element(login.button_login)32 ...
registered_testcase.py
Source:registered_testcase.py
1#导å
2from page_object.business_page import Business3from public_method.assert_screenshot import Assert_Screenshot45class Registered(Assert_Screenshot):67 def test_registered_scceed(self):8 # 注åæå9 driver = self.driver10 username=Business().registerd(driver)11 text = Business().return_text(driver)12 self.assert_equal(driver, text, username)13
...
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!!