tomation中制作可选择的appPackage和appAct

tomation中制作可选择的appPackage和appAct

本文介绍了如何在android Appium Test Automation中制作可选择的appPackage和appActivity BeforeScenario的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在@BeforeScenario 中选择启动app(appPackage,appActivity) 来为一个测试项目中的多个应用开发一个测试场景.我知道使用 start 活动,但由于安全许可被拒绝,我无法使用它.唯一的工作方法是使用 beforeScenario 中的功能.在开始测试之前,我想选择启动应用程序.我的代码:

I want to choose starting app(appPackage,appActivity) in @BeforeScenario to develop a test scenarios for multiple apps in one test project. I know use the start activity but because of security permission denial, I can not use it. The only working method is using capabilities in beforeScenario. Before start the test I want to choose the starting app.My Code:

`@BeforeScenariopublic void beforeScenario() 抛出 MalformedURLException {

`@BeforeScenario public void beforeScenario() throws MalformedURLException {

    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    desiredCapabilities
            .setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
    desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "device");
    desiredCapabilities.setCapability(MobileCapabilityType.UDID, "L2N4C19924005752");
    if (localAndroid) {
        logger.info("Local Browser");


        desiredCapabilities
                .setCapability(AndroidMobileCapabilityType.APP_PACKAGE,
                        notapadAppPackageName);
        desiredCapabilities
                .setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,
                        notepadAppActivityName);

    }

    desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
    desiredCapabilities.setCapability(MobileCapabilityType.NO_RESET, true);
    desiredCapabilities.setCapability(MobileCapabilityType.FULL_RESET, false);
    desiredCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);
    desiredCapabilities.setCapability("unicodeKeyboard", false);
    desiredCapabilities.setCapability("appWaitDuration", 30);
    desiredCapabilities.setCapability("resetKeyboard", false);
    URL url = new URL("http://localhost:4723/wd/hub");
    appiumDriver = new AndroidDriver(url, desiredCapabilities);

    selector = SelectorFactory
            .createElementHelper(localAndroid ? SelectorType.ANDROID : SelectorType.IOS);
    appiumDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    appiumFluentWait = new FluentWait(appiumDriver);
    appiumFluentWait.withTimeout(8, TimeUnit.SECONDS)
            .pollingEvery(350, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class);
}

`

推荐答案

您可以从 VM 参数中传递应用程序名称,并在此基础上设置驱动程序实例.请看下面的代码:

You can pass app name from VM aguements and base on that you can set driver instance. Please have a look on code below:

@BeforeScenario public void beforeScenario(String appName) throws MalformedURLException {

    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    switch (appName) {
  case "notepadApp":
    desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,notapadAppPackageName);
    desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,notepadAppActivityName);
    break;
  case "App-A":
    desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,appAAppPackageName);
    desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,appApadAppActivityName);
    break;
    case "App-B":
    desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE,appBAppPackageName);
    desiredCapabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY,appBApadAppActivityName);
    break;
  default:
    System.out.println("No matching app is found.");
}

    // Common desired capabilities set
    desiredCapabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
    desiredCapabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "device");
    desiredCapabilities.setCapability(MobileCapabilityType.UDID, "L2N4C19924005752");
    desiredCapabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "uiautomator2");
    desiredCapabilities.setCapability(MobileCapabilityType.NO_RESET, true);
    desiredCapabilities.setCapability(MobileCapabilityType.FULL_RESET, false);
    desiredCapabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);
    desiredCapabilities.setCapability("unicodeKeyboard", false);
    desiredCapabilities.setCapability("appWaitDuration", 30);
    desiredCapabilities.setCapability("resetKeyboard", false);
    URL url = new URL("http://localhost:4723/wd/hub");
    appiumDriver = new AndroidDriver(url, desiredCapabilities);

    selector = SelectorFactory
            .createElementHelper(localAndroid ? SelectorType.ANDROID : SelectorType.IOS);
    appiumDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    appiumFluentWait = new FluentWait(appiumDriver);
    appiumFluentWait.withTimeout(8, TimeUnit.SECONDS)
            .pollingEvery(350, TimeUnit.MILLISECONDS)
            .ignoring(NoSuchElementException.class);
}

这篇关于如何在android Appium Test Automation中制作可选择的appPackage和appActivity BeforeScenario的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 01:35