环境 linux:centos7.5
安装docker
安装docker-selenium镜像
docker pull elgalu/selenium
安装zalenium
docker pull dosel/zalenium
查看镜像:#docker images
运行zalenium扩展(备注:由于腾讯云限制4444端口的安全组设置,因此改用4445端口来启动)
docker run --rm -ti --name zalenium -p 4445:4445 -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/videos:/home/seluser/videos --privileged dosel/zalenium start --timeZone "Asia/Shanghai"
安装chrome
( 版本: google-chrome-stable.x86_64 0:76.0.3809.132-1 )
1)安装chrome及依赖:#curl https://intoli.com/install-google-chrome.sh | bash
2)检查是否缺乏依赖:#ldd /opt/google/chrome/chrome | grep "not found"
3)运行chrome:#google-chrome-stable --no-sandbox --headless --disable-gpu --screenshot https://www.baidu.com/
安装chrome驱动
1)下载压缩包https://npm.taobao.org/mirrors/chromedriver/并解压
2)建立软链接:ln -s /opt/chromedriver /usr/bin/chromedriver
安装selenium
pip install selenium
运行脚本
from selenium import webdriver
from time import sleep
driver = webdriver.Remote(command_executor='http://localhost:4445/wd/hub',desired_capabilities={'browserName': 'chrome'})
print("start==========")
driver.get('https://www.baidu.com')
driver.find_element_by_id("kw").send_keys("docker selenium")
driver.find_element_by_id("su").click()
sleep(1)
driver.get_screenshot_as_file('1.png')
print("end=============")
driver.quit()
监控运行结果
http://IP:端口/grid/admin/live?refresh=1
3)linux配置HTMLTestRunner
3.1)下载http://tungwaiyip.info/software/HTMLTestRunner.html
3.2)上传到/usr/lib/python2.7/site-packages