python运维脚本部署jdk_基于Java/Python搭建Web UI自动化环境
Java搭建UI自動化測試環境
下載JDK8
https://www.cnblogs.com/thloveyl/p/12378124.html
配置Java環境
1.解壓Jdk壓縮包
2.配置環境變量
計算機->屬性->高級->環境變量->系統變量->Path
3.添加根目錄下的bin與lib目錄、jre下的bin目錄(近期我發現只將bin目錄加入Path就可以了)
{% asset_img 2.PNG %}
注:都是目錄下絕對路徑地址,我這兒在E盤。
4.輸入java、javac、java -version確認
下載selenium server
安裝對應版本的Chrome瀏覽器驅動
IDEA導入jar包
File->Project Settings->Modules->Dependencies->‘+‘->JARS...
選中之后點ok->勾上jar包->applay->ok
實例
package com.smeoa.UI;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
public class DemoChromeDriver
{
public static void main(String[] args) throws Exception
{
//設置瀏覽器的驅動屬性、值。
System.setProperty("webdriver.chrome.driver","D:\\Driver\\chromedriver.exe");
//取消 chrome正受到自動測試軟件的控制的信息欄
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
//實例化Driver對象
WebDriver driver = new ChromeDriver(options);
//打開網址:在url欄輸入https://www.baidu.com
driver.get("http://www.baidu.com");
//xpath元素定位:輸入欄,sendKeys輸入Java
driver.findElement(By.xpath("/html//input[@id='kw']")).sendKeys("github");
//點擊百度一下
driver.findElement(By.xpath("/html//input[@id='su']")).click();
Thread.sleep(100);
//關閉瀏覽器
driver.close();
}
}
Python搭建UI自動化環境
下載Python3
環境配置
安裝Python
勾選Add Python to PATH,一直下一步。
驗證:CMD輸入Python
下載Chrome Driver
安裝PyCharm
安裝Selenium
打開PyCharm
新建Python File
點擊面板底部 Terminal
輸入pip install selenium 安裝、pip list 驗證
實例
from selenium import webdriver
# 設置 :忽略正在受自動測試軟件的控制
option = webdriver.ChromeOptions()
option.add_argument('disable-infobars')
# 實例化 對象
driver = webdriver.Chrome(chrome_options=option)
# 打開網址
driver.get("https://www.baidu.com")
# 通過id元素定位到輸入框,輸入github
driver.find_element_by_id("kw").send_keys("github")
# 點擊百度一下
driver.find_element_by_id("su").click()
driver.close()
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的python运维脚本部署jdk_基于Java/Python搭建Web UI自动化环境的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 讯飞输入法怎么恢复原来的键盘(更好用的手
- 下一篇: iCloud 钥匙串是什么iCloud