当前位置: 首页 > wzjs >正文

如何做行业网站著名咨询公司有哪些

如何做行业网站,著名咨询公司有哪些,心理学网站可以在线做量表,寻求网站建设技术提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 一、web自动化1.xpath定位1.属性定位2.属性与逻辑结合3.属性和层级结合 2.常见元素定位方法(面试题)3.常见元素定位失败原因4.cookie1.验证码…

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 一、web自动化
    • 1.xpath定位
      • 1.属性定位
      • 2.属性与逻辑结合
      • 3.属性和层级结合
    • 2.常见元素定位方法(面试题)
    • 3.常见元素定位失败原因
    • 4.cookie
      • 1.验证码处理方案
      • 2.认识cookie
      • 3.cookie跳过登录案例
    • 5.pytest
      • 1.pytest介绍及安装
      • 2.定义用例
      • 3.执行测试用例
        • 1.命令行运行
        • 2.PyTest配置文件运行
        • 3.项目配置文件config.py
      • 4.参数化
      • 5.断言
      • 6.allure报告


一、web自动化

1.xpath定位

1.属性定位

  • 说明:利用元素的属性来进行定位
  • 示例://*[@xalue=‘提交’]
  • 在这里插入图片描述

#导包
from selenium.webdriver.common.by import By
from tools.chromeDriver import get_driver, quit_driver
#需求:打开注册页面。完成以下操作:
#1). 利用元素的属性信息精准定位用户名输入框,并输入:admin
#项目地址:http://121.43.169.97:8848/pageA.html
driver = get_driver(“http://121.43.169.97:8848/pageA.html”)
driver.find_element(By.XPATH, “//*[@id=‘userA’]”).send_keys(“admin”)
#退出浏览器
quit_driver(driver)

2.属性与逻辑结合

  • 说明:利用元素的多个属性来进行定位
  • 示例://input[@value='提交’and@class=‘banana’]\
  • 在这里插入图片描述

#导包
from selenium.webdriver.common.by import By
from tools.chromeDriver import get_driver, quit_driver
#需求:打开注册页面。完成以下操作:
#1). 利用属性与逻辑结合在test1输入框输入:admin
#项目地址:http://121.43.169.97:8848/pageA.html
driver = get_driver(“http://121.43.169.97:8848/pageA.html”)
driver.find_element(By.XPATH, “//*[@name=‘user’ and
@class=‘login’]”).send_keys(“admin”)
#退出浏览器
quit_driver(driver)

3.属性和层级结合

  • 说明:先定位到其父级元素,然后在找到该元素
  • 示例://div[@id=‘test1’]/input[@value=‘提交’]
  • 在这里插入图片描述

#导包
from selenium.webdriver.common.by import By
from tools.chromeDriver import get_driver, quit_driver
#需求:打开注册页面。完成以下操作:
#1). 利用属性与逻辑结合在test1输入框输入:admin
#项目地址:http://121.43.169.97:8848/pageA.html
driver = get_driver(“http://121.43.169.97:8848/pageA.html”)
#driver.find_element(By.XPATH, “//[@name=‘user’ and
@class=‘login’]").send_keys(“admin”)
driver.find_element(By.XPATH, "//
[@id=‘p1’]/input”).send_keys(“admin”)
#退出浏览器
quit_driver(driver)

2.常见元素定位方法(面试题)

在这里插入图片描述

3.常见元素定位失败原因

在这里插入图片描述

4.cookie

1.验证码处理方案

  • 去掉验证码、万能验证码
  • 验证码识别技术
  • 记录cookie
  • 在这里插入图片描述

2.认识cookie

在这里插入图片描述

3.cookie跳过登录案例

在这里插入图片描述

  • 需求:使用cookie实现跳过登录
    1). 手动登录商城,获取cookie
    2). 使用获取到的cookie,达到登录目的,然后就可以执行登录之后的操作
    在这里插入图片描述

