蓝色天空网 · mbsky.com
高级自动化:动态页面、受控配置和隔离
让配置有可观察效果,保留未执行范围。
固定本地测试页的实际浏览器结果,不是在线Python解释器。下载代码后可在独立环境修改输入并重新运行。
本章Python入口 · 完整实验实现 · 本站测试服务 · 本站页面交互

当前输入实际检查
| 实际检查 | 结果 |
|---|---|
| fixture-initial-no-severe-errors | 通过 |
| no-jQuery-assumption | 通过 |
| actual-fetch-result | 通过 |
| test-token-negative | 通过 |
| test-token-positive | 通过 |
| proxy-actual-search | 通过 |
| actual-proxy-forwarded-request | 通过 |
| image-disabled-natural-width | 通过 |
| disabled-image-request-count | 通过 |
| JS-still-executes | 通过 |
| page-JS-disabled-marker | 通过 |
| static-HTML-still-present | 通过 |
| screenshot-saved-actual-browser | 通过 |
| PNG-magic-actual-browser | 通过 |
| PNG-extent-actual-browser | 通过 |
| all-created-sessions-quit | 通过 |
本章完整入口
from selenium_lab import *
@case('selenium-advanced')
def advanced(l,d,b,s):
from grid_runtime import local_proxy
l.eq('no-jQuery-assumption',d.execute_script('return typeof window.jQuery'),'undefined');click(d,'trigger-fetch');wait(d).until(lambda x:x.find_element(By.ID,'fetch-result').get_attribute('data-ready')=='true');l.eq('actual-fetch-result',d.find_element(By.ID,'fetch-result').text,'2');token=d.find_element(By.ID,'token');token.send_keys('wrong');click(d,'test-token');l.eq('test-token-negative',d.find_element(By.ID,'token-result').text,'测试校验失败');token.clear();token.send_keys('MBSKY-TEST');click(d,'test-token');l.eq('test-token-positive',d.find_element(By.ID,'token-result').text,'测试校验通过')
with local_proxy(b)as(proxy,forwarded):
with browser(l,'local-proxy',extra_arguments=['--proxy-server='+proxy,'--proxy-bypass-list=<-loopback>'])as pd:
pd.get(b+'/search');l.eq('proxy-actual-search',search(pd,'CSS'),['CSS布局','CSS选择器']);l.check('actual-proxy-forwarded-request',any('/api/search?'in u for u in forwarded),forwarded)
before=sum(v['path']=='/pixel.png'for v in s['requests'])
with browser(l,'images-off',preferences={'profile.managed_default_content_settings.images':2})as off:
off.get(b);l.eq('image-disabled-natural-width',off.execute_script("return document.querySelector('#probe-image').naturalWidth"),0);l.eq('disabled-image-request-count',sum(v['path']=='/pixel.png'for v in s['requests']),before);l.check('JS-still-executes',off.execute_script('return window.fixtureBoot===true'))
with browser(l,'javascript-off',preferences={'profile.managed_default_content_settings.javascript':2})as off:
off.get(b);l.eq('page-JS-disabled-marker',off.execute_script('return window.fixtureBoot??null'),None);l.check('static-HTML-still-present',bool(off.find_elements(By.ID,'query')))
l.pending_case('production-captcha-and-external-proxy','Only controlled local test-token/localproxy, resource prefs and ownfetch executed; no production CAPTCHA solving service, external IP-evasion or dynamic live proxy switching')
if __name__ == "__main__":
run('selenium-advanced')