如何使用 appium 在浏览器堆栈中执行期间更新应用程序?

问题描述

这是APP正常更新的示例代码, @RunWith(JUnit4.class) 公开课 Edition009_Android_Upgrade {

private String APP_PKG = "io.cloudgrey.the_app";
private String APP_ACT = "com.theapp.MainActivity";

private String APP_V1_0_0 = "https://github.com/cloudgrey-io/the-app/releases/download/v1.0.0/TheApp-v1.0.0.apk";
private String APP_V1_0_1 = "https://github.com/cloudgrey-io/the-app/releases/download/v1.0.1/TheApp-v1.0.1.apk";
private String APP_V1_0_2 = "https://github.com/cloudgrey-io/the-app/releases/download/v1.0.2/TheApp-v1.0.2.apk";


private String TEST_MESSAGE = "Hello World";

private By msginput = MobileBy.AccessibilityId("messageInput");
private By savedMsg = MobileBy.AccessibilityId(TEST_MESSAGE);
private By saveMsgBtn = MobileBy.AccessibilityId("messageSaveBtn");
private By echoBox = MobileBy.AccessibilityId("Echo Box");

@Test
public void testSavedTextAfterUpgrade () throws IOException {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability("platformName","Android");
    capabilities.setCapability("deviceName","Android Emulator");
    capabilities.setCapability("automationName","UiAutomator2");
    capabilities.setCapability("app",APP_V1_0_0);

    // change this to APP_V1_0_1 to experience a failing scenario
    String appUpgradeVersion = APP_V1_0_2;

    // Open the app.
    AndroidDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"),capabilities);

    webdriverwait wait = new webdriverwait(driver,10);

    try {
        wait.until(ExpectedConditions.presenceOfElementLocated(echoBox)).click();
        wait.until(ExpectedConditions.presenceOfElementLocated(msginput)).sendKeys(TEST_MESSAGE);
        wait.until(ExpectedConditions.presenceOfElementLocated(saveMsgBtn)).click();
        String savedText = wait.until(ExpectedConditions.presenceOfElementLocated(savedMsg)).getText();
        Assert.assertEquals(savedText,TEST_MESSAGE);

        driver.installApp(appUpgradeVersion);
        Activity activity = new Activity(APP_PKG,APP_ACT);
        driver.startActivity(activity);

        wait.until(ExpectedConditions.presenceOfElementLocated(echoBox)).click();
        savedText = wait.until(ExpectedConditions.presenceOfElementLocated(savedMsg)).getText();
        Assert.assertEquals(savedText,TEST_MESSAGE);
    } finally {
        driver.quit();
    }
}

}

请帮助我为这种情况设置浏览器堆栈,我需要在两者之间更新应用程序

解决方法

有一种方法可以实现这一点。目前这仍然是一种解决方法,并且正在处理流程。

第 1 步:使用 REST API 上传应用的两个版本。请记下每个版本的哈希 ID。

参考:https://www.browserstack.com/docs/app-automate/api-reference

第 2 步:需要在会话开始前上传会话中所需的应用。在此步骤中,仅上传应用程序,但未在设备上预安装应用程序。

app 功能指定为主应用(低版本):

"app": "bs://<hash-ad>"

第 3 步:在 otherApps 功能内指定要在会话中使用的应用。这将是该应用程序的较新版本:

"otherApps" : ["bs://<hash-id-of-newer-app>","bs://<hash-id-of-newer-app>"]

如果 bundle id 相同,我们不会在会话开始之前安装应用程序,但实际安装会发生,当您调用时 installApp("bs://hashed-id") 命令。

第 4 步:在会话中间,您可以运行 installApp("bs://hashed-id") 命令并传递在 otherApps 功能中发送的 app_url。

driver.installApp("bs://<hashed-id-of-newer-app>");
Activity activity = new Activity(APP_PKG,APP_ACT);
driver.startActivity(activity);

这是目前的解决方法。我们正在努力优化此工作流程。

如果您对此有疑问,可以直接联系 support@browserstack.com。


更新:

BrowserStack 现在支持在会话中测试应用升级的工作流。

https://www.browserstack.com/docs/app-automate/appium/advanced-features/test-app-upgrades