使用appium节点服务器在模拟器上安装Android APK

我有一个在NODE.JS中创build的appium服务器。 我正在制作appiumtesting来运行模拟器并安装apk。 无法在网上find任何具体的例子,如何使用节点服务器。 大多数情况下,桌面安装的appium服务器就是这样的例子 我需要一些关于如何做到这一点的指导方针。 为了进一步细化,我想使用appium Node服务器来执行以下的事情(不要在应用程序源代码中纠正任何testing用例)

  1. 启动模拟器或可能的话,如果可以在真实的设备上进行
  2. 在模拟器/设备上安装APK
  3. 启动在模拟器/设备上启动应用程序的意图。 意图还包含数据包中的数据
  4. 点击应用程序中的button。

  1. 在你的terminal启动appium服务器

    appium

  2. 在你的terminal上面输出如下的命令

在这里输入图像描述

  1. 示例代码在这里:

    公共类AppTest {

     AppiumDriver driver; MobileElement appTitle; @Before public void setup() throws MalformedURLException { DesiredCapabilities desiredCapabilities = new DesiredCapabilities(); desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android"); desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.0"); desiredCapabilities.setCapability(MobileCapabilityType.NO_RESET, true); desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Moto"); desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.android.vending"); desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.google.android.finsky.activities.MainActivity"); driver = new AndroidDriver(new URL("http://0.0.0.0:4723/wd/hub"), desiredCapabilities); } @Test public void testGooglePlayApp() throws InterruptedException { String appName = "Amazon Now - Grocery Shopping"; //How to scroll to specific text MobileElement scrollToText = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().text(\"" + appName + "\"));")); scrollToText.click(); // Verifying the app detail page appTitle = (MobileElement) driver.findElementById("com.android.vending:id/title_title"); Assert.assertTrue(appName.equals(appTitle.getText().trim())); driver.navigate().back(); //Clicking the search bar icon MobileElement scrollToElement = (MobileElement) driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(new UiSelector().description(\"Search\"));")); scrollToElement.click(); MobileElement editText = (MobileElement) driver.findElementById("com.android.vending:id/search_box_text_input"); editText.sendKeys(appName); Thread.sleep(1000); List<MobileElement> listOfSuggestedResults = driver.findElementsById("com.android.vending:id/suggest_text"); for (MobileElement element : listOfSuggestedResults) { if (appName.equals(element.getText().trim())) { element.click(); break; } } appTitle = (MobileElement) driver.findElementById("com.android.vending:id/title_title"); Assert.assertTrue(appName.equals(appTitle.getText().trim())); } @After public void tearDown() { if (driver != null) { driver.quit(); } } 

    }

github中的示例代码: https : //github.com/tech-tock-tech/apptest

希望以上将帮助,如果你仍然面临的问题,请检查下面的video链接 –

https://www.youtube.com/watch?v=jP2NAY8ylp8