如何设置 Appium UI 测试 maven 项目与 Gitlab CI 一起测试 Android App? [英] how to set up a Appium UI test maven project to work with Gitlab CI to test Android App?

查看:22
本文介绍了如何设置 Appium UI 测试 maven 项目与 Gitlab CI 一起测试 Android App?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在是一名实习生,刚接触自动化测试.我的目标是帮助我的公司为客户端设置 CI.

I am an intern now, new to automation test.My goal here is to help my company set up CI for client side.

现在我有一个 maven 项目,其中包含几个使用 Appium java-client lib 的测试,在 Eclipse IDE 下,可以在本地运行 UI 测试.我下一步的目标是将我的测试与 gitlab 存储库(已经存在,由 android 开发人员创建)挂钩,但我被困在这里.有人可以帮我吗?请尽量具体:

Right now I have a maven project contains several tests using Appium java-client lib, under Eclipse IDE, which could run the UI tests locally. My goal next step is to hook my tests with the gitlab repo(which is already there, created by the android developers), but I am stuck here. Could somebody help me out? Please try to be specific:

  1. 我应该如何设置 .gitlab.yaml?
    • 我们可以在 yaml 中使用脚本来下载 Appium 和 maven 吗?
    • 或者我们可以只下载 Appium,但将所有 Appium java-client jars 导入到 main 中的 libs 中?

非常感谢!

推荐答案

既然终于有人也对这个问题感兴趣了,就分享一下我的解决方案吧.

Since finally someone is also interested in this question, let me share my solution to this.

因此,如果您正在查看这个问题,我假设您已经拥有测试套件,并且可以在您的机器上本地测试它,或者将您的应用程序安装在模拟器或真实设备中.现在您需要阅读有关 gitlab 管道和 gitlab CI 的更多信息:

So, if you are looking at this question, I assume you already have your test suite and you could test it locally in your machine, either have your app installed in a simulator or a real device. Now you need to read more about gitlab pipeline and gitlab CI :

gitlab CI:https://docs.gitlab.com/ee/ci/quick_start/

你应该已经注意到,Appium 的一个优点是你不需要改变你正在测试的应用程序,你正在测试完全相同的应用程序投入生产.要了解有关 Apppium 的更多信息:

And you should have noticed that, one of the advantages of Appium is that you don't need to change a thing about the App you are testing, you are testing exactly the same App which is going into production. To learn more about Apppium:

现在,要运行自动化测试,您需要测试套件、应用和 Appium 服务器.我们需要做的是在.gitlab-ci.yml中添加另一个阶段,告诉它

Now, to run the automation test, you need your test suite, the app, and Appium server. What we need to do is adding another stage in .gitlab-ci.yml, tell it to

  • 使用新编译的 App,编译你的测试套件

  • take the newly compiled App, compile your test suite

在模拟器/真机上安装应用

install the App in simulator/real device

编译您的测试套件并运行它.

compile your test suite and run it.

为了让事情更容易理解,我们从问题 4 开始,工作流程:

To make things easier to understand, we start with question 4, workflow:

所以当代码签入到gitlab时,gitlab runner会运行你的.gitlab-ci.yml中每个stage的jobs,当它运行到你的stage时,它会做自动化测试,注意是在你的服务器上运行,所以这意味着你需要在你的服务器上安装 Appium,并在尝试运行你的自动化测试套件时让它运行起来.现在的问题是,您的服务器有能力这样做吗?如果你想在你的服务器上做自动化测试,你需要在上面安装Appium,模拟器(可能需要你的服务器配备GPU)等等,这些都是维护服务器的问题.另一种方法是使用第三方服务,这就是我所做的.原来我们的(当我在那家公司时)服务器不能运行自动化 UI 测试,所以我们转向了 AWS-ADF(Amazon Device Farm),还有许多其他服务提供商可以选择,请参阅链接以获取参考:

So when the code is checked in to gitlab, the gitlab runner runs the jobs of each stage in your .gitlab-ci.yml, and when it runs to your stage, it does the automation test, and note that it is running on your server, so it means you need to have Appium installed on your server and have it up and running when try to run your automation test suite. Now the problem is that, is your server capable to do so? If you wanna do the automation test in your server, you need to install Appium on it, simulator probably(and which might need your server to equip with GPU), etc, these are the concerns of maintaining server. The alternative would be using the third-party service ,which is what I did. Turns out our(when I was in that company) server isn't capable of running automation UI test, so we turned to AWS-ADF(Amazon Device Farm), there are many other service providers you could choose, see the link for references:

https://adtmag.com/blogs/dev-watch/2017/05/device-clouds.aspx

所以我在功能测试阶段基本上有一个python脚本,它会抓取新编译的应用程序,自动化测试套件,将它们上传到AWS ADF,然后安排运行,运行完成时产生结果.

So I basically have a python script in my functional test stage, and it will grab the newly complied App, the automation test suite, upload them to AWS ADF, and then schedule a run, yields result when the run is finished.

所以,回答问题 1:

  • 我们需要在 .gitlab.yaml 中为我们的功能测试再创建一个阶段,就我而言,我在编译 Android 应用程序的阶段之后有一个阶段功能测试_项目阶段.然后你在你的阶段编写必要的 cmd 脚本,或者如果它太长,你的脚本在另一个文件中(把它放在你的仓库中)然后执行它.就我而言,我将脚本放在 python_ci.py 中,然后在我的舞台中使用python python_ci.py"执行它.(这里你需要一个具有这些要求的 docker,也见下文)

  • we need to create one more stage for our functional test in .gitlab.yaml, in my case, I have a stage functionalTest_project stage after the stage which compiles the Android App. And then you script the necessary cmd in your stage, or if its too lengthy, your script in another file(put it in your repo) and then execute it. In my case, I put my script in python_ci.py, and then I execute it in my stage use "python python_ci.py" .(here you need a docker with these requirement, see below too)

您不下载 Appium,而是在您的设备上安装 Appium,或者如果您使用云服务,该服务应该为您安装 Appium.

You don’t download Appium, you set up Appium on your or if you use a cloud service, that service should set up Appium for you.

我所做的是使用 maven 构建并在本地打包测试套件,然后将其推送到 gitlab 存储库,现在我相信更好的方法是在 .gitlab.yml.现在回到问题 1 的第一点,如何获取 maven,我的理解是它是服务器的依赖项,例如 python,因此它们都可以通过告诉 gitlab 使用具有 python 的 docker 执行您的脚本来获得,并且Maven 依赖.

What I did it is that I use maven built and package the test suite locally and then push it to gitlab repo, which now I believe the better way would be compile and package it in the your functionalTest stage in .gitlab.yml. now it comes back to first point of question 1, how to get maven, my understanding is that its a dependency of the server, like python, so they could both be obtained by telling gitlab to execute your script with a docker that has python and maven dependency.

问题 3 的答案:

  • 将它放在同一个 repo 中,但不在 Android 项目中(即它们将在同一目录下).

  • put it in the same repo, but out of the Android project(i.e. they will under the same directory).

如何告诉 yml 到达测试套件?请记住它们在同一台服务器中,因此您可以使用 yml 脚本中的相对路径来告诉 yml 从何处获取您的测试套件.

how to tell yml to reach the test suite? remember they are in the same server, so you could the relative path in your yml script to tell yml where to get your test suite.

希望这有帮助!

这篇关于如何设置 Appium UI 测试 maven 项目与 Gitlab CI 一起测试 Android App?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