Python3.6.4 + selenium + chrome structures in ubuntu system, implemented on a free running web front end interface automated testing
A, ubuntu 16.04 system comes python2.7 and python3.5, need to python3.6.4 steps:
1, using the wget command to download Python3.6.4 installation package: wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
2, the tar command to decompress Python3.6.4: tar zxvf Python-3.6.4.tgz
3, into the Python-3.6.4 directory: cd Python-3.6.4
4, compile and install, execute ./configure script: ./ configure
5, the installation: make make install
After installation is complete check using python3.6 is installed successfully, and then use pip3.6 install selenium if properly installed, installation instructions python3.6
If pip installation failed, suggesting: pip is configured with locations that require TLS / SSL .......
1. When using pip need ssl, openssl command to install and libssl-dev: apt-get install openssl apt-get install libssl-dev
2.cd Python-3.6.4
3. Modify the Modules / Setup
Modules Vim / the Setup
# modify the results as follows:
# Helper Module1 for the Socket Socket (2)
is _socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
4. ./configure --with-ssl again
5. the installation: make make install
Second, install Chrome
Download the command line chrome: wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
Installation command: sudo dpkg -i google-chrome-stable_current_amd64.deb
Reference may also be mounted in other ways
Third, the installation Chromedriver
Here you need to find chromedrive (match version of Chrome)
After decompression, the incoming ubuntu system
Chromedriver configured to perform, refer to the following:
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
Go to the next / usr / bin directory find chromedriver the existence of
sudo mv chromedriver there is no / usr / bin move the file to this directory
Chromedriver modify permission sudo chmod a + x chromedriver
Fourth, the Xvfb mounting (refer here)
使用 命令安装Xvfb sudo apt-get update && sudo apt-get install -y xfonts-100dpi xfonts-75dpi xfonts-scalable xfonts-cyrillic Xvfb x11-apps imagemagick firefox google-chrome-stable
Test whether the installation was successful:
1, start Xvfb service: Xvfb -ac: 7 -screen 0 1280x1024x8 (Note that this is x, not * oh)
2、export DISPLAY=:7
/usr/bin/google-chrome-stable http://www.mimvp.com // chrome 浏览www.mimvp.com
If you run after, it appears:
Xlib: extension "RANDR" missing on display ":7"
you made it. This is irrelevant information, I tried to get rid of it before, without success. Finally, after I run selenium script, no this information, the script execution is normal there, so now I think of it as a success is installed.
The service started in this way (the next day to start this way service is closed, the operation is not clear follow-up study closed)
Create a service, first touch /etc/init.d/Xvfb
Script is as follows:
! # / Bin / the bash
IF [the -Z "$. 1"]; the then
echo "$` 0` the basename {Start |} STOP "
Exit
Fi
Case" $. 1 "in
Start)
/ usr / bin / the Xvfb: 0. 7 -ac -screen & 1024x768x8
;;
STOP)
killall Xvfb
;;
esac
modify the script permissions to start the service:
chmod +x /etc/init.d/Xvfb
chkconfig Xvfb on
service Xvfb start
The word is out of service: service Xvfb stop
Fifth, test scripts
Command to install pyvirtualdisplay: sudo pip install pyvirtualdisplay
Refer to the following script:
from pyvirtualdisplay import Display
from selenium import webdriver
import time
display = Display(visible=0, size=(1024, 768))
display.start()
driver = webdriver.Chrome()
time.sleep(1)
driver.get('http://www.baidu.com')
time.sleep(10)
print (driver.page_source)
driver.save_screenshot('/home/test/test.png')
time.sleep(2)
driver.close()
driver.quit()
display.stop()
使用python3.6 +脚本文件名,运行脚本