一、jenkins的环境配置
详细见Jenkins环境搭建篇
二、Appium+Jenkins构建配置
1.登录Jenkins系统,点击‘新建’

2.输入项目名称,选择第一个选项,点击保存

3.在项目界面选择‘构建触发器’→‘构建’→‘增加构建步骤’中选择‘Execute shell’

4.在Execute shell界面输入如下指令

5.在构建后操作选择E-mail Notification选项

6.在E-mail Notification界面输入接收者邮箱地址,点击保存

7.点击立即构建

8.运行结果,点击返回面板,在Jenkins主界面可以看到如下图所示

配合端收件邮箱收件结果:

二、构建过程中需注意以下几点:
1.保障appium和模拟器处于启动链接状态
2.脚本中启动app的目录需与jenkins构建后存放apk的目录一致
3.脚本中生成的html测试报告需存放在统一规定目录下
4.脚本结构及规则
>Common目录:共通的方法
>TestDemo(unittest.TestCase):测试类名;Test+测试的模块名;继承unittest的testcase类
>setUpClass(cls):执行用例之前的初始化操作;配置模拟器信息、测试apk信息,启动app应用;
>tearDownClass(cls):完成用例后的退出处理;
>test_login(self):具体的测试case
>if __name__ == '__main__':脚本主入口;加载用例,形成html格式的测试报告
三、配置过程中遇到的坑
1.点击立即构建,提示ImportError:No module named 'appium'

解决方法是:你安装的Python可能有好几个版本,设置指定你当前Python编译器版本(或者用Python绝对路径去运行代码),在Jenkins中的Excute shell中写入Python编译器的绝对路径即可
2.在Jenkins中构建过程中提示:[test] $ sh -xe C:\Windows\TEMP\hudson6299483223982766034.sh系统找不到指定的文件,分析原因是因为选择了Excute shell来执行指令
解决办法是:在‘构建’选择Execute Windows batch command 来执行指令 参考资料:提示找不到系统问题

后续知识将在实际项目中继续优化。。。敬请期待。
参考资料:appium自动化入门-python上海-悠悠1105(PDF文档)
网友评论