Best Python code snippet using SeleniumBase
ad_block_list.py
Source:ad_block_list.py
...3Usage:4 On the command line:5 "pytest SOME_TEST.py --ad_block"6 From inside a test:7 self.ad_block()8If using the command line version, the ad_block functionality gets9activated after "self.wait_for_ready_state_complete()" is called,10which is always run after page loads, unless changed in "settings.py".11Using ad_block will slow down test runs a little. (Use only if necessary.)12Format: A CSS Selector that's ready for JavaScript's querySelectorAll()13"""14AD_BLOCK_LIST = [15 '[aria-label="Ad"]',16 '[class^="sponsored-content"]',17 '[data-ad-details*="Advertisement"]',18 '[data-native_ad*="placement"]',19 '[data-provider="dianomi"]',20 '[data-type="ad"]',21 '[data-track-event-label*="-taboola-"]',...
test_page.py
Source:test_page.py
...16 await page.load_page(None, testing_url, browser, True)17 await browser.close()18 page_content = page.content19 assert "google" in page_content, f"Not 'google' {page_content}"20def test_ad_block():21 ad_block = AdBlock(["./ads-servers.txt", "./ads-servers.he.txt"])22 assert ad_block.is_ad("js.nagich.co.il")23 assert ad_block.is_ad("ad.a8.net")24 assert not ad_block.is_ad("123sad4.co.il")25 assert ad_block.is_ad("taboola.com")26 assert ad_block.is_ad("ad-delivery.net")27 assert ad_block.is_ad("www.googletagmanager.com")28def test_get_tld():29 assert AdBlock._get_tld("js.nagich.co.il", 2) == "co.il"30 assert AdBlock._get_tld("js.nagich.co.il", 3) == "nagich.co.il"31 assert AdBlock._get_tld("il", 2) == "il"32if __name__ == "__main__":33 loop = asyncio.get_event_loop()34 loop.run_until_complete(Page().load_page(testing_url))
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!!