调查问卷
ppt
笔记格式:markdown
相关链接
代码
打开浏览器
from time import sleep
from selenium import webdriver
# 创建一个 Chromdriver 的实例
driver = webdriver.Chrome()
# 打开网址
driver.get("https://www.baidu.com/")
sleep(10)
搜狗搜索
# Generated by Selenium IDE
import pytest
import time
import json
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
class TestSougou():
def setup_method(self, method):
self.driver = webdriver.Chrome()
self.vars = {}
def teardown_method(self, method):
self.driver.quit()
def test_sougou(self):
self.driver.get("https://www.sogou.com/")
self.driver.set_window_size(995, 579)
self.driver.find_element(By.ID, "query").click()
self.driver.find_element(By.ID, "query").send_keys("霍格沃兹测试开发")
self.driver.find_element(By.ID, "stb").click()
报告生成
执行测试,生成报告
pytest test_sougou.py --alluredir=results
根据报告结果进行展示
allure serve results
ceshiren搜索
from selenium import webdriver
from selenium.webdriver.common.by import By
class TestCeshiren:
# 测试前置动作
def setup(self):
base_url = "https://ceshiren.com/"
# 打开测试人首页
self.driver = webdriver.Chrome()
self.driver.get(base_url)
# 设置隐式等待时间
self.driver.implicitly_wait(10)
# 搜索功能测试
def test_search(self):
search_btn = (By.CSS_SELECTOR,".d-icon-search")
search_input = (By.ID,"search-term")
adv_search_btn = (By.CSS_SELECTOR,".show-advanced-search")
search_result_title = (By.CSS_SELECTOR,".search-link")
search_value = "Selenium"
# 点击查询按钮
self.driver.find_element(*search_btn).click()
# 输入查询值
self.driver.find_element(*search_input).send_keys(search_value)
# 点击高级查询按钮
self.driver.find_element(*adv_search_btn).click()
# 判断查询结果是否包含关键字
res = self.driver.find_element(*search_result_title)
assert search_value in res.text
po封装
- 将帖子中(自己已成功调通)面向过程的代码复制到项目中
- 根据po设计(提取页面元素、值、动作)封装IndexPage、SearchPage、BasePage
- 使用po对象编写测试类
作业
使用po的封装方式判断帖子详情页面的标题和内容内容是否包含关键字