简体   繁体   中英

How to unittest selenium code without browser or network access while testing code in CI platform like travis-ci?

I am scrapping website data using selenium package in python with functions like:

driver.find_element_by_ ...  (...) 

I want to test this code in travis-ci platform where it has no access to browser or network.

How to test this code? it uses the following methods to retrieve data:

driver.get(url)
driver.find_element()

Because it processes html inside, I can't feed static fixed html data directly to it for testing. So can you suggest best way to do so?

如果您可以将网站页面放在测试脚本所在的机器上,Selenium可以使用file:协议打开本地HTML文件,如下所示:

driver.get('file:///C:/Users/xxxxx/Desktop/test.html')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM