web UI自动化项目实战-项目

项目使用禅道,所以你需要搭建1个禅道,搭建禅道的方法和步骤见

https://www.cnblogs.com/xinhua19/p/13151296.html

搭建UI自动化的框架

第一步,搭建框架,从配置文件信息开始,然后读取配置文件,然后是读取驱动。

第二步,对selenium中的一些方法做二次封装

第三步,封装页面的元素对象和元素的新增,删除,查询,修改等操作

第四步,测试用例层,设计测试用例

selenium读取配置文件的方法封装

有了配置config.ini的配置文件,肯定是要读取这个配置文件的,话不多说,直接上代码

import os
import codecs
import configparser
import logging proDir = os.path.split(os.path.realpath(__file__))[0]
rootDir = os.path.dirname(proDir)
dataDir = os.path.join(rootDir, "data")
configPath = os.path.join(rootDir, "config", "config.ini") class ReadConfig:
def __init__(self):
fd = open(configPath)
data = fd.read() # remove BOM
if data[:3] == codecs.BOM_UTF8:
data = data[3:]
file = codecs.open(configPath, "w")
file.write(data)
file.close()
fd.close() self.cf = configparser.ConfigParser()
self.cf.read(configPath) def get_email(self, name):
value = self.cf.get("EMAIL", name)
return value def get_http(self, name):
value = self.cf.get("HTTP", name)
return value def get_db(self, name):
value = self.cf.get("DATABASE", name)
return value def get_postgresql(self, name):
value = self.cf.get("POSTGRESQL", name)
return value def get_loglevel(self, name):
value = self.cf.get("LOG", name)
return value def get_account(self, name):
value = self.cf.get("ACCOUNT", name)
return value def get_accounts(self):
return self.cf.items("ACCOUNT") def get_webapp(self, name):
return self.cf.get("WEBAPP", name)

那么读取到了配置文件信息后,肯定也是要应用配置文件的,话不多说,直接上代码

# coding:utf-8
import time
from utils import readconfig
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC localReadConfig = readconfig.ReadConfig() class BasePage:
scheme = localReadConfig.get_http("scheme")
base_url = scheme + r"://" + localReadConfig.get_http("baseurl")+':'+localReadConfig.get_http("port")+'/zentao' def __init__(self, driver, url=None):
self.url = url
self.driver = driver
self.timeout = 12
self.wait = WebDriverWait(self.driver, self.timeout) self.url = self.base_url
if url:
self.url = self.base_url + url def open(self, url=None):
if not url:
self.driver.get(self.url)
else:
self.driver.get(url)
self.driver.maximize_window() def wait_for_element_presence(self, locator):
self.wait.until(EC.presence_of_element_located(locator)) def find_element(self, locator):
try:
return self.driver.find_element(*locator)
except Exception as e:
print("element not be found {}".format(locator[1]))
print("python tell us: {}".format(str(e)))
return None def wait_for_element_visible(self, locator):
self.wait.until(EC.visibility_of_element_located(locator)) def wait_for_element_invisible(self, locator):
self.wait.until(EC.invisibility_of_element(locator)) def implicitly_wait(self, time_to_wait=3):
self.driver.implicitly_wait(time_to_wait) @staticmethod
def sleep(t=1):
time.sleep(t)

selenium读取驱动的方法封装

selenium常用方法的二次封装

页面元素对象和 操作的封装

测试用例调用操作,执行测试用例

HTMLTestRunner,py 生成报告

执行结束查看报告

最新文章

  1. Oracle学习笔记七 锁
  2. 自定义控件(View的绘制流程源码解析)
  3. 跟我学Windows Azure 三 使用vs2013创建windows azure web site
  4. C#实现堆栈
  5. CSS3盒模型温故
  6. 阿里云+wordpress搭建个人博客网站【小白专用的图文教程】
  7. D3D的绘制
  8. mysqldump 参数说明
  9. 《A First Course in Probability》-chaper6-随机变量的联合分布-独立性
  10. Android之ListView性能优化
  11. openstack 入门1
  12. JS子元素oumouseover触发父元素onmouseout
  13. warfare(最大生成树裸题)
  14. Mysql5.7 安装
  15. 面向对象重写(override)与重载(overload)区别
  16. java面试题之分析(二)
  17. Notepad++ 安装连接服务器的NppFTP插件
  18. android查看屏幕密度,分辨率的shell命令
  19. 向Word添加一段文本
  20. igmpproxy启动时错误:There must be at least 2 Vif's where one is upstream.

热门文章

  1. Java实现俄式乘法
  2. http1.0 、http1.1和http2.0的区别
  3. Spring Boot 集成 Swagger 构建接口文档
  4. ES 复合查询
  5. 2.vue-常用指令
  6. [CF696D]Legen...
  7. Dos命令提示符下 - 用sqlcmd执行*.sql语句
  8. Excel数据透视表的日常应用技巧
  9. TypeError: this.xxx.substring is not a function的解决办法
  10. c常用函数-strcat 和 strncat