如何设置一个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?

查看:196
本文介绍了如何设置一个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项目,该项目包含在Eclipse IDE下使用Appium java-client lib进行的多个测试,这些测试可以在本地运行UI测试.我下一步的目标是将我的测试与gitlab repo(已经存在,由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 jar导入到main中的库中?
  1. how should I set up the .gitlab.yaml?
    • can we just have the script in yaml to download Appium and maven?
    • or we could just download Appium, but import all the Appium java-client jars to libs in main?

非常感谢!

推荐答案

由于终于有人对此问题也感兴趣,所以让我分享我的解决方案.

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/

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

您应该已经注意到,Appium的优点之一是您不需要更改正在测试的App的任何内容,您所测试的完全相同.投入生产.要了解有关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

  • 使用新编译的应用程序,编译您的测试套件

  • 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运行器将在.gitlab-ci.yml中运行每个阶段的作业,并在运行至阶段时进行自动化测试,并注意在服务器上运行,因此这意味着您需要在服务器上安装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脚本,它将抓取新编译的App(自动化测试套件),将其上传到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应用程序的阶段之后,我有一个阶段functionTest_project阶段.然后,在阶段中编写必要的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 repo,现在我相信更好的方法是在的FunctionalTest阶段进行编译和打包. gitlab.yml.现在回到问题的第一点,如何获取Maven,我的理解是它是服务器(如python)的依赖项,因此可以通过告诉gitlab使用具有python和docker的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的答案

  • 将其放入相同的存储库中,但退出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天全站免登陆