#导包
import time
from selenium import webdriver
#打开浏览器
driver = webdriver.Chrome()
#打开页面
driver.get(“https://hmshop-test.itheima.net/Home/User/index.html”)
time.sleep(2)
#绕过登录
cookie_data = {
“name”: “PHPSESSID”,
“value”: “h0lrprhei3p3v16pr8sb2ehrm3”
}
driver.add_cookie(cookie_data)
time.sleep(2)
driver.refresh() # 刷新
#退出浏览器
time.sleep(3)
driver.quit()

5.pytest

1.pytest介绍及安装

  • pytest:python中的一种单元测试框架。
  • 为什么学习pytest?
    能阻止多个用例去执行
    方便实现参数化
    能够生成测试报告
  • 安装
    安装: pip install pytest
    在这里插入图片描述
    验证: pip show pytest
    在这里插入图片描述

2.定义用例

  • 在这里插入图片描述

#导包
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
class TestLogin:
def setup_class(self):
#打开浏览器
self.driver = webdriver.Chrome()
self.driver.maximize_window()
def setup(self):
#打开页面
self.driver.get(“https://hmshop-test.itheima.net/Home/user/login.html”)
def test_login(self):
#case02:登录失败(用户名为空)
self.driver.find_element(By.ID, “username”).send_keys(“”)
self.driver.find_element(By.ID, “password”).send_keys(“123456”)
self.driver.find_element(By.ID, “verify_code”).send_keys(“8888”)
self.driver.find_element(By.LINK_TEXT, “登 录”).click()
def test_login2(self):
#case03:登录失败(密码为空)
self.driver.find_element(By.ID, “username”).send_keys(“13488888888”)
self.driver.find_element(By.ID, “password”).send_keys(“”)
self.driver.find_element(By.ID, “verify_code”).send_keys(“8888”)
self.driver.find_element(By.LINK_TEXT, “登 录”).click()
def test_login3(self):
#case01:登录成功
self.driver.find_element(By.ID, “username”).send_keys(“13488888888”)
self.driver.find_element(By.ID, “password”).send_keys(“123456”)
self.driver.find_element(By.ID, “verify_code”).send_keys(“8888”)
self.driver.find_element(By.LINK_TEXT, “登 录”).click()
def teardown(self):
time.sleep(2)
def teardown_class(self):
#退出浏览器
time.sleep(3)
self.driver.quit()

3.执行测试用例

1.命令行运行

在这里插入图片描述
在这里插入图片描述

#导包
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
class TestLogin:
def setup_class(self):
#打开浏览器
self.driver = webdriver.Chrome()
self.driver.maximize_window()
def setup_method(self):
#打开页面
self.driver.get(“https://hmshop-test.itheima.net/Home/user/login.html”)
def test_login(self):
#case02:登录失败(用户名为空)
self.driver.find_element(By.ID, “username”).send_keys(“”)
self.driver.find_element(By.ID, “password”).send_keys(“123456”)
self.driver.find_element(By.ID, “verify_code”).send_keys(“8888”)
self.driver.find_element(By.LINK_TEXT, “登 录”).click()
def test_login2(self):
#case03:登录失败(密码为空)
self.driver.find_element(By.ID, “username”).send_keys(“13488888888”)
self.driver.find_element(By.ID, “password”).send_keys(“”)
self.driver.find_element(By.ID, “verify_code”).send_keys(“8888”)
self.driver.find_element(By.LINK_TEXT, “登 录”).click()
def test_login3(self):
#case01:登录成功
self.driver.find_element(By.ID, “username”).send_keys(“13488888888”)
self.driver.find_element(By.ID, “password”).send_keys(“123456”)
self.driver.find_element(By.ID, “verify_code”).send_keys(“8888”)
self.driver.find_element(By.LINK_TEXT, “登 录”).click()
def teardown_method(self):
time.sleep(2)
def teardown_class(self):
#退出浏览器
time.sleep(3)
self.driver.quit()
在这里插入图片描述

2.PyTest配置文件运行

在这里插入图片描述

[pytest]
addopts = -s
testpaths = ./scripts
python_files = test*.py
python_classes = Test*
python_functions = test*

3.项目配置文件config.py
  • 技术点: 参数化(数据驱动)
  • 作用:将测试数据和测试脚本分离,后期代码维护焦点放在数据
  • 使用:装饰器@(不改变方法内部的代码逻辑 新增功能)
    @pytest.mark.parametrize==》循环遍历测试数据 调用测试脚本
  • 步骤:
    ① 准备测试数据,格式:[(),(),()]
    ② 在被测试方法前面引入装饰器
    @pytest.mark.parametrize(“保存数据的变量,注意变量个数=(中数据的个数)”, 测试数据)
    def test_login(self, 直接复制装饰器中保存数据的一组变量名即可):
    pass
    ③ 修改测试方法代码 引用变量中的数据完成测试

#导包
import time
import config
import pytest
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
test_data = [
(“”, “123456”, “8888”),
(“13488888888”, “”, “8888”),
(“13488887799”, “123456”, “8888”),
(“13488888888”, “123457”, “8888”),
(“13488888888”, “123456”, “8888”)
]
class TestLogin:
#类前置处理
def setup_class(self):
#打开浏览器
service = Service(executable_path=config.BASE_PATH +
‘/chromedriver.exe’)
self.driver = webdriver.Chrome(service=service)
#driver = webdriver.Chrome()
#窗口最大化
self.driver.maximize_window()
#类后置处理
def teardown_class(self):
#退出浏览器
self.driver.quit()
#方法前置处理
def setup_method(self):
#打开页面
self.driver.get(“https://hmshop-
test.itheima.net/index.php/Home/user/login.html”)
#方法后置处理
def teardown_method(self):
#等待3秒
time.sleep(3)
@pytest.mark.parametrize(“username, password, code”, test_data)
def test_login(self, username, password, code):
#页面定位+操作
self.driver.find_element(By.ID, “username”).send_keys(username)
self.driver.find_element(By.ID, “password”).send_keys(password)
self.driver.find_element(By.ID, “verify_code”).send_keys(code)
self.driver.find_element(By.NAME, “sbtbutton”).click()

4.参数化

  • 说明:通过参数的方式来传递数据,从而实现数据和脚本分离。并且可以实现用例的重复执行
  • 在这里插入图片描述

#导包
import time
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
test_data = [(“”, “123456”, “8888”),
(“13488888888”, “”, “8888”),
(“13488888888”, “123456”, “8888”)]
class TestLogin:
def setup_class(self):
#打开浏览器
self.driver = webdriver.Chrome()
self.driver.maximize_window()
def setup_method(self):
#打开页面
self.driver.get(“https://hmshop-test.itheima.net/Home/user/login.html”)
@pytest.mark.parametrize(“username, password, code”, test_data)
def test_login(self, username, password, code):
self.driver.find_element(By.ID, “username”).send_keys(username)
self.driver.find_element(By.ID, “password”).send_keys(password)
self.driver.find_element(By.ID, “verify_code”).send_keys(code)
self.driver.find_element(By.LINK_TEXT, “登 录”).click()
def teardown_method(self):
time.sleep(2)
def teardown_class(self):
#退出浏览器
time.sleep(3)
self.driver.quit()

5.断言

  • 说明:让程序代替人为判断测试程序执行结果是否符合预期结果的过程
  • 在这里插入图片描述
    在这里插入图片描述
  • 案例:断言登录成功后的用户信息
    在这里插入图片描述

#导包
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
class TestLogin:
def setup_class(self):
#打开浏览器
self.driver = webdriver.Chrome()
self.driver.maximize_window()
def setup_method(self):
#打开页面
self.driver.get(“https://hmshop-test.itheima.net/Home/user/login.html”)
def test_login(self):
#case01:登录成功
self.driver.find_element(By.ID, “username”).send_keys(“13488888888”)
self.driver.find_element(By.ID, “password”).send_keys(“123456”)
self.driver.find_element(By.ID, “verify_code”).send_keys(“8888”)
self.driver.find_element(By.LINK_TEXT, “登 录”).click(
time.sleep(3)
assert “13488888888” == self.driver.find_element(By.CLASS_NAME,
“userinfo”).text
def teardown_method(self):
time.sleep(2)
def teardown_class(self):
#退出浏览器
time.sleep(3)
self.driver.quit()

6.allure报告

  • 安装: pip install allure-pytest
    在这里插入图片描述
  • 验证: pip show allure-pytest
    在这里插入图片描述
  • 下载: https://github.com/allure-framework/allure2/releases
    在这里插入图片描述
  • 解压
    在这里插入图片描述
  • allure配置
    在这里插入图片描述
  • pytest.ini配置文件

[pytest]
addopts = -s --alluredir report
testpaths = ./scripts
python_files = test*.py
python_classes = Test*
python_functions = test*

  • 生成报告:
    ① 运行测试脚本:pytest
    ② 生成测试报告:allure serve report
    在这里插入图片描述
    在这里插入图片描述

文章转载自:

http://4GrV77j7.gfjgq.cn
http://hrDjWUuc.gfjgq.cn
http://oWBoBb2C.gfjgq.cn
http://kvlqpOtk.gfjgq.cn
http://yVvrOlOG.gfjgq.cn
http://t5tzkJra.gfjgq.cn
http://cFI3JkC8.gfjgq.cn
http://BxNzggjp.gfjgq.cn
http://t3F9oToI.gfjgq.cn
http://5tuCscq5.gfjgq.cn
http://O74NHf4s.gfjgq.cn
http://Co1jqOKR.gfjgq.cn
http://FN1UIFSa.gfjgq.cn
http://Fpw1YFYA.gfjgq.cn
http://bSqAmCb6.gfjgq.cn
http://cbGYCwP9.gfjgq.cn
http://YjNONqZC.gfjgq.cn
http://3rfkmPRp.gfjgq.cn
http://CpPuTgGw.gfjgq.cn
http://KSlXzxcJ.gfjgq.cn
http://8f4oe47W.gfjgq.cn
http://BFkMVeKP.gfjgq.cn
http://f5OvWBkQ.gfjgq.cn
http://JafZCV4d.gfjgq.cn
http://cLDH0nY9.gfjgq.cn
http://9Pk5E2VJ.gfjgq.cn
http://OvoDz8Wg.gfjgq.cn
http://pIZMlF6k.gfjgq.cn
http://gt16Z7dA.gfjgq.cn
http://8JBbwlgJ.gfjgq.cn
http://www.dtcms.com/wzjs/688984.html

相关文章:

  • 蔬菜网站模板建筑网片的用途
  • 音乐设计网站推荐上海公司购买新能源车条件
  • 直缝钢管网站建设wordpress页面背景
  • discuz视频网站模板虚拟主机有哪些
  • html 网站发布永春县建设局网站
  • 网站建设及推广方案ppt模板企业网站登录
  • 怎么做视频还有网站吗专业做旗袍花的网站是什么网站
  • 管理系统网站建设中企动力做网站的优势
  • 网站开发就业外部威胁郑州注册公司流程及费用
  • 商务网站建设报告书品牌网站怎么建设
  • wordpress资讯网站模板网站开发宝典
  • 电子贺卡免费制作网站开发网站排名优化
  • 在什么网站可以做外贸出口劳保鞋东莞市网站建设制作设计平台
  • 佛山网站建设与设计怎么在百度搜到自己的网站
  • 怎么做网站策划宁安市建设局网站
  • 建立网站的流程的合理顺序如何制作个人公众号
  • 网站开发如何兼容不同ie自助建站基础工作主要包括()
  • seo技术服务外包公司属于seo优化范畴的是
  • PS做任务的网站wordpress 自动缩进
  • 查域名网站按天计费的seo弊端
  • 生活家装饰官方网站澄海建网站
  • 哪一款软件可以自己做网站Sensei wordpress插件
  • 肇庆网站建设制作公司php网站开发系统
  • 高端品牌网站建设兴田德润怎么联系品牌建设 宣传
  • 团购网站的交易流程网站logo是什么意思
  • 常州seo网站推广白银网站建设白银
  • 生物科技 网站模板推盟
  • 精品网站建设教程青岛谁做网站多少钱
  • 石家庄最新状况锦绣大地seo
  • 2万元建设网站贵吗网站制作厦门