如何为 Android 自动化设置 Appium 环境? [英] How to setup Appium Environment for Android Automation?

查看:33
本文介绍了如何为 Android 自动化设置 Appium 环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在测试中担任 SD.我是 Appium 自动化工具的新手,这个工具为我设置环境非常棘手.

I am working as SD in Test. I am new to Appium Automation tool, this tool is very tricky to set up environment for me.

我参考了以下链接:http://unmesh.me/category/appium/

此链接帮助我通过命令行安装 Node.js 和 appium.但我不确定这是正确的做法.

This link helped me to install Node.js and appium through command line. But I am not sure this right way to do.

我从命令行收到以下消息:

I got following message from command line :

mani-kandans-MacBook-Pro:platform-tools manikandan$ info: Welcome to Appium v0.8.2 (REV e9cc66197ad6a3496322bd77a8699509fc761b69)
info: Appium REST http interface listener started on 0.0.0.0:4723
   info  - socket.io started

在这之后我没有任何想法.如何编写测试用例并通过 Appium 运行?

After this I don't have any idea. How to write testcase and run it through Appium?

如果您有兴趣分享有关 Appium 工具的知识.请指导我.

If your interest to share your knowledge about Appium tool. Please guide me.

  1. 如何安装 Appium?
  2. 如何通过 Appium 工具运行测试用例?

推荐答案

第一部分:-.您似乎已经使用 node server.js 启动了 appium 服务器- 您可以通过在浏览器中访问 localhost:4723/wd/hub/status 来检查服务器,这将返回服务器的一些详细信息.你已经这样做了.

Part One:-. You appear to have launched the appium server using node server.js - You can check the server by going to localhost:4723/wd/hub/status in your browser this will return a few details of the server. You have already done this.

命令输出将如下所示,确认服务器已启动:

The command output will look like this confirming that the server is started:

info: Welcome to Appium v0.8.1 (REV ***********************************)
info: Appium REST http interface listener started on 0.0.0.0:4723
       info  - socket.io started

第二部分:-.接下来,您将 selenium RC 用于 Python、Java 或 c# 或任何您选择的语言.我使用了 c# 并且可以提供示例,这应该与您的测试类似.

Part Two:-. Next you use the selenium RC for Python, Java, or c# or whatever your language choice. I used c# and can provide examples this should be similar for your tests.

将 selenium 添加到 c# 类:using OpenQA.Selenium.Remote;您将所有数据传递给 selenium 所需的功能对象.存在一些自定义所需的功能,例如:

To add the selenium to a c# class: using OpenQA.Selenium.Remote; You pass all your data to a selenium desired capabilities object. Some custom desired capabilities exist such as:

  • 'app-package' 这是应用程序包名称,例如 com.myapp.main,
  • 'app-activity' 是要调用的应用程序主要活动,它也将启动应用程序.这通常是一项启动活动或主要活动,
  • 'wait-activity' 是 Appium 启动后将检查的活动,这将是应用程序活动,但对我而言,如果在某些测试中启动新活动而不是调用新活动,则情况有所不同,
  • 'version' 取安卓版本,
  • '设备 ID' 将您连接的设备或 AVD 带到命令和应用程序,该应用程序将具有您要安装的 apk 的本地路径.这会在启动时签名并安装,如果已签名的应用程序已经存在,它将为您跳过此步骤.

  • 'app-package' this is the app package name such as com.myapp.main,
  • 'app-activity' which is the apps main activity to be called which will also launch the app. This is often a splash activity or main activity,
  • 'wait-activity' is the activity that Appium will check for once launched, this would be the app-activity but for me it is different if for some tests a new activity is launched than is called,
  • 'version' taking the android version,
  • 'device ID' taking your attached device or AVD to command and app which will have a local path to the apk you wish to install. This is signed and installed on start-up if a resigned app already exists it will skip this for you.

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.SetCapability("app-package", "com.myapp.test");
    caps.SetCapability("browserName", "");
    caps.SetCapability("device", "Android");
    caps.SetCapability("app-activity", "com.myapp.SplashActivity");
    caps.SetCapability("takesScreenshot", true);
    caps.SetCapability("version", "4.1.2");
    caps.SetCapability("device ID", "uniquedeviceid");
    caps.SetCapability("app", @"C:\path to\app\on\pc\app.apk");

按照您创建的功能创建一个远程 Web 驱动程序对象,并传递您使用的集线器 url,例如 http://localhost:4723/wd/hub 和您创建的所需功能.

Following the Capabilities you create create a remote web driver object passing the hub url that you've used e.g http://localhost:4723/wd/hub and the Desired Capabilities you've created.

RemoteWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4723/wd/hub/"), caps);

这一行使用 Appium 服务器的 ip 或主机开始侦听请求.对我来说,这一步会在连接的设备上签署安装并启动应用程序,希望这对你也能奏效.这是您编写的 selenium 测试连接到 Appium 服务器的地方.

This line uses the ip or host of the Appium server to begin listening for requests. For me this step signs installs and launches the app on the attached device hopefully this will work for you the same. This is where the selenium tests you write are connected to the Appium server.

现在使用创建的 driver 对象,您可以访问 selenium rc 命令,Appium 已经为 Android 测试实现了许多替代方案.在这些过程中,您的 Appium 服务器控制台窗口应该会显示是否有任何问题.

Now using the created driver object you can access the selenium rc commands of which Appium has implemented many alternatives for android testing. During each of these your Appium server console window should show you if there is any issues.

输出将进行颜色编码,以帮助识别此窗口中的故障,但您可以按照自己的方式处理这些问题,并在需要时输出到文件中.

Output will be colour coded to assist in identifying failures from this window but you can handle these your own way and output to a file if needed.

针对多台设备的更新我不确定是否使用多个设备,我会考虑 selenium grid 我之前尝试添加 2 个设备对一台机器和测试有混淆,其中无论设备 ID 添加到配置和命令中,adb 都无法区分.Appium 团队一直在改进以向服务器添加网格功能,我建议您查看 Appium Grid(链接已更新)

Update for multiple devices I am unsure on the use of multiple devices, I would consider selenium grid my previous attempts to add 2 devices to one machine and test had confusion where adb was unable to distinguish regardless of the device id addition to the configuration and commands. The Appium team have been making improvements to add grid functionality to the server, I recommend you have a look into Appium Grid (link updated)

对于我缺乏使用网格的经验来进一步帮助您,我深表歉意.

I apologize for my lack the experience with grid to assist you further.

问候,布赖恩

这篇关于如何为 Android 自动化设置 Appium 环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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