![](/img/trans.png)
[英]Why do my selenium tests fail on travis-ci after no code change, while they pass locally?
[英]How to unittest selenium code without browser or network access while testing code in CI platform like travis-ci?
我正在使用python中的selenium包來抓取網站數據,其功能如下:
driver.find_element_by_ ... (...)
我想在無法訪問瀏覽器或網絡的travis-ci平台中測試此代碼。
如何測試此代碼? 它使用以下方法檢索數據:
driver.get(url)
driver.find_element()
由於它在內部處理html,因此我無法將靜態的固定html數據直接提供給它進行測試。 那么,您能建議最好的方法嗎?
如果您可以將網站頁面放在測試腳本所在的機器上,Selenium可以使用file:
協議打開本地HTML文件,如下所示:
driver.get('file:///C:/Users/xxxxx/Desktop/test.html')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.