一、環(huán)境搭建
1、安裝python+pycharm軟件 。python安裝網(wǎng)址官網(wǎng):https://www.python.org/about/
根據(jù)自己的電腦系統(tǒng)選擇最新版本
下載到本地,選擇安裝路徑并配置好環(huán)境變量
驗(yàn)證安裝是否成功 搜索中錄入cmd 打開(kāi)命令窗口 錄入python顯示一下版本號(hào)表示安裝成功
2、pycharm軟件安裝地址:https://www.jetbrains.com/pycharm/download/#section=windows
根據(jù)自己的需求選擇專業(yè)版或者社區(qū)版
首次安裝打開(kāi) New Project 在Location創(chuàng)建項(xiàng)目存放的路徑
添加解釋器File,選擇settings,點(diǎn)擊 project interpret 添加模塊 pymysql
二、步驟
1、在命令窗口安裝使用的模塊,安裝模塊selenium
pip install selenium
3、安裝瀏覽器啟動(dòng)器
2、打開(kāi)pycharm 創(chuàng)建新的代碼文件,編輯代碼。
# 導(dǎo)入使用的模塊
from selenium improt webdriver
# 啟動(dòng)瀏覽器
# 啟動(dòng)瀏覽器
driver = webdriver.Chrome('下載的瀏覽器驅(qū)動(dòng)')
3、發(fā)送請(qǐng)求,和網(wǎng)址,
driver.get('網(wǎng)址')
4、編寫(xiě)自己的代碼
三、服務(wù)器部署
# 創(chuàng)建實(shí)例對(duì)象 通過(guò)ssh協(xié)議
ssh = paramiko.SSHClient()
# 連接服務(wù)器 信任服務(wù)器
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 連接遠(yuǎn)程 ip 端口 用戶名 密碼
ssh.connect(ipd地址, "用戶名", "密碼")
# 管道查找運(yùn)行的包名,并去除grep形同的包名
stdin,stdout,stder = ssh.exec_command('ps -ef|grep 包名 |grep -v grep')
output = stdout.read().decode()
print(output)
if '打印出的安裝包路徑和運(yùn)行包' in output:
# 找到信息并提取信息 split 分割字符串
parts = output.split('')
# 列表生成式 去除空格
parts = [part for part in parts if part!='']
pid = parts[1]
#殺死進(jìn)程
ssh.exec_cmmand(f'kill-9{pid}')
# 刪除舊的安裝包
ssh.exec_command('rm -f restapl-teach.zip')
# 上傳新安裝包文件
sftp = ssh.open_sftp()
sftp.put(r'安裝包名')
sftp.close()
到此這篇關(guān)于教你用Python+selenium搭建自動(dòng)化測(cè)試環(huán)境的文章就介紹到這了,更多相關(guān)python+selenium自動(dòng)化測(cè)試環(huán)境內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:- 詳解Python 使用 selenium 進(jìn)行自動(dòng)化測(cè)試或者協(xié)助日常工作
- Python利用Selenium實(shí)現(xiàn)網(wǎng)站自動(dòng)簽到功能
- Selenium+Python自動(dòng)化腳本環(huán)境搭建的全過(guò)程
- 利用Python+Selenium破解春秋航空網(wǎng)滑塊驗(yàn)證碼的實(shí)戰(zhàn)過(guò)程
- python Selenium等待元素出現(xiàn)的具體方法
- Python使用Selenium自動(dòng)進(jìn)行百度搜索的實(shí)現(xiàn)
- Python中Selenium對(duì)Cookie的操作方法
- python+opencv+selenium自動(dòng)化登錄郵箱并解決滑動(dòng)驗(yàn)證的問(wèn)題
- 用Python selenium實(shí)現(xiàn)淘寶搶單機(jī)器人
- Python selenium的這三種等待方式一定要會(huì)!
- Python爬蟲(chóng)實(shí)戰(zhàn)之用selenium爬取某旅游網(wǎng)站
- 教你如何使用Python selenium
- python Web應(yīng)用程序測(cè)試selenium庫(kù)使用用法詳解