通常我们的自动化测试系统是部署在公司内网的,用于日常的功能验证。这时,Selenium hub和node节点之间只需要绑定本地ip即可,即配置-host localIp。
但是如果在诸如阿里云ECS、亚马逊EC2等云虚拟主机中部署hub和node,并且需要通过公网地址通信,则发现这样配置是行不通的。
- 弹性云虚拟主机通常不配备独立的公网网卡,而是绑定弹性公网ip,这类公网ip无法通过ifconfig查询到,若host指定这类ip,selenium会因无法绑定ip地址而不能运行。
- 对于hub节点,可通过绑定所有地址来监听node请求:-host 0.0.0.0
- 对于node节点,首先通过-hub指定hub节点的公网ip。然后显式配置remoteHost参数:-remoteHost http://nodePublicIp:port。这个remoteHost会在node向hub注册时发送给hub,告诉hub需要通过remoteHost来给node发送指令。可不指定-host,selenium自动绑定本地localIp。
如此,我们就可以在公网使用不同服务商提供的弹性主机,来进行自动化测试了。
1. 简介
Kite是一个用于测试WebRTC跨浏览器互操作性的测试引擎。
- 支持编写跨平台的自动化的Java或JavaScript测试脚本
- 支持Linux、Windows、Mac、iOS和Android系统
- 支持Chrome、Firefox、Safari、Opera、MicroftEdge等主流Web浏览器
- 支持Mobile Native Apps on Android, iOS
- 支持Desktop Native Apps on Windows and MacOS
- 支持Electron Apps
【工作原理】:
一个完整的KITE测试环境由以下几部分组成:
此为selenium测试集群的中心节点,是一个运行selenium.jar的Java进程。
用于管理node,包括接受node的注册、和node之间的保活、选择node并向node派发测试指令。
- selenium grid node,称之为proxy
此为selenium测试集群的执行节点,也是一个运行selenium.jar的Java进程
其主要作用为接受hub发送的测试指令,并通过webdriver运行测试指令
和浏览器通信,“远程”操控浏览器
通过kite或者说selenium提供的测试sdk,编写自动化测试脚本,支持Java、js等多种语言
Kite集成了Selenium(automates browsers)gird测试框架,可以构建出一个分布式测试环境。
用户通过client连接selenium hub,hub选择合适的测试node来执行测试用例,并将测试结果保存至Allure(开源的测试报告框架),测试结果可通过浏览器查看。
Selenium Grid是一个分布式测试框架,如下图所示:
想要熟练使用kite,需要先了解selenium。
当然你更应该了解webrtc是什么,推荐这本开发书籍:《WebRTC Native开发实战》,比较详细讲解了webrtc的原理,并结合实际项目给出了使用方法。

2. 安装
- 依赖项目
- Windows
- 安装Git
- 安装JDK:下载安装包,安装后设置环境变量JAVA_HOME,并将%JAVA_HOME%\bin添加到PATH环境变量中
- 安装Maven:下载编译好的zip文件,解压;添加环境变量MAVEN_HOME,并将%MAVEN_HOME%\bin添加到PATH环境变量中:

- 执行mvn -version检查安装结果
- 修改conf/settings.xml,添加阿里的Maven源镜像:

- 安装kite2.0
- 从github下载源码,存放源码的路径中不能有空格。进入KITE目录。
- 执行bat,用于设置KITE_HOME环境变量以及添加工具脚本到PATH中。根据脚本提示安装selenium local grid,注意默认配置中浏览器版本是否和本机匹配,若不一致,需要修改scripts\windows\gridCofnig.bat。

- 这个过程可能由于网络原因导致下载失败,需要手动下载相关文件并放到相应的目录中:
Selenium.jar:下载,然后复制jar到KITE\localGrid\selenium.jar
ChromeDriver: 下载,然后解压复制到KITE\localGrid\chrome\chromedriver.exe
GeckDriver:下载,然后解压复制到KITE\localGrid\firefox\geckodriver.exe
然后再运行一次configure.bat。成功后会看到下边的几个窗口:

打开http://localhost:4444/grid/console,可以看到两个Selenium节点


- 配置:iceconnection.local.config.json
{
"name": "IceConnectionTest JS",
"callable": true,
"remotes": [ //配置hub
{
"type": "local",
"remoteAddress": "http://localhost:4444/wd/hub"
}
],
"tests": [
{
"name": "IceConnectionTest",
"tupleSize": 2, //打开的node个数
"description": "This test check the ICEConnection state between two browsers communicating via appr.tc",
"testImpl": "IceConnectionTest.js", //测试用例主脚本
"payload" : { //测试用例所需参数,可根据需要灵活配置
"url": "https://appr.tc",
"testTimeout": 60,
"statsCollectionTime": 3,
"statsCollectionInterval": 1,
"getStats": true,
"selectedStats": [
"candidate-pair",
"inbound-rtp",
"outbound-rtp",
"track"
]
}
}
],
"browsers": [ //浏览器配置
{
"browserName": "chrome",
"version": "73",
"platform": "WINDOWS",
"flags": []
}
]
}
- 主脚本:js版
const {TestUtils, WebDriverFactory, KiteBaseTest, Status} = require('kite-common');
const globalVariables = TestUtils.getGlobalVariables(process);
// Steps & checks
const {OpenAppUrlStep, ConnectToAppRoomStep, GetStatsStep} = require('./steps');
const {PeerConnectionCheck, RemoteVideoDisplayCheck} = require('./checks');
// KiteBaseTest config
const capabilities = require(globalVariables.capabilitiesPath);
const payload = require(globalVariables.payloadPath);
//Main Class
class IceConnectionTest extends KiteBaseTest {
constructor(name, globalVariables, capabilities, payload)
{
super(name, globalVariables, capabilities, payload);
}
async testScript() {
try {
this.driver = await WebDriverFactory.getDriver(this.capabilities,this.capabilities.remoteAddress);
//测试步骤
let openAppUrlStep = new OpenAppUrlStep(this);
await openAppUrlStep.execute(this);
let connectToAppRoomStep = new ConnectToAppRoomStep(this);
await connectToAppRoomStep.execute(this);
let peerConnectionCheck = new PeerConnectionCheck(this);
await peerConnectionCheck.execute(this);
let remoteVideoDisplayCheck = new RemoteVideoDisplayCheck(this);
await remoteVideoDisplayCheck.execute(this);
let getStatsStep = new GetStatsStep(this);
await getStatsStep.execute(this);
// End of Test reportWebDriverUtils
this.report.setStopTimestamp();
} catch (error) {
console.log(error);
} finally {
await this.driver.quit();
}
this.reporter.generateReportFiles();
let value = this.report.getJsonBuilder();
TestUtils.writeToFile(this.reportPath + '/result.json', JSON.stringify(value));
}
}
module.exports = IceConnectionTest;
var test = new IceConnectionTest('IceConnection Test', globalVariables, capabilities, payload);
test.testScript();
- TestSteps
- OpenAppUrlStep//open appr.tc
- ConnectToAppRoomStep//根据当前时间生成roomId,在tc页面设置//roomId,并进入房间
- PeerConnectionCheck//通过js获取iceConnectionState
- RemoteVideoDisplayCheck
- GetStatsStep//获取sdp信息
Kite框架分析
- KiteBaseTest
- name, numberOfParticipant, capabilities
- report(AllurTestReport), reporter //测试报告相关
- payload //测试用例配置传入的参数
- testScript() //子类必须实现此函数:构造TestStep并调用execute()
- TestStep
- dsescription
- report(AllurTestReport)
- execute() //调用setp(),并设置report信息和状态
- skip(), finish()
- step() //子类必须实现此函数:实现本测试步骤的逻辑