1

我有一个在 NODE.JS 中创建的 appium 服务器。我正在努力进行 appium 测试以运行模拟器并安装 apk。无法在线找到任何特定示例,其中包含有关如何使用 Node 服务器进行操作的示例。大多数示例是桌面安装的 appium 服务器。我需要一些关于如何做到这一点的指导方针。为了进一步分解,我想使用 appium 节点服务器执行以下操作(不要纠正应用程序源代码中的任何测试用例)

  1. 启动模拟器,如果可以在真机上启动,则可以
  2. 在模拟器/设备上安装 APK
  3. 触发在 emulator/device 上启动应用程序的意图。Intent 还包含 bundle 中的数据
  4. 单击应用程序内的按钮。
4

1 回答 1

0
  1. 在终端中启动 appium 服务器

    appium

  2. 在您的终端上输出上述命令,如下所示

在此处输入图像描述

  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

希望以上内容对您有所帮助,如果您仍然遇到问题,请查看以下视频链接 -

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

于 2017-12-13T02:39:23.360 回答