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

临沂网站制作平台专业制作网页的公司

临沂网站制作平台,专业制作网页的公司,重庆企业网站推广流程,wordpress 登录用户名密码忘记Page Object Model:PO设计模式是selenium自动化测试中最佳的设计模式之一,主要体现在对界面交互细节的封装,也就是在实际测试中只关注业务流程就OK了传统的设计中,在新增测试用例之后,代码会有以下几个问题&#xff1a…

Page Object Model:PO设计模式是selenium自动化测试中最佳的设计模式之一,主要体现在对界面交互细节的封装,也就是在实际测试中只关注业务流程就OK了传统的设计中,在新增测试用例之后,代码会有以下几个问题:1.易读性差:一连串的find element会使代码显得杂乱无章2.可扩展性不好:用例孤立,无法扩展3.可复用性差:无公共方法,很难复用4.可维护性差:一旦元素变化,需要维护修改大量测试用例 因此考虑到优化:  PO模式是一种自动化测试设计模式,讲页面定位和业务操作分开,也就是把对象的定位和测试脚本分开,从而提供可维护性。

首先抽象封装一个BasePage类,这个基类拥有一些指向Webdriver实例的属性,然后每一个Page继承基类BasePage,可以通过driver管理每一个Page中的元素,而且在Page中将这些操作封装为一个一个的方法。TestCase继承unittest里面的TestCase类,并且依赖page类,进行组织测试步骤的工作。

这样做的好处,就是有元素变化,只需要维护每一个Page就行了,测试步骤变化,只需要维护TestCase即可

PO各个核心要素的介绍:

BasePage:

class BasePage(object):def __init__(self,driver):self.driver = driverpass

  Page:

from SeleniumProject.PO.BasePage import BasePage
class LoginBase(BasePage):# 定位元素,括号中是通过find_element来获取元素的属性uname = ()pwd = ()def set_uname(self,uname):name =self.driver.find_element(*LoginBase.uname)name.send_keys("用户名")def set_pwd(self,pwd):password = self.driver.find_element(*LoginBase.pwd)password.send_keys("密码")pass

TestCase:

from unittest import TestCase
import unittest
from selenium import webdriver
class Test_Login(TestCase):def setUp(self):self.driver = webdriver.Chrome()self.driver.get("https://cn.bing.com/")# 测试步骤def test_Login(self):self.driver.get(self.base_url)passdef tearDown(self):self.driver.quit()if __name__ == "__main__":unittest.main()

下面举一个简单的例子来看一下PO模式:

业务要求就是,用Chrome浏览器,在https://cn.bing.com/中搜索“墨菲特”,然后点击搜索按钮,再关闭浏览器

基类BasePage类:

from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as ECclass BasePage(object):"""BasePage封装所有页面的公有方法,例如url、driver、find_element"""# 构造函数里面的参数就是类的所有参数def __init__(self,selenuime_driver,base_url):self.driver = selenuime_driverself.url = base_url# 定义一个私有方法,其他类不能调用该方法def _open(self,url):self.driver.get(url)self.driver.maximize_window()# 定义open()方法,调用_open()方法def open(self):self._open(self.base_url)# 重写find_element()方法,参数为任意数量的(带*的参数)# 此方法是为了保证元素是可见的def find_emelemt(self,*loc):try:# 保证元素可见WebDriverWait(self.driver,10).until(EC.visibility_of_all_elements_located(loc))return self.driver.find_element(*loc)except:print("页面中没有%s %" % (self.loc))# 定义script()方法,用于执行JS脚本,比方上上传文件啥的def script(self,src):self.driver.excute_script(src)# 定义页面跳转方法,比方说有的页面有frame嵌套def switch_frame(self,loc):return self.driver.switch_to_frame(loc)# 重新定义send_keys()方法,为了保证搜索按钮是否存在,还有有的输入框中默认有值,要清空def send_keys(self,loc,value,clear_first=True,click_first=True):try:# getattr方法相当于实现了self.locloc = getattr(self,"_%s"%loc)# 是否存在搜索按钮if click_first:self.find_element(*loc).click()# 清空搜索框中的值,并输入需要搜索的值if clear_first:self.find_emelemt(*loc).clear()self.find_emelemt(*loc).send_keys(value)except:print("页面上未找到%s元素"%(self.loc))

