web自动化测试框架搭建封装

时间: 2023-12-10 16:33:41 浏览: 48
根据提供的引用内容,我们可以了解到一个WEB UI自动化测试框架的三个核心模块:对象层、逻辑层和业务层。下面是一个简单的WEB UI自动化测试框架搭建封装的步骤: 1. 安装Python和Selenium库 ```shell pip install selenium ``` 2. 创建一个基础类BasePage,用于封装一些基础方法,例如元素定位、点击、输入等操作。 ```python from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By class BasePage(object): def __init__(self, driver): self.driver = driver def find_element(self, locator, timeout=10): element = WebDriverWait(self.driver, timeout).until(EC.presence_of_element_located(locator)) return element def click(self, locator): element = self.find_element(locator) element.click() def input_text(self, locator, text): element = self.find_element(locator) element.clear() element.send_keys(text) ``` 3. 创建一个页面类,继承BasePage类,并实现该页面的元素定位和控件操作方法。 ```python from selenium.webdriver.common.by import By from base_page import BasePage class LoginPage(BasePage): # 元素定位 username_input = (By.ID, 'username') password_input = (By.ID, 'password') login_button = (By.ID, 'login-button') # 控件操作方法 def input_username(self, username): self.input_text(self.username_input, username) def input_password(self, password): self.input_text(self.password_input, password) def click_login_button(self): self.click(self.login_button) ``` 4. 创建一个逻辑层类,用于实现一些功能用例的模块。 ```python from page.login_page import LoginPage class LoginAction(object): def __init__(self, driver): self.driver = driver self.login_page = LoginPage(self.driver) def login(self, username, password): self.login_page.input_username(username) self.login_page.input_password(password) self.login_page.click_login_button() ``` 5. 创建一个业务层类,用于实现测试用例的操作部分。 ```python from selenium import webdriver from action.login_action import LoginAction class TestLogin(object): def setup_method(self): self.driver = webdriver.Chrome() self.driver.maximize_window() self.driver.get('http://www.example.com') def teardown_method(self): self.driver.quit() def test_login(self): login_action = LoginAction(self.driver) login_action.login('username', 'password') # 添加断言等测试用例操作 ```

相关推荐

最新推荐

recommend-type

二十三种设计模式【PDF版】

状态是编程中经常碰到的实例,将状态对象化,设立状态变换器,便可在状态中轻松切换. 设计模式之 Memento(注释状态?) 很简单一个模式,就是在内存中保留原来数据的拷贝. 设计模式之 Interpreter(解释器) 主要用来对...
recommend-type

华为OD机试D卷 - 用连续自然数之和来表达整数 - 免费看解析和代码.html

私信博主免费获取真题解析以及代码
recommend-type

Screenshot_2024-05-10-20-21-01-857_com.chaoxing.mobile.jpg

Screenshot_2024-05-10-20-21-01-857_com.chaoxing.mobile.jpg
recommend-type

数字图像处理|Matlab-频域增强实验-彩色图像的频域滤波.zip

数字图像处理|Matlab-频域增强实验-彩色图像的频域滤波.zip
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

list根据id查询pid 然后依次获取到所有的子节点数据

可以使用递归的方式来实现根据id查询pid并获取所有子节点数据。具体实现可以参考以下代码: ``` def get_children_nodes(nodes, parent_id): children = [] for node in nodes: if node['pid'] == parent_id: node['children'] = get_children_nodes(nodes, node['id']) children.append(node) return children # 测试数
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依