请自行在电脑上搭建Python+Selenium的Web自动化测试环境,进行功能测试。
实验内容:
(1)要求自行编写测试脚本代码,执行测试脚本并分析结果;
(2)至少测试三个功能,例如主页的搜索功能;
实验要求:
(1)撰写实验报告,主要填写本人测试步骤、测试结果分析和自己的实验体会;
(2)测试步骤要附上自己所编写的三个功能测试的脚本;
(3)测试结果分析要附上截图。
功能一:窗口跳转点击
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time
s = Service(executable_path=r"你的driver路径")
driver = webdriver.Chrome(service=s)
driver.get("http://www.swpu.edu.cn")
information=driver.find_element(By.XPATH,'/html/body/div[4]/div/div/div/ul/li[1]/a')
information.click()
time.sleep(3)
# driver.window_handles 获取所有窗口句柄
handles = driver.window_handles
# 切换窗口
driver.switch_to.window(handles[-1])
driver.find_element(By.XPATH,'/html/body/div[3]/div[1]/div[2]/ul/li[2]/a').click()
time.sleep(1)
driver.find_element(By.XPATH,'/html/body/div[3]/div[1]/div[2]/ul/li[3]/a').click()
time.sleep(1)
driver.find_element(By.XPATH,'/html/body/div[3]/div[1]/div[2]/ul/li[4]/a').click()
功能一:搜索功能
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
s = Service(executable_path=r"你的driver路径")
driver = webdriver.Chrome(service=s)
driver.get("http://www.swpu.edu.cn")
p_input=driver.find_element(By.ID, 'showkeycode252338')
p_input.clear()
p_input.send_keys('计算机科学学院')
driver.find_element(By.XPATH,'/html/body/div[2]/div/div[2]/div[1]/form/input[6]').click()