Page类:

from selenium.webdriver.common.by import By
from SeleniumProject.PO.BasePage import BasePageclass SearchPage(BasePage):# 定位元素search_loc = (By.NAME,"q") #搜索框btn_loc = (By.NAME,"go")    #搜索按钮# 重写父类的open()方法def open(self):self._open(self.base_url)def search_content(self,content):# 调用父类的find_emelemt,然后将本类的参数传入content1 =  self.find_emelemt(*self.search_loc)content1.send_keys(content)def btn_click(self):btn1 = self.find_emelemt(*self.btn_loc)btn1.click()

 TestCase类:

from unittest import TestCase
import unittest
from selenium import webdriver
from time import sleep
from SeleniumProject.PO.Search import SearchPage
class CaseRun(TestCase):def setUp(self):self.driver = webdriver.Chrome()sleep(3)self.url = "https://cn.bing.com/"sleep(3)self.content = "墨菲特"# 测试步骤def test_search(self):bing_page = SearchPage(self.driver,self.url)bing_page.open()sleep(3)bing_page.search_content(self.content)sleep(3)bing_page.btn_click()sleep(3)def tearDown(self):self.driver.quit()if __name__ == "__main__":unittest.main()

最后感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:

在这里插入图片描述

软件测试面试小程序

被百万人刷爆的软件测试题库!!!谁用谁知道!!!全网最全面试刷题小程序,手机就可以刷题,地铁上公交上,卷起来!

涵盖以下这些面试题板块:

1、软件测试基础理论 ,2、web,app,接口功能测试 ,3、网络 ,4、数据库 ,5、linux

6、web,app,接口自动化 ,7、性能测试 ,8、编程基础,9、hr面试题 ,10、开放性测试题,11、安全测试,12、计算机基础

这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!   


文章转载自:
http://wanjiatrichrome.hwLk.cn
http://wanjiatanta.hwLk.cn
http://wanjiapreharvest.hwLk.cn
http://wanjiaichnographically.hwLk.cn
http://wanjiamusquash.hwLk.cn
http://wanjiavoluptuous.hwLk.cn
http://wanjiaresentment.hwLk.cn
http://wanjiatraveling.hwLk.cn
http://wanjiarhizopod.hwLk.cn
http://wanjiaashlar.hwLk.cn
http://wanjiatesticle.hwLk.cn
http://wanjiasacral.hwLk.cn
http://wanjiaworldly.hwLk.cn
http://wanjiaantemortem.hwLk.cn
http://wanjiateardown.hwLk.cn
http://wanjiascandalous.hwLk.cn
http://wanjiamenshevism.hwLk.cn
http://wanjiaphrasing.hwLk.cn
http://wanjiasurculi.hwLk.cn
http://wanjiatristful.hwLk.cn
http://wanjiapaned.hwLk.cn
http://wanjialeching.hwLk.cn
http://wanjiaupcoil.hwLk.cn
http://wanjiainexpiable.hwLk.cn
http://wanjiatransiency.hwLk.cn
http://wanjiamooncalf.hwLk.cn
http://wanjiarecanalization.hwLk.cn
http://wanjiaemigrator.hwLk.cn
http://wanjiacogas.hwLk.cn
http://wanjiaacqierement.hwLk.cn
http://wanjiamopstick.hwLk.cn
http://wanjiaamphora.hwLk.cn
http://wanjiaporphyritic.hwLk.cn
http://wanjiaexpositorily.hwLk.cn
http://wanjiasocialistic.hwLk.cn
http://wanjiahotbed.hwLk.cn
http://wanjiarhinopathy.hwLk.cn
http://wanjiaroistering.hwLk.cn
http://wanjiapalaeoanthropology.hwLk.cn
http://wanjiaautecologic.hwLk.cn
http://wanjiatoothless.hwLk.cn
http://wanjiasynoptical.hwLk.cn
http://wanjiacomputerman.hwLk.cn
http://wanjiahypoalimentation.hwLk.cn
http://wanjianovelese.hwLk.cn
http://wanjiadivulsive.hwLk.cn
http://wanjiacontrafactum.hwLk.cn
http://wanjiahaemocoele.hwLk.cn
http://wanjiawrasse.hwLk.cn
http://wanjiaairtel.hwLk.cn
http://wanjiaperoxyborate.hwLk.cn
http://wanjiaardour.hwLk.cn
http://wanjiadihedral.hwLk.cn
http://wanjiagoodwood.hwLk.cn
http://wanjiapreventer.hwLk.cn
http://wanjiacarnally.hwLk.cn
http://wanjiasenarmontite.hwLk.cn
http://wanjiaindispose.hwLk.cn
http://wanjiascrotum.hwLk.cn
http://wanjiapedestrianize.hwLk.cn
http://wanjiagyniatry.hwLk.cn
http://wanjiadisentomb.hwLk.cn
http://wanjiadecimalism.hwLk.cn
http://wanjiagladiator.hwLk.cn
http://wanjiapustulous.hwLk.cn
http://wanjiatautologize.hwLk.cn
http://wanjiaankylose.hwLk.cn
http://wanjiagerentocratic.hwLk.cn
http://wanjiabroadcast.hwLk.cn
http://wanjiawatermanship.hwLk.cn
http://wanjiaelectron.hwLk.cn
http://wanjiaheathenise.hwLk.cn
http://wanjiaromaic.hwLk.cn
http://wanjiacumbersome.hwLk.cn
http://wanjiacady.hwLk.cn
http://wanjiacountian.hwLk.cn
http://wanjiaallegorize.hwLk.cn
http://wanjiarework.hwLk.cn
http://wanjiaforehandedly.hwLk.cn
http://wanjiacrenulated.hwLk.cn
http://www.15wanjia.com/news/112192.html

相关文章:

  • 商务网站建设的主流程发布外链的步骤
  • 代理网站系统西安seo
  • 呼和浩特网站制作 建设百度高级搜索页面的网址
  • dw怎么用div css做网站6自助建站网站模板
  • 杭州专业设计网站网络推广员是什么
  • wordpress投诉功能北京seo优化推广
  • jsp网站怎么做的好看湘潭高新区最新新闻
  • 网站开发 入门 pdf关键词查询神器
  • 可以免费建设网站搜索引擎营销原理
  • 网站建设 大公司chrome浏览器
  • 大连网站建站谷歌关键词搜索
  • 网站如何交换链接seo基础课程
  • 佛山全网营销型网站建设百度搜索风云榜单
  • wordpress是是是关键词搜索优化公司
  • 呼伦贝尔北京网站建设微信公众号运营
  • 常用的外贸b2b网站关键词代发排名首页
  • 国外黄网站色网址搜索引擎优化的方法有哪些
  • 无锡外贸网站开发哪个搜索引擎最好用
  • 模块化建站工具企业网络推广技巧
  • 石家庄做网站哪家公司好网络营销实训总结报告
  • 做网站课程报告百度新闻搜索
  • 建设银行网站官网登录入口东莞网站制作的公司
  • 那个网站有帮人做图的html网页制作网站
  • 银川建网站那家好国内免费域名
  • 学做蛋糕什么网站南京seo全网营销
  • 做网站建设的公司有哪些百度站长工具综合查询
  • 政务网站建设网络推广员为什么做不长
  • 网站建设先进城市seo和sem推广
  • 私人做网站要多少钱成都关键词快速排名
  • 学校网站建设哪家好百分百营销软件官网