惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
SecWiki News
SecWiki News
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
Jina AI
Jina AI
N
Netflix TechBlog - Medium
GbyAI
GbyAI
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
AWS News Blog
AWS News Blog
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
C
Cybersecurity and Infrastructure Security Agency CISA
I
Intezer
T
Tor Project blog
P
Palo Alto Networks Blog
P
Privacy & Cybersecurity Law Blog
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
T
Tailwind CSS Blog
C
Check Point Blog
Cloudbric
Cloudbric
Y
Y Combinator Blog
The Last Watchdog
The Last Watchdog
Forbes - Security
Forbes - Security
Last Week in AI
Last Week in AI
S
Security Affairs
博客园 - Franky
F
Fortinet All Blogs
量子位
M
MIT News - Artificial intelligence
C
Cisco Blogs
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
S
Secure Thoughts
V
Visual Studio Blog
AI
AI
美团技术团队
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 三生石上(FineUI控件)
阮一峰的网络日志
阮一峰的网络日志
Engineering at Meta
Engineering at Meta
人人都是产品经理
人人都是产品经理
Microsoft Security Blog
Microsoft Security Blog
T
Threatpost
Cyberwarzone
Cyberwarzone

陈少文的网站

巨变与机遇的未来十年 Kubernetes 平台管理软件压力测试方案 使用镜像部署 Hexo 静态页面 终于等到你 - GitHub 镜像仓库服务(ghcr.io) 一起来学 Go --(6)Interface 一起来学 Go --(5)Goroutine 和 Channel 什么是函数式编程 如何在 Kubernetes 集群集成 Kata 柯里化与偏函数 使用 PyGithub 自动创建 Label 软件产品是团队能力的输出 Helm 2 、Helm 3 比较 IoT 变现 Kubernetes 中的 DNS 服务 国内的 Helm 镜像源 Harbor 使用自签证书支持 Https 访问 DevOps 工具链之 Prow 如何使用 kfctl 安装 Kubeflow VS Code 无法下载 Go 插件的工具包 工程师更应具有服务精神 你不知道的 Docker 使用技巧 使用 Docker 运行 Tensorflow 论中国 什么是左移 如何清空 Git 仓库全部历史记录 一禅小和尚 有风吹过厨房 时间的玫瑰 如何在 CentOS 安装 GPU 驱动 开发 Tips(19) 使用 Velero 备份 Kubernetes 集群 Kubernetes Cheat Sheet 开发 Tips(18) 如何构建一个 Java 工程 开发 Tips(17) KubeSpray 安装 Kubernetes 报错 ip in ansible_all_ipv4_addresses 基于 Kubernetes 和 Jenkins 搭建自动化测试系统 在 Kubernetes 上动态创建 Jenkins Slave 使用 Jenkins 进行服务拨测 开发 Tips(16) Kubernetes 签发 Ingress 证书及日常故障运维 Kubernetes 中 Deployment 的基本操作 Kubernetes 中的证书 如何使用 KubeBuilder 开发一个 Operator Kubernetes 1.6.0 安装问题汇总 镜像管理工具 -- Harbor 开发 Tips(15) Docker 如何拉取镜像 开发 Tips(14) 使用 Helm 安装 harbor 开发 Tips(13) 使用 S2I 构建云原生应用 在 Kubernetes 中使用 emptyDir、hostPath、localVolume 开发 Tips(12) 开发 Tips(11) 代码质量分析工具 SonarQube 使用 Kubeadm 安装 Kubernetes 集群 一起来学 Go --(4)常用函数 Kubernetes 中的 Ceph Kubernetes 之 Volumes Kubernetes 之 Labels、Selectors 开发 Tips(10) 开源正在重构商业模式 Kubernetes 之网络 Kubernetes 之 API 使用 Helm 和 Operator 快速部署 Prometheus Kubernetes 复杂有状态应用管理框架 -- Operator Kubernetes 的包管理器 -- Helm 一起来学 Go --(3)Go Modules 如何一步一步地优化博客方案 kubectl 实用指南 Kubernetes 中的基本概念 搭建远程 Kubernetes 开发环境 大公司和小公司的 ToB 思路 开发 Tips(9) Go 入门指南 一起来学 Go --(2)数据与逻辑结构 如何预防 Web 富文本中的 XSS 攻击 django-xss-cleaner 云工作时代 一起来学 Go --(1)背景与特点 SaaS 开发团队的不同阶段 你不知道的 Git 使用技巧 输出既服务 微服务设计 继续奔跑 开发 Tips(8) 从账户安全到二次验证 Django 性能之数据库查询优化 Django 性能之分库分表 敏捷开发之研发流程 打造一致性的团队 开发 Tips(7) Pytest 进阶学习之 Mock PaaS 部署之 buildpack Go 开发配置 领域输出才是 PaaS 的核心竞争力 Pytest 入门学习 开发 Tips(6) 如何使用 Jenkins、Docker、GitLab 搭建 Django 自动化部署流程
如何打包一个 Robot Framework 的 Docker 镜像
微信公众号 · 2018-09-18 · via 陈少文的网站

Please enable Javascript to view the contents

为了方便 CI 集成 UI 自动化测试,需要将 Robot Framework 运行环境打包为 Docker 镜像。本篇主要内容是一些与打包过程相关的配置和脚本。

1. 打包目录结构

1
2
3
4
5
6
tree
.
├── docker-compose.yml
├── Dockerfile
├── google-chrome.repo
├── requirements_base.txt

1.1 Dockerfile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
FROM centos:7

ADD ./google-chrome.repo /etc/yum.repos.d/google-chrome.repo

RUN yum -y install epel-release

RUN yum -y install wget unzip python-pip google-chrome-stable

RUN google-chrome -version

RUN wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip

RUN unzip chromedriver_linux64.zip

RUN mv chromedriver /usr/bin/

RUN  mkdir /data

ADD ./requirements_base.txt /data/requirements_base.txt

RUN cd  /data

RUN chmod 777 /data

RUN  pip install -r /data/requirements_base.txt

RUN yum -y install cjkuni-ukai-fonts cjkuni-uming-fonts wqy-zenhei-fonts

WORKDIR /data

1.2 google-chrome.repo

1
2
3
4
5
6
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

1.3 requirements_base.txt

1
2
3
4
5
6
7
8
robotframework==3.0.4
robotframework-archivelibrary==0.4.0
robotframework-ftplibrary==1.6
robotframework-ride==1.5.2.1
robotframework-selenium2library==3.0.0
robotframework-seleniumlibrary==3.1.1
robotframework-sshlibrary==3.1.0
robotframework-excellibrary==0.0.2

1.4 docker-compose.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
version: '2'

services:

    robot-framework:
      build: ./
      image: robot-framework:1.2.0
      volumes:
        - ./framework:/data
      command:  /bin/bash -c  '/data/start.sh'

2. 生成镜像并导出

为了方便生成镜像,并进行测试,这里使用 docker-compose 工具。docker-compose 提供了对 docker 镜像进行编排的功能。

编译生成镜像(由于已经编译过一次,docker 直接使用了缓存)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
docker-compose build
Building robot-framework
Step 1/15 : FROM centos:7
 ---> 5182e96772bf
Step 2/15 : ADD ./google-chrome.repo /etc/yum.repos.d/google-chrome.repo
 ---> Using cache
 ---> 170c52cb6d03
Step 3/15 : RUN yum -y install epel-release
 ---> Using cache
 ---> 16e06b65b06b
Step 4/15 : RUN yum -y install wget unzip python-pip google-chrome-stable
 ---> Using cache
 ---> fa1d529a3c79
Step 5/15 : RUN google-chrome -version
 ---> Using cache
 ---> 85d30717b2cc
Step 6/15 : RUN wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip
 ---> Using cache
 ---> 478e06633003
Step 7/15 : RUN unzip chromedriver_linux64.zip
 ---> Using cache
 ---> f349532ce26a
Step 8/15 : RUN mv chromedriver /usr/bin/
 ---> Using cache
 ---> 0cda97e8015d
Step 9/15 : RUN  mkdir /data
 ---> Using cache
 ---> 1140837158be
Step 10/15 : ADD ./requirements_base.txt /data/requirements_base.txt
 ---> Using cache
 ---> 453287832315
Step 11/15 : RUN cd  /data
 ---> Using cache
 ---> 2c37da1e6d90
Step 12/15 : RUN chmod 777 /data
 ---> Using cache
 ---> 39db1f669549
Step 13/15 : RUN  pip install -r /data/requirements_base.txt
 ---> Using cache
 ---> 1d91f1cab3f6
Step 14/15 : RUN yum -y install cjkuni-ukai-fonts cjkuni-uming-fonts wqy-zenhei-fonts
 ---> Using cache
 ---> 45b4ecae1112
Step 15/15 : WORKDIR /data
 ---> Using cache
 ---> 609dde1f878e
Successfully built 609dde1f878e
Successfully tagged robot-framework:1.2.0

查看镜像列表

1
2
3
4
docker  image
REPOSITORY                TAG                 IMAGE ID            CREATED             SIZE
robot-framework           1.2.0               609dde1f878e        3 weeks ago         962MB
centos                    7                   5182e96772bf        6 weeks ago         200MB

导出镜像

1
docker save -o ./robot-framework_V1.2.0 robot-framework:1.2.0

将镜像拷贝到其他机器,还可以导入镜像

1
docker load -i robot-framework_V1.2.0

3. 测试

需要准备一个 Robot Framework 的 Demo。

tree framework/
framework/
|---cases
|------ 测试用例
|---process
|------ 测试流程
|---keywords (存放关键字)
|------common (通用关键字)
|---resources(附件资源文件夹,放图片、表格、文件等)
|---global.robot(存放一些必须的全局变量)
|---locators (存放页面上一些固定的元素,进行统一管理)
|---lib (自己写的一些库 Python 库文件)
|---requirements.txt 依赖库文件
|---report 测试输出文件夹
|---start.sh 启动执行测试用例命令

在项目的根目录下,存在 start.sh 脚本,用于启动测试执行。

1
2
cat start.sh
pybot  --outputdir  report .

然后,继续使用 docker-compose 工具,创建容器,运行测试用例。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
docker-compose up
Starting robot-framework-compose_robot-framework_1 ... done
Attaching to robot-framework-compose_robot-framework_1
robot-framework_1  | ==============================================================================
robot-framework_1  | Data
robot-framework_1  | ==============================================================================
robot-framework_1  | Data.Cases
robot-framework_1  | ==============================================================================
robot-framework_1  | Data.Cases.Home
robot-framework_1  | ==============================================================================
robot-framework_1  | ????                                                              | PASS |
robot-framework_1  | ------------------------------------------------------------------------------
robot-framework_1  | ????                                                              | PASS |
robot-framework_1  | ------------------------------------------------------------------------------
robot-framework_1  | ????                                                              | PASS |
robot-framework_1  | ------------------------------------------------------------------------------
robot-framework_1  | Data.Cases.Home                                                       | PASS |
robot-framework_1  | 3 critical tests, 3 passed, 0 failed
robot-framework_1  | 3 tests total, 3 passed, 0 failed
robot-framework_1  | ==============================================================================
robot-framework_1  | Data.Cases                                                            | PASS |
robot-framework_1  | 3 critical tests, 3 passed, 0 failed
robot-framework_1  | 3 tests total, 3 passed, 0 failed
robot-framework_1  | ==============================================================================
robot-framework_1  | Data                                                                  | PASS |
robot-framework_1  | 3 critical tests, 3 passed, 0 failed
robot-framework_1  | 3 tests total, 3 passed, 0 failed
robot-framework_1  | ==============================================================================
robot-framework_1  | Output:  /data/report/output.xml
robot-framework_1  | Log:     /data/report/log.html
robot-framework_1  | Report:  /data/report/report.html
robot-framework-compose_robot-framework_1 exited with code 0

最终在本地文件夹中,可以看到执行完测试用例生成的报告。

除此,你还可以直接使用线上的镜像,跳过编译镜像的过程:

docker-compose.yml

1
2
3
4
5
6
7
8
9
version: '2'

services:

    robot-framework:
      image: shaowenchen/docker-robotframework
      volumes:
        - ./framework:/data
      command:  /bin/bash -c  '/data/start.sh'

微信公众号