在Linux下使用selenium+ Chrome + Chromedriver并发布到jenkins

我自己的操作:

远程服务器重启后防火墙会默认重新启动,需要关掉防火墙才能访问jenkins :systemctl stop firewalld/shutdown -r now
/test_flow/test_Authentication/test_login.py
jenkins:
root001/Pass1234

1.远程安装jenkins
https://www.jianshu.com/p/c517f09df025
2.远程安装Java,以及python
https://www.cnblogs.com/kimyeee/p/7250560.html python3.6安装
3.远程git安装
https://www.jianshu.com/p/89a2917ff5c1
3.安装python requirements 模块
4.谷歌浏览器以及webdriver配置
https://www.cnblogs.com/czz-728/articles/13714359.html ALT+P 上传文件 secureCRT PUT

5.在Linux下使用selenium+ Chrome + Chromedriver
https://blog.csdn.net/qq_36853469/article/details/103234466
注意 :在执行构建状态处添加谷歌路径

6.邮件发送
https://blog.csdn.net/weixin_39246324/article/details/104590445

chromedriver --version
google-chrome --version


google-chrome-stable


操作系统:CentOS7.8
IP地址:10.10.128.156
用户名:root/user
密码:P#ssword1v3/!QAZ2wsx03

http://10.10.128.156:8888/job/AutoTest-python/allure

qq 授权码
asdkisrfygkweada
git remote add origin https://github.com/cyz-2020/test.git
git branch -M cyz
git push -u origin cyz
cat /Users/cango/.ssh/id_rsa.pub

下面是细分的:

第一步:

安装jenkins就不说了 大家应该都知道的

第二步:

远程安装Java,以及python

https://www.cnblogs.com/kimyeee/p/7250560.html python3.6安装

一、安装python3.6

1. 安装依赖环境

  # yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

2.下载Python3
  https://www.python.org/downloads/

1
# wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

3.安装python3

  我个人习惯安装在/usr/local/python3(具体安装位置看个人喜好)
  创建目录:

1
# mkdir -p /usr/local/python3

  解压下载好的Python-3.x.x.tgz包(具体包名因你下载的Python具体版本不不同⽽而不不同,如:我下载的是Python3.6.1.那我这里就是Python-3.6.1.tgz)

1
# tar -zxvf Python-3.6.1.tgz

4.进入解压后的目录,编译安装。

1
2
# cd Python-3.6.1
# ./configure --prefix=/usr/local/python3

  make

1
# make

  make install

1
make install    或者 make && make install

5.建立python3的软链

1
# ln -s /usr/local/python3/bin/python3 /usr/bin/python3

6.并将/usr/local/python3/bin加入PATH

1
2
3
4
5
6
7
8
9
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH

  按ESC,输入:wq回车退出。

  修改完记得执行行下面的命令,让上一步的修改生效:

1
# source ~/.bash_profile

  检查Python3及pip3是否正常可用:

1
2
3
4
# python3 -V
Python 3.6.1
# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)

7.不行的话在创建一下pip3的软链接(我也不清楚这一步有什么用)

1
# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

二、安装pip以及setuptools

  毕竟丰富的第三方库是python的优势所在,为了更加方便的安装第三方库,使用pip命令,我们需要进行相应的安装。

1、安装pip前需要前置安装setuptools

命令如下:

wget --no-check-certificate  https://pypi.python.org/packages/source/s/setuptools/setuptools-19.6.tar.gz#md5=c607dd118eae682c44ed146367a17e26

tar -zxvf setuptools-19.6.tar.gz

cd setuptools-19.6

python3 setup.py build

python3 setup.py install

如果前面没布置好环境的话,就要苦逼一下了:

  报错: RuntimeError: Compression requires the (missing) zlib module

  我们需要在linux中安装zlib-devel包,进行支持。

  yum install zlib-devel

  需要对python3.5进行重新编译安装。

  cd python3.6.1

  make && make install

  又是漫长的编译安装过程。

  重新安装setuptools

  python3 setup.py build

  python3 setup.py install

2、安装pip

命令如下:

wget --no-check-certificate  https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb

tar -zxvf pip-8.0.2.tar.gz

cd pip-8.0.2

python3 setup.py build

python3 setup.py install

如果没有意外的话,pip安装完成。

如果没有搞好环境的话,会碰见亲切的报错:

  pip3 install paramiko

  报这个错

  pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

  然后开始进行如下操作

  yum install openssl
  yum install openssl-devel
  cd python3.6.1
  make && make install

第三步:远程安装git

https://www.jianshu.com/p/89a2917ff5c1这个很简单不多介绍

第四步:谷歌浏览器以及webdriver配置

https://www.cnblogs.com/czz-728/articles/13714359.html

第五步:

1.安装selenium
pip3 install selenium

2.安装chrome
用下面的命令安装Google Chrome

yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

也可以先下载至本地,然后安装

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

yum install ./google-chrome-stable_current_x86_64.rpm
安装必要的库

yum install mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts
3、安装 chromedriver
如果为了谷歌浏览器版本,查看安装谷歌浏览器办版本号:命令

google-chrome --version
查询结果如图:

 

查看相应版本的谷歌浏览器对应的驱动版本 http://chromedriver.storage.googleapis.com/index.html

可以直接在这里下载然后上传到linux环境下.

chrome官网 安装

wget https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_linux64.zip
淘宝源(推荐)

wget http://npm.taobao.org/mirrors/chromedriver/78.0.3904.70/chromedriver_linux64.zip
将下载的文件解压,放在如下位置

unzip chromedriver_linux64.zip

mv chromedriver /usr/bin/
给予执行权限

cd /usr/bin

chmod chromedriver+x /usr/bin/

4、运行代码,查看是否成功(python下)
进入ipython环境或者直接python3

python3

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
browser = webdriver.Chrome(options=chrome_options)

'''
其他提高性能参数
'''
chrome_options.add_argument('blink-settings=imagesEnabled=false')
chrome_options.add_argument('--disable-gpu')

其中
“–no-sandbox”参数是让Chrome在root权限下跑
“–headless”参数是不用打开图形界面

注意一定要设置无界面,不然会报错

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
5.如果报错:
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 3.10.0-957.5.1.el7.x86_64 x86_64)
原因:
1.chromedriver没有安装

2.chromedriver的版本和chrom浏览器的版本不对应

因为我们已经安装过了,所以很明显是原因2,所以自己去找到和谷歌浏览器相应的chromedriver吧.
注意 :在执行构建状态处添加谷歌路径

第六步:

6.邮件发送
https://blog.csdn.net/weixin_39246324/article/details/104590445

 

查询谷歌的版本合驱动版本

chromedriver --version
google-chrome --version

google-chrome-stable

posted @ 2021-09-09 14:09  冬天里的狐狸  阅读(764)  评论(0编辑  收藏  举报