kubernetes一键部署zalenium测试环境
2018-11-15 本文已影响0人
wywincl
1. 背景介绍

随着DevOps,容器,微服务等技术实践的日益深入,对自动化测试环境提出了更高的要求。按需定制自动化测试环境,以及物理资源共享成了迫切需求。本文将重点介绍如何在kubernetes集群中一键部署zalenium测试环境,以用于大规模高并发的Web UI自动化测试场景。
2. 技术工具

工具 | 介绍 | 备注 |
---|---|---|
kubernetes | 容器编排引擎 | PaaS(平台即服务) |
Zalenium | 动态扩展的selenium容器平台 | CaaS(容器即服务) |
2.1 zalenium 原理

3. 部署步骤
3.1 准备好kubernetes集群环境
这里默认大家已经搭建了kubernetes集群环境,或者已经开通了公有云k8s集群,如阿里云AKS, aws EKS, google GKE等;

验证kubernetes集群
$ kubectl cluster-info
Kubernetes master is running at https://localhost:6443
KubeDNS is running at https://localhost:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
3.2 克隆zalenium项目
$ git clone https://github.com/zalando/zalenium.git
$ cd zalenium
$ kubectl apply -f kubernetes/
persistentvolumeclaim/zalenium-data created
persistentvolumeclaim/zalenium-mounted created
persistentvolume/zalenium-data created
persistentvolume/zalenium-mounted created
namespace/zalenium created
service/zalenium created
serviceaccount/zalenium created
clusterrole.rbac.authorization.k8s.io/zalenium-role created
clusterrolebinding.rbac.authorization.k8s.io/zalenium created
deployment.extensions/zalenium created
3.3 查看kubernetes dashboard

3.4 访问zalenium服务

4. 运行web UI自动化测试
这里我们使用robot framework来进行web ui自动化测试用例编写运行。你也可以直接用selnium+python or java的方式编写测试脚本。
//demo.robot
*** Setting ***
Library SeleniumLibrary
*** Variables ***
${HOST} https://www.baidu.com
*** Test Cases ***
T_Case_1
Log Open Browser
Open Browser ${HOST} chrome remote_url=http://localhost:32195/wd/hub
Input Text id=kw Robot Framework
Click Button id=su
Capture Page Screenshot
Sleep 5s
Close Browser
*** Keywords ***
执行用例
robot demo.robot
查看实时执行情况

回看测试过程

5. 总结
至此,我们就基本搭建完了zalenium测试环境,并且可以执行Web UI自动化测试任务;而且执行完测试后,我们可以在k8s上轻松删除创建的测试环境,释放资源,以达到节省物理资源,提高资源利用率。