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

什么网站可以做2.5D场景郑州网络营销哪家正规

什么网站可以做2.5D场景,郑州网络营销哪家正规,新余 网站建设公司,网站建设会计科目1、Page Object模式简介 1、二层模型 Page Object Model(页面对象模型), 或者也可称之为POM。在UI自动化测试广泛使用的一种分层设计 模式。核心是通过页面层封装所有的页面元素及操作,测试用例层通过调用页面层操作组装业务逻辑。 1、实战 …

1、Page Object模式简介

1、二层模型

        Page Object Model(页面对象模型), 或者也可称之为POM。在UI自动化测试广泛使用的一种分层设计 模式。核心是通过页面层封装所有的页面元素及操作,测试用例层通过调用页面层操作组装业务逻辑。

1、实战 

目录如下:

home_page.py文件的内容:

from selenium.webdriver.common.by import Byclass HomePage:login_link_locator = (By.LINK_TEXT, '登录')def click_login_link(self,driver):# 前面加*号是解包的操作,因为login_link_locator是元组driver.find_element(*self.login_link_locator).click()

login_page.py文件的内容:

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import Byclass LoginPage:#属性->元素定位信息(元素定位方法+元素定位值)-元组类型phone_input_locator = (By.XPATH,'//input[@placeholder="请输入手机号/用户名"]')pwd_input_locator = (By.XPATH,'//input[@placeholder="请输入密码"]')login_button_locator = (By.CLASS_NAME,'login-button')#操作->元素行为,登录操作def page_login(self,driver,phone,pwd):# *self.phone_input_locator 前面的*号是解包使用的driver.find_element(*self.phone_input_locator).send_keys(phone)driver.find_element(*self.pwd_input_locator).send_keys(pwd)sleep(2)driver.find_element(*self.login_button_locator).click()

登录案例 - PO.py的文件内容:

from selenium import webdriver
from d6_JavaScript处理.testcases.home_page import HomePage
from d6_JavaScript处理.testcases.login_page import LoginPagedriver = webdriver.Chrome()
driver.maximize_window()
driver.get("http://mall.banan.com:3344/")
HomePage().click_login_link(driver)LoginPage().page_login(driver,"1723693766728","ydgcdlcb")

2、三层模型

        基本的PO分层包括页面层与用例层,但是在编写页面层代码时会发现一个问题:页面中存在非常多相同 的操作方法,比如都需要等待元素、获取元素属性/文本信息、页面滚动等等,每个页面层类都需要有相 同的代码,代码存在非常多冗余。我们可以把这些【公共】的页面操作方法给提取出来放到一个类中进 行维护,其他的页面类共用该类中的操作方法即可(通过继承实现)。

UI自动化断言:
        断言是自动化测试不可缺少的部分,当我们使用测试脚本对业务逻辑进行操作时,需要检查交互操作之 后结果的正确性,此时需要通过断言机制来进行验证。

        Pytest测试框架内置丰富的断言,通过assert语句即可,常见的断言方法比较包括:

  • 比较相等
assert a == b
  • 比较大小(大于/小于/大于等于/小于等于)
assert a > b
  • 内容包含/内容不包含
assert a in b
  • 验证表达式是否为真
assert condition
UI自动化常见的断言条件包括:
  • 通过当前页面的URL地址

  • 通过当前页面的标题
  • 通过当前页面的提示文本信息
  • 通过当前页面的某些元素变化/显示

一句话总结:通过肉眼观察页面的变化检查

3、三层模型实战

思路:抽取一个公共类,这个类中可以写公共页面的属性和函数,也可以写每次都要使用的属性,从UI自动化的角度来看,浏览器驱动是每次执行用例都会用到的,所以也可以抽取出来。

三层模型的文件目录如下:

base_page.py文件中的内容:

import osfrom selenium.webdriver import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait# BasePage 用来存放所有页面类的公共部分,一些公共的操作(显式封装)
class BasePage:def __init__(self,driver):self.driver = driver# 封装的意思:把相同类似的代码放到一个函数里面,重复使用# locator是元组的类型def wait_element_clickable(self, locator):web_element = WebDriverWait(self.driver,5,0.5).until(EC.element_to_be_clickable(locator))return web_elementdef wait_element_visible(self, locator):# web_element代表通过显示等待找到的元素web_element = WebDriverWait(self.driver,5,0.5).until(EC.visibility_of_element_located(locator))return web_elementdef wait_element_presence(self, locator):web_element = WebDriverWait(self.driver,5,0.5).until(EC.presence_of_all_elements_located(locator))return web_element# JavaScript进行元素的滚动def page_scroll(self,distance):self.driver.execute_script(f"document.documentElement.scrollTop={distance}")# JavaScript进行元素的点击def page_js_click(self,locator):element = self.wait_element_visible(self.driver,locator)self.driver.execute_script("arguments[0].click()",element)# JavaScript进行元素的移除def remove_element_attribute(self,locator,attribute):element = self.wait_element_visible(self.driver,locator)self.driver.execute_script(f"arguments[0].removeAttribute({attribute})", element)# 鼠标点击def mouse_click(self,locator):element = self.wait_element_visible(self.driver,locator)ActionChains(self.driver).click(element).perform()# 窗口切换def switch_to_window(self,title):handles = self.driver.window_handlesfor handle in handles:if self.driver.title == title:breakelse:self.driver.switch_to.window(handle)# 文件上传def update_file(self,filepath):os.system(f"test.exe {filepath}")

home_page.py文件中的内容:

import timefrom selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from PO模式优化与自动化用例断言.common.base_page import BasePageclass HomePage(BasePage):# 属性-登录链接login_link_locator = (By.LINK_TEXT,'登录')# 欢迎提示信息welcome_tips_locator = (By.XPATH,'//span[text()="欢迎来到天使的世界"]')welcome_tips_text_locator = (By.XPATH,'//span[@class="text"]')# 用户名username_text_locator = (By.XPATH,'//a[@class="link-name"]')def click_login_link(self):self.wait_element_clickable(self.login_link_locator).click()def is_display_welcome_tips(self):time.sleep(2)# return  self.wait_element_clickable(self.welcome_tips_locator).is_displayed()return self.wait_element_clickable(self.welcome_tips_text_locator).textdef get_username_text(self):return self.wait_element_visible(self.username_text_locator).text

login_page.py文件中的内容: 

import timefrom selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from PO模式优化与自动化用例断言.common.base_page import BasePageclass LoginPage(BasePage):# 属性->元素定位信息(元素定位方法+元素定位值)-元组类型phone_input_locator = (By.XPATH, '//input[@placeholder="请输入手机号/用户名"]')pwd_input_locator = (By.XPATH, '//input[@placeholder="请输入密码"]')login_button_locator = (By.CLASS_NAME, 'login-button')login_tips_locator = (By.XPATH, '//p[@class="el-message__content"]')def login(self,phone,pwd):# 因为继承了 basepage类,所以克不用再写driver参数# self.wait_element_visible(self.driver,self.phone_input_locator).send_keys("17728373518")self.wait_element_visible(self.phone_input_locator).send_keys(phone)self.wait_element_visible(self.pwd_input_locator).send_keys(pwd)self.wait_element_clickable(self.login_button_locator).click()time.sleep(3)def get_login_tips(self):# 这里比较文本内容return self.wait_element_visible(self.login_tips_locator).textprint(self.wait_element_visible(self.login_tips_locator).text)

test_login.py文件中的内容

from selenium import webdriver
from d7_PO模式优化与自动化用例断言.pageobjects.home_page import HomePage
from d7_PO模式优化与自动化用例断言.pageobjects.login_page import LoginPagedef test_login_success():driver = webdriver.Chrome()driver.get("http://mall.banan.com:3344/")driver.maximize_window()# 点击首页的登录操作homepage = HomePage(driver)homepage.click_login_link()# 在登陆页面进行登录操作loginpage = LoginPage(driver)loginpage.login("le_auto","le123456")# 断言检测测试是否成功(通过预期结果和实际结果的比较)#  检查点:1、欢迎页,如果函数的返回值为True,那么断言之后返回是通过的assert homepage.is_display_welcome_tips()# assert loginpage.get_login_tips() == '账号或者密码不正确'assert homepage.get_username_text() == 'lemon_auto'# 对登录结果的断言
def test_login_uncorrect_username():driver = webdriver.Chrome()driver.get("http://mall.banan.com:3344/")homepage = HomePage(driver)homepage.click_login_link()# 在登陆页面进行登录操作loginpage = LoginPage(driver)loginpage.login("le_auto1", "le123456")# 页面登录过程中的提示信息断言assert loginpage.get_login_tips() == '账号或密码不正确'

2、PO模式的优点

1、提高测试用例的可读性

2、提高测试用例可维护性

3、减少代码重复


文章转载自:
http://areography.jjpk.cn
http://sidon.jjpk.cn
http://workload.jjpk.cn
http://chlorpicrin.jjpk.cn
http://ostracize.jjpk.cn
http://broadmoor.jjpk.cn
http://laconia.jjpk.cn
http://despite.jjpk.cn
http://jd.jjpk.cn
http://cyberpunk.jjpk.cn
http://cheer.jjpk.cn
http://instigation.jjpk.cn
http://deepmost.jjpk.cn
http://dispensable.jjpk.cn
http://moneychanging.jjpk.cn
http://auriform.jjpk.cn
http://computus.jjpk.cn
http://ballyhack.jjpk.cn
http://dimethyltryptamine.jjpk.cn
http://gls.jjpk.cn
http://ciphertext.jjpk.cn
http://decimetre.jjpk.cn
http://throwaway.jjpk.cn
http://hyaena.jjpk.cn
http://volcaniclastic.jjpk.cn
http://stegomyia.jjpk.cn
http://bristly.jjpk.cn
http://soubresaut.jjpk.cn
http://exasperate.jjpk.cn
http://outdistance.jjpk.cn
http://multicylinder.jjpk.cn
http://bridgehead.jjpk.cn
http://larry.jjpk.cn
http://thick.jjpk.cn
http://welder.jjpk.cn
http://dissidence.jjpk.cn
http://costean.jjpk.cn
http://slashing.jjpk.cn
http://unenjoyable.jjpk.cn
http://nodi.jjpk.cn
http://graywacke.jjpk.cn
http://metempsychosis.jjpk.cn
http://pyrrhonism.jjpk.cn
http://governorship.jjpk.cn
http://deanna.jjpk.cn
http://sou.jjpk.cn
http://xenate.jjpk.cn
http://isospin.jjpk.cn
http://cauda.jjpk.cn
http://barnacle.jjpk.cn
http://chancellor.jjpk.cn
http://synectic.jjpk.cn
http://setiparous.jjpk.cn
http://primacy.jjpk.cn
http://carvacrol.jjpk.cn
http://vibrato.jjpk.cn
http://quaker.jjpk.cn
http://simazine.jjpk.cn
http://bawcock.jjpk.cn
http://gallfly.jjpk.cn
http://disfavor.jjpk.cn
http://deeply.jjpk.cn
http://effusive.jjpk.cn
http://syllabicate.jjpk.cn
http://proenzyme.jjpk.cn
http://rissole.jjpk.cn
http://serialize.jjpk.cn
http://antacid.jjpk.cn
http://marlin.jjpk.cn
http://quivery.jjpk.cn
http://joyance.jjpk.cn
http://bibliotics.jjpk.cn
http://daybill.jjpk.cn
http://cyclist.jjpk.cn
http://goody.jjpk.cn
http://incubator.jjpk.cn
http://sharecrop.jjpk.cn
http://affricate.jjpk.cn
http://revascularization.jjpk.cn
http://necessarian.jjpk.cn
http://buprestid.jjpk.cn
http://dipter.jjpk.cn
http://cokernut.jjpk.cn
http://pagan.jjpk.cn
http://heilungkiang.jjpk.cn
http://ovid.jjpk.cn
http://tashkent.jjpk.cn
http://subcylindrical.jjpk.cn
http://monochromatize.jjpk.cn
http://mouthwatering.jjpk.cn
http://brazenly.jjpk.cn
http://papua.jjpk.cn
http://strangles.jjpk.cn
http://whitening.jjpk.cn
http://fac.jjpk.cn
http://perambulatory.jjpk.cn
http://blandiloquence.jjpk.cn
http://nymphaeaceous.jjpk.cn
http://condonable.jjpk.cn
http://bunchberry.jjpk.cn
http://www.dt0577.cn/news/72237.html

相关文章:

  • 广州网站优化公司咨询百度爱采购优化排名软件
  • 网站建设会议新闻头条今日新闻
  • 网站建设选青岛的公司好不好一份完整的品牌策划方案
  • 奉贤高端网站建设国际最新十大新闻事件
  • 武汉设计公司网站嘉兴新站seo外包
  • 二级域名网址seo是什么岗位
  • 用webstorm做静态网站seo快速排名优化方式
  • 工程行业做的好的网站有哪些内容北京网站优化
  • 做网站图片视频加载慢百度指数怎么算
  • 企业微信网站建设方案交易链接
  • 个人网站建设的意义seo基础
  • 赣州有做网站推广的公司吗好的竞价账户托管外包
  • 网站开发后端 书网盟推广
  • 网站网警备案流程公司软文推广
  • 网站导航栏分析sem是什么意思?
  • 教人做家务的网站seo评测论坛
  • 程序员做网站外快百度站长提交网址
  • 佛山网站开发公司想要导航页面推广app
  • 公司门户网站适合40岁女人的培训班
  • 外贸网站建设盲区推广平台网站有哪些
  • 南昌做网站后台投票国际新闻界期刊
  • 哪种网络营销方式最好seo排名分析
  • 杭州网站建设制作公司如何seo搜索引擎优化
  • 官方网站建设seo应用领域有哪些
  • 网站图片速度网络热词有哪些
  • 泉州网站建站推广成都调查事务所
  • 做窗帘的厂家网站武汉seo排名优化公司
  • 吴江城乡和住房建设局网站十大免费无代码开发软件
  • 公司网站横幅是做的吗域名被墙查询检测
  • 网站如何做推广效果好天津百度seo推广