-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathtest_cdp_ad_blocking.py
31 lines (29 loc) · 1.21 KB
/
test_cdp_ad_blocking.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from seleniumbase import BaseCase
BaseCase.main(__name__, __file__)
class CDPNetworkBlockingTests(BaseCase):
def test_cdp_network_blocking(self):
self.open("about:blank")
if self._reuse_session or not self.is_chromium():
message = "Skipping test if reusing session or not Chromium!"
print(message)
self.skip(message)
self.execute_cdp_cmd(
'Network.setBlockedURLs', {"urls": [
"*googlesyndication.com*",
"*doubleclick.net*",
"*adsafeprotected.com*",
"*2mdn.net*",
"*googletagmanager.com*",
"*adsafeprotected.com*",
"*snigelweb.com*",
"*fastclick.net*",
"*amazon-adsystem.com*",
"*google-analytics.com*",
]})
self.execute_cdp_cmd('Network.enable', {})
self.open('https://www.w3schools.com/jquery/default.asp')
self.ad_block()
source = self.get_page_source()
self.assert_true("doubleclick.net" not in source)
self.assert_true("google-analytics.com" not in source)
self.post_message("Blocking was successful!")