目录
安全测试初学体验_W&L.的博客-CSDN博客_burp suite测试
python+selenium+unittest自动化测试_W&L.的博客-CSDN博客
使用postman进行juiceshop系统的接口自动化测试及生成报告_W&L.的博客-CSDN博客
综合任务 :熟悉测试环境
测试环境:http://114.116.97.187:8080/symfony/web/index.php/auth/login
用户名密码: admin/Bitnami.12345
配置为汉语
添加用户 功能添加10个用户。
1、先使用selenium实现(添加一 个 用户的 自动化)
1.1 新建包 selenium_pytest_allure
1.2 新建文件py
1.3 导包from selenium import webdriver
1.4 调用chromedriver(驱动),建立浏览器。driver
1.5 添加智能等待10
1.6 打开 测试 环境get("")
1.7 定位用户名,输入用户名
1.8 定位密码 ,输入密码
1.9 定位提交,点击提交
2.0验证登陆成功
2.1-2.3悬停{}--点击用户
2.4 点击添加
2.5 定位 用户角色 *
ESS
员工姓名 *
输入以查看提示...
用户名 *
状态 *
启用
密码
确认密码
2.11 点击保存
2.12 验证添加成功。
3.1退出系统
4.1关闭浏览器
1.使用selenium实现
一 .准备工作
打开pycharm
请确保有浏览器驱动 不会看连接python自动化测试_W&L.的博客-CSDN博客
调用chromedriver(驱动),建立浏览器。driver
把浏览器驱动 放在driver下
新建python文件
打开测试网站
对网站复制http://114.116.97.187:8080/symfony/web/index.php/auth/login
登录
进入也F12检查 可以看到登录和密码ID 运用定位技术 进行登录
用定位找到对应的ID或者NAME、
如果不想经警告:
service = ChromeService(r“c:\\\\driver.exe”)
driver = webdriver.Chrome(service=service)
driver.find_element(By.ID, "txtUsername").send_keys("账号")
driver.find_element(By.ID, "txtPassword").send_keys("密码")
driver.find_element(By.ID, "btnLogin").click()
from selenium.webdriver.common.by import By
import time
par_path=os.path.abspath("..")
CHROMEDRIVER_PATH=par_path+"/driver/chromedriver"
# service = ChromeService(executable_path=CHROMEDRIVER_PATH)
# driver = webdriver.Chrome(service=service)
driver =webdriver.Chrome(CHROMEDRIVER_PATH)
driver.implicitly_wait(30)
driver.get("http://114.116.97.187:8080/symfony/web/index.php/auth/login")
driver.find_element(By.ID,"txtUsername").send_keys("admin")
driver.find_element(By.ID,"txtPassword").send_keys("Bitnami.12345")
driver.find_element(By.NAME,"Submit").click()
悬停
admin_link=driver.find_element(By.LINK_TEXT,"个人信息管理系统")
user_manager=driver.find_element(By.ID,"menu_pim_addEmployee")
xuanting=ActionChains(driver)
xuanting.move_to_element(admin_link).click(user_manager).perform()
添加用户
driver.find_element(By.ID,"firstName").send_keys("*")
driver.find_element(By.ID,"middleName").send_keys("*")
driver.find_element(By.ID,"lastName").send_keys("*")
确认密码
driver.find_element(By.ID,"user_name").send_keys("admin")
driver.find_element(By.ID,"user_password").send_keys("WWWWxxx123123..")
driver.find_element(By.ID,"re_password").send_keys("WWWWxxx123123..")
上传照片
删除
# 选择 我们添加的一个删除
# 通过用户名找到 无素link --,
href=driver.find_element(By.LINK_TEXT,"**********").get_attribute("href")
# 获得它的属性 href的值/symfony/web/index.php/pim/viewEmployee/empNumber/**
# 字符串,切 最 后2个取回来 ,
num=href[href.rindex("/")+1:]
# 与id拼接一下"ohrmList_chkSelectRecord_"+num
driver.find_element(By.ID,"ohrmList_chkSelectRecord_"+num).click()
driver.find_element(By.ID,"btnDelete").click()
time.sleep(2)
driver.find_element(By.ID,"dialogDeleteBtn").click()
验证
# 验证用户登陆
assert 'admin' in driver.find_element(By.PARTIAL_LINK_TEXT,"欢迎").text.lower()
登出
driver.find_element(By.LINK_TEXT,"登出").click()
# Author: 王贤明
# Date: 7/27/22 1:32 PM
# File: test_oranghrm_login.py
# 任务:已经添加10个用户,
# 1、写一脚本,登陆,(orangehrm)
# 2、数据驱动10个用户依次登陆+pytest
# 3、pytest+allure生成报告
# 4、10个用户并发登陆生成报告,并发执行方式。
from selenium import webdriver
from selenium.webdriver.common.by import By
import os,time
import pytest
@pytest.fixture(scope="module")
def driver():
par_path=os.path.abspath("..")
CHROMEDRIVER_PATH=par_path+"/driver/chromedriver"
driver =webdriver.Chrome(CHROMEDRIVER_PATH)
driver.implicitly_wait(30)
yield driver
time.sleep(1)
driver.close()
def test_logins(driver):
driver.get("http://114.116.97.187:8080/symfony/web/index.php/auth/login")
driver.find_element(By.ID,"txtUsername").send_keys("admin")
driver.find_element(By.ID,"txtPassword").send_keys("Bitnami.12345")
driver.find_element(By.NAME,"Submit").click()
time.sleep(2)
# 验证用户登陆
assert 'admin' in driver.find_element(By.PARTIAL_LINK_TEXT,"欢迎").text.lower()
time.sleep(2)
# 退出
driver.find_element(By.ID,"welcome").click()
driver.find_element(By.LINK_TEXT,"登出").click()
from selenium import webdriver
from selenium.webdriver.common.by import By
import os,time
import pytest
@pytest.fixture(scope="module")
def driver():
par_path=os.path.abspath("..")
CHROMEDRIVER_PATH=par_path+"/driver/chromedriver"
driver =webdriver.Chrome(CHROMEDRIVER_PATH)
driver.implicitly_wait(30)
yield driver
time.sleep(1)
driver.quit()
user = [{"txtUsername": "admin",
"txtPassword": "Bitnami.12345",
"firstName": "Admin",
},
{"txtUsername": "ftest001",
"txtPassword": "Ft12a3./",
"firstName": "linda",
},
{"txtUsername": "ftest002",
"txtPassword": "Ft12a3./",
"firstName": "linda002",
}
]
@pytest.mark.parametrize("test_data",user)
def test_logins(driver,test_data):
txtUsername=test_data['txtUsername']
txtPassword=test_data['txtPassword']
firstName=test_data['firstName']
driver.get("http://114.116.97.187:8080/symfony/web/index.php/auth/login")
driver.find_element(By.ID,"txtUsername").send_keys(txtUsername)
driver.find_element(By.ID,"txtPassword").send_keys(txtPassword)
driver.find_element(By.NAME,"Submit").click()
time.sleep(2)
# 验证用户登陆
assert firstName in driver.find_element(By.PARTIAL_LINK_TEXT,"欢迎").text
time.sleep(2)
# 退出
driver.find_element(By.ID,"welcome").click()
driver.find_element(By.LINK_TEXT,"登出").click()
创建yaml文件
- txtUsername: admin
txtPassword: Bitnami.12345
firstName: Admin
- txtUsername: ftest001
txtPassword: Ft12a3./
firstName: linda
- txtUsername: ftest002
txtPassword: Ft12a3./
firstName: linda002
并发 执行 -n 3
并发语句
3 passed, 1 warning in 32.45s
3 passed, 3 warnings in 24.51s
整体代码
# Author: lindafang
# Date: 7/27/22 1:32 PM
# File: test_oranghrm_login.py
# 任务:已经添加10个用户,
# 1、写一脚本,登陆,(orangehrm)
# 2、数据驱动10个用户依次登陆+pytest
# 3、pytest+allure生成报告
# 4、10个用户并发登陆生成报告,并发执行方式。
import yaml
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium import webdriver
from selenium.webdriver.common.by import By
import os,time
import pytest
import allure
par_path=os.path.abspath("..")
@pytest.fixture(scope="module")
def driver():
with allure.step("0、打开浏览器 "):
CHROMEDRIVER_PATH=par_path+"/driver/chromedriver"
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
service = ChromeService(executable_path=CHROMEDRIVER_PATH)
driver = webdriver.Chrome(service=service,options=options)
driver.implicitly_wait(30)
yield driver
time.sleep(1)
with allure.step("7、关闭浏览器 "):
driver.quit()
@allure.feature("登陆")
@pytest.mark.parametrize("test_data",yaml.safe_load(open(par_path+"/selenium_pytest_allure/test_data_login.yaml",encoding='utf8')))
def test_logins(driver,test_data):
txtUsername=test_data['txtUsername']
txtPassword=test_data['txtPassword']
firstName=test_data['firstName']
with allure.step("1、打开登陆页"):
driver.get("http://114.116.97.187:8080/symfony/web/index.php/auth/login")
with allure.step("2、输入用户名密码"+txtUsername):
allure.attach.file(par_path+"/selenium_pytest_allure/test_data_login.yaml","测试数据",attachment_type=allure.attachment_type.YAML)
driver.find_element(By.ID,"txtUsername").send_keys(txtUsername)
driver.find_element(By.ID,"txtPassword").send_keys(txtPassword)
with allure.step("3、点击登陆"):
driver.find_element(By.NAME,"Submit").click()
time.sleep(2)
# 验证用户登陆
with allure.step("4、验证名字正确"):
assert firstName in driver.find_element(By.PARTIAL_LINK_TEXT,"欢迎").text
with allure.step("5、截图验证登陆成功"):
driver.save_screenshot("login_"+txtUsername+".png")
allure.attach.file("login_"+txtUsername+".png","用户登陆成功",attachment_type=allure.attachment_type.PNG)
time.sleep(2)
# 退出
with allure.step("6、登出"):
driver.find_element(By.ID,"welcome").click()
driver.find_element(By.LINK_TEXT,"登出").click()