项目作者: seoktaehyeon

项目描述 :
An end-to-end automation solution for web product testing using Selenium + RobotFramework + Allure Reporting Tool
高级语言: Python
项目地址: git://github.com/seoktaehyeon/sraFramework.git
创建时间: 2021-02-22T02:01:03Z
项目社区:https://github.com/seoktaehyeon/sraFramework

开源协议:MIT License

下载


sraFramework

An end-to-end automation solution for web product testing using Selenium + RobotFramework + Allure Reporting Tool

利用 Selenium + RobotFramework + Allure Reporting Tool 设计的一套关于 Web 端到端自动化解决方案

环境准备

  • Chrome + Webdriver
    Webdriver 列表
  • Bash
  • Python3
  • Python 依赖包
    pip install -r requirements.txt
  • RobotFramework
  • JRE + Allure Commandline (可选)
    Allure 安装方法
  • Docker (可选)

目录结构

目录 作用 文件命名 文件内容示例
testcase 用于存放测试用例 \.robot testcase/demo.robot
keywords 用于存放关键字
以便在编写 testcase 中的用例时引用
\\.robot keywords/qsphereVision.robot
pages 用于存放封装好的页面元素操作函数
以便在封装 keywords 中的关键字时使用
\/\.py pages/qsphere/Vision.py
elements 用于存放页面元素的 xpath
以便被 pages 中的函数加载
\/\.yaml elements/qsphere/Vision.yaml
common 用于存放与产品解耦的基础函数
以便被 pages 中的函数调用
xxx.py common/Browser.py
config 用于存放用例执行过程中使用的全局变量和测试数据
以便在 testcase 或 keywords 中可以直接引用
xxx.yaml config/template.yaml

如何使用

准备配置文件

  • 复制模板
  1. cp config/template.yaml config/demo.yaml
  • 修改 demo.yaml 配置中的变量值
  1. # RobotFramework Configuration
  2. # If you wanna debug via browser, you can set RF_DEBUG as true
  3. RF_DEBUG: false
  4. # Target Configuration
  5. TARGET_URL: https://qualitysphere.gitee.io
  6. TARGET_USER: will
  7. TARGET_PASSWORD: password
  8. TARGET_TITLE: 欢迎使用 | QSphere

执行测试用例

  • —config 指定配置文件执行测试用例
  1. ./sraf-cmd --config config/demo.yaml --clean
  • —tag 执行指定标签的测试用例
  1. ./sraf-cmd --config config/demo.yaml --tag demo --clean
  • —suite 执行指定测试集中的测试用例
  1. ./sraf-cmd --config config/demo.yaml --suite testcase/demo.robot --clean

更多用法请运行 ./sraf-cmd 查看

如何本地调试

  1. import os
  2. from common.Browser import Browser
  3. from common import elePages
  4. os.environ['RF_PWD'] = os.path.join('.')
  5. os.environ['RF_DIR'] = os.path.join('.')
  6. os.environ['RF_VAR_FILE'] = os.path.join('.', 'config', 'template.yaml')
  7. assert os.path.exists(os.getenv('RF_VAR_FILE')), u'文件不存在'
  8. browser = Browser()
  9. browser.access(url='https://qualitysphere.gitee.io')
  10. browser.click_button(
  11. page=elePages.qsphere.Vision(),
  12. key=u'愿景'
  13. )
  14. browser.close_chrome()

如何在容器中执行

  1. docker build --pull -t sraf-cmd:local .
  2. docker run --shm-size=1g --rm -p 80:80 -it sraf-cmd:local bash -c "./sraf-cmd --config config/demo.yaml --tag demo --clean --report local-allure"
  3. # 若在 windows 中执行,需要在命令前面使用 winpty
  4. winpty docker run --shm-size=1g --rm -p 80:80 -it sraf-cmd:local bash -c "./sraf-cmd --config config/demo.yaml --tag demo --clean --report local-allure"

编写测试用例

在 testcase 目录中编写测试用例

testcase/test_case.robot

  1. *** Settings ***
  2. Documentation 用例集描述
  3. Resource ../keywords/<menu><Page>.robot # 引入关键字资源
  4. Test Setup SRAF.开始测试
  5. Test Teardown SRAF.结束测试
  6. *** Variables ***
  7. *** Test Cases ***
  8. SRAF 测试用例标题
  9. [Documentation] 用例描述
  10. [Tags] 标签1 标签2
  11. SRAF.menu1.Page1.关键字1
  12. SRAF.menu1.Page1.关键字2
  13. *** Keywords ***

在 keywords 目录中封装关键字

keywords/<menu><Page>.robot

  1. *** Settings ***
  2. Documentation 关键字说明
  3. Library ../pages/<menu>/<Page>.py # 导入封装的 py 包
  4. *** Keywords ***
  5. SRAF.<menu>.<Page>.关键字
  6. <python_def> ${KDP_VAR_1} ${KDP_VAR_1}

在 pages 目录中按照页面元素封装功能

pages/<menu>/<Page>.py

  1. from common.Browser import Browser
  2. from common import elePages
  3. class PageName(object):
  4. def __init__(self):
  5. self.browser = Browser()
  6. def login_kdp(self, user: str, password: str):
  7. self.browser.input_text(
  8. page=elePages.menu1.Page1(),
  9. key=u'登录名',
  10. value=user
  11. )
  12. self.browser.input_text(
  13. page=elePages.menu1.Page1(),
  14. key=u'密码',
  15. value=password
  16. )
  17. self.browser.click_button(
  18. page=elePages.menu1.Page1(),
  19. key=u'登录'
  20. )
  21. def upload_file(self):
  22. self.browser.upload_file(
  23. page=elePages.menu2.Page4(),
  24. key=u'上传附件',
  25. value='/workspace/demo_attach.png'
  26. )

在 elements 目录中存储页面元素的 xpath

elements/<menu>/<Page>.yaml

  1. 元素名称: 'xpath'