通过 Appium 在 Android 操作系统上运行 Selenium 测试

Posted

技术标签:

【中文标题】通过 Appium 在 Android 操作系统上运行 Selenium 测试【英文标题】:Running Selenium Test on Android OS through Appium 【发布时间】:2015-03-15 09:18:53 【问题描述】:

我正在尝试在 android 模拟器上运行我的 selenium 测试,但这不能正常工作。我使用eclipse在java中编写我的代码,设置如下 1. selenium-server-standalone-jar.2.44.0 2.testng-6.8.jar 3.appium 1.3.4.1 这些是我要发送给 Appium 的功能

@BeforeMethod()
public void setUp() throws Exception 

    //Appium needs the path of app build
    //Set up the desired capabilities and pass the ios SDK version and app path to Appium
    DesiredCapabilities capabilities = new DesiredCapabilities();

    File appDir = new File("C:/Appium");
    File app = new File(appDir, "android-server-2.38.0.apk");        
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("automationName", "Appium");       
    capabilities.setCapability("deviceName", "Nexus_5");
    capabilities.setCapability("browserName", "Firefox");

    driver = new SelendroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);

这是我通常从 Eclipse 得到的输出

FAILED CONFIGURATION: @AfterMethod tearDown
org.openqa.selenium.WebDriverException: Not yet implemented. Please help us: http://appium.io/get-involved.html (WARNING: The server did not provide any stacktrace information)

这是我通常从 Appium 得到的输出

> Starting Node Server
> info: Welcome to Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe)
> info: Appium REST http interface listener started on 127.0.0.1:4723
> info: [debug] Non-default server args: "app":"C:\\Appium\\android-server-2.38.0.apk","address":"127.0.0.1","fullReset":true,"logNoColors":true,"androidPackage":"org.openqa.selenium.android.app","androidActivity":".MainActivity","avd":"N5-Emulator","deviceName":"Nexus_5","platformName":"Android","platformVersion":"19","automationName":"Appium"
> info: Console LogLevel: debug
> info: --> POST /wd/hub/session "desiredCapabilities":"automationName":"Appium","platformName":"Android","deviceName":"Nexus_5","browserName":"Firefox"
> info: Client User-Agent string: Apache-HttpClient/4.3.2 (java 1.5)
> info: [debug] Using local app from command line: C:\Appium\android-server-2.38.0.apk
> info: [debug] Creating new appium session daa741f2-6153-441d-951e-b4f17f3e4e09
> info: Starting android appium
> info: [debug] Getting Java version
> info: Java version is: 1.7.0_55
> info: [debug] Using fast reset? false
> info: [debug] Preparing device for session
> info: [debug] Checking whether app is actually present
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from C:\Program Files (x86)\Android\sdk\platform-tools\adb.exe
> info: [debug] Trying to find N5-Emulator emulator
> info: [debug] Getting connected emulators
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: "C:\Program Files (x86)\Android\sdk\platform-tools\adb.exe" devices
> info: [debug] 1 device(s) connected
> info: [debug] 1 emulator(s) connected
> info: [debug] Sending telnet command to device: avd name
> info: [debug] Getting running emulator port
> info: [debug] Socket connection to device created
> info: [debug] Socket connection to device ready
> info: [debug] Telnet command got response: N5-Emulator
> info: [debug] Found emulator N5-Emulator in port 5556
> info: [debug] Setting device id to emulator-5556
> info: [debug] Did not launch AVD because it was already running.
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: "C:\Program Files (x86)\Android\sdk\platform-tools\adb.exe" -s emulator-5556 wait-for-device
> info: [debug] executing cmd: "C:\Program Files (x86)\Android\sdk\platform-tools\adb.exe" -s emulator-5556 shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Getting device API level
> info: [debug] executing cmd: "C:\Program Files (x86)\Android\sdk\platform-tools\adb.exe" -s emulator-5556 shell "getprop ro.build.version.sdk"

毕竟,我在模拟器上看到一个空白屏幕,上面写着“WebDriver Ready”,就是这样,它没有打开浏览器或任何东西。任何帮助将不胜感激。

【问题讨论】:

用@AfterMethod 注释的方法看起来如何? 嗨,在@AfterMethod 中,我想我只是在打电话给driver.close(); driver.quit();,但我只是凭记忆说话,因为出于逻辑原因,我早就放弃了让它工作 嗨!我明白了,放弃这些事情对我来说也是如此。似乎某些被调用的方法没有实现。与 here 相同,使用 .close 方法。 我开始意识到 appium 只能用于测试应用程序,而不能用于测试使用 chrome 或 firefox 等浏览器的网站上的移动兼容性。我真的希望有人能证明我错了。 好的:)。你有没有发现任何测试移动兼容性的东西,似乎移动兼容性测试相当经验? 【参考方案1】:

我知道这个问题很老了。但是找到一个使用 Appium here 的 Android 功能测试框架的示例工作模板,它是在 Java 中并从代码中启动 Appium 服务器。这意味着,您不必每次在运行这些测试之前都启动 Appium 应用程序,并且它可以轻松集成到 CI 服务器。

【讨论】:

【参考方案2】:

我的建议是,在编写任何代码之前,先手动尝试,这样当你启动并运行所有代码时,真的很容易注入代码。

请检查以下要求:

在服务器部分 (Appium) 启动活动是否为真, 模拟器名称是否正确, API 级别与模拟器相同,

在代码方面(java、pyhton、c#...):

检查服务器中提供的所有数据是否都被“注入”到所需的功能中

检查此链接,这是一个很好的起点: https://appium.io/docs/en/writing-running-appium/running-tests/#running-your-test-app-with-appium-android

【讨论】:

以上是关于通过 Appium 在 Android 操作系统上运行 Selenium 测试的主要内容,如果未能解决你的问题,请参考以下文章

appium 架构原理

appium自动化 - android

Python Appium自动化测试 Monkey搭建+操作

appium(四) 操作介绍

appium在android7.0上无法启动问题

appium简介