蓝色天空网 · 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')