简体   繁体   English

在CI平台(如travis-ci)中测试代码时,如何在没有浏览器或网络访问的情况下对硒代码进行单元测试?

[英]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: 我正在使用python中的selenium包来抓取网站数据,其功能如下:

driver.find_element_by_ ...  (...) 

I want to test this code in travis-ci platform where it has no access to browser or network. 我想在无法访问浏览器或网络的travis-ci平台中测试此代码。

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. 由于它在内部处理html,因此我无法将静态的固定html数据直接提供给它进行测试。 So can you suggest best way to do so? 那么,您能建议最好的方法吗?

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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