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

做网站爱高级搜索

做网站爱,高级搜索,wordpress.org 移除,安徽省住房和城乡建设厅网站首页前言 可怜的宾馆,可怜得像被12月的冷雨淋湿的一条三只腿的黑狗。——《舞舞舞》 \;\\\;\\\; 目录 前言test_1或s_test格式非测试文件pytest.fixture()装饰器pytestselenium test_1或s_test格式 要么 test_前缀 在前,要么 _test后缀 在后! …

前言

可怜的宾馆,可怜得像被12月的冷雨淋湿的一条三只腿的黑狗。——《舞舞舞》

在这里插入图片描述


\;\\\;\\\;

目录

    • 前言
    • test_1或s_test格式
    • 非测试文件
    • @pytest.fixture()装饰器
    • pytest+selenium

test_1或s_test格式

要么 test_前缀 在前,要么 _test后缀 在后!

#test_1.py
def test_1():name='aa'assert 'bb'==namedef test_2():name='a'assert 'bcb'==namedef test_3():a = 1assert a == 2def test_4():a = 4assert a == 2assert 'a' in 'abc'assert 'a' not in 'abc'assert 'a' is not Trueassert 'a' is False

右击可以单独运行某个函数,看看哪个错了!

class TestTint:def test_5(self):a = 1assert a == 2def test_6(self):a = 1assert a == 2def test_7(self):a = 1assert a == 2

在这里插入图片描述

\;\\\;\\\;

非测试文件

如果是按pytest格式的文件名,但是内容不是测试的话,那么会出现(没有发现测试)

#test_calc.py
a = 1
b = 2
print(a + b)

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

@pytest.fixture()装饰器

import pytest@pytest.fixture(scope='function')
def fixture1():print('前置步骤1')return 4@pytest.fixture(scope='function')
def fixture2():print('前置步骤2')return 2@pytest.fixture(scope='function',autouse=True)
def fixture3():print('前置步骤3')return 2def test_1(fixture1,fixture2):assert fixture1 == 2assert fixture2 == 2def test_2(fixture3):assert fixture3 == 2if __name__ == '__main__':pytest.main()

可以在测试函数的位置,右击运行test_1或test_2函数

\;\\\;\\\;

pytest+selenium

关于selenium使用的edge驱动器,版本要和电脑上装的edge版本一致!

pytest类要以Test为前缀

#test_f.py
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import pytest# 前置方法
@pytest.fixture(scope='class')
def driver():driver = webdriver.Edge(executable_path=r"C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Scripts\msedgedriver.exe")#C:\ProgramData\anaconda3\Scripts\msedgedriver.exereturn driverclass TestSpider:# fixture函数作为形参def test_baidu(self, driver):driver.get('https://www.baidu.com/')title = driver.titleurl = driver.current_urltext = driver.find_element(By.CSS_SELECTOR, "a[href*='news.baidu.com']").textbutton = driver.find_element(By.ID, 'su').get_attribute('value')# 检测assert title == '百度一下,你就知道'assert url == 'https://www.baidu.com/'assert text == '新闻'assert button == '百度一下'# sleep(3)
# driver.close()if __name__ == '__main__':pytest.main()

运行命令 pytest test_f.py

http://www.hkea.cn/news/546364/

相关文章:

  • 什么网站做海报b站不收费网站
  • 如何自己做个简单网站seo知识点
  • 有哪些做批发的网站有哪些手续百度推广优化是什么意思
  • 用阿里巴巴店铺做公司网站怎么样引擎搜索有哪些
  • 网页制作软件属于什么软件类别简述seo的优化流程
  • 网站建设 公司新闻谷歌排名网站优化
  • 怎样做自己的vip解析网站佛山外贸seo
  • 我的网站在百度搜不到了seo是什么职业做什么的
  • 网站私信界面国外网站seo免费
  • wordpress mysql类惠州网站seo
  • 为什么做网站必须要用域名举出最新的网络营销的案例
  • 电子请柬网站开发百度竞价推广登录入口
  • 网站设计与推广国际时事新闻2022最新
  • 柬埔寨网站开发营销技巧和营销方法
  • 网站建立价格长沙网站外包公司
  • 王建设医生个人网站免费google账号注册入口
  • 免费自建手机网站搜索引擎优化的方法包括
  • 甘肃省建设工程安全质量监督管理局网站官网拉新项目官方一手平台
  • 做电影网站赚钱武汉新闻最新消息
  • 做网站没有成本的方法上海百度分公司电话
  • 寺庙网站建设百度ai人工智能
  • 完成公司网站建设下载关键词推广软件
  • wordpress如何关闭网站下载app
  • WordPress小程序二次修改石家庄seo排名外包
  • 做百度关键词网站厦门seo外包
  • 泉州seo-泉州网站建设公司谷歌关键词搜索工具
  • 组织部网站建设方案行业关键词分类
  • 上海黄浦 网站制作中国搜索引擎排名2021
  • 手机网站建设 cms营销技巧和营销方法
  • 平顶山做网站优化微博搜索引擎优化