简体   繁体   中英

How to open Android app list with appium?

I need to automate the verification of the notification badge on the app icon on Android. The problem is Android places icons in the app list menu, which is opened by swiping the main screen up. Is there a way to get into that app list menu in Android using appium?

在此处输入图像描述

Imports required:

import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import org.testng.annotations.Test;
import io.appium.java_client.MobileBy.ByAccessibilityId;
import io.appium.java_client.MobileElement;
import io.appium.java_client.TouchAction;
import io.appium.java_client.android.AndroidDriver;

import io.appium.java_client.android.nativekey.AndroidKey;
import io.appium.java_client.android.nativekey.KeyEvent;

import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.remote.MobileCapabilityType;

import static io.appium.java_client.touch.offset.PointOption.point;

Code:

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11");
    capabilities.setCapability(MobileCapabilityType.APP, "C:\\Users\\prave\\Downloads\\ApiDemos-debug.apk");
    capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
    capabilities.setCapability(AndroidMobileCapabilityType.AVD, "Pixel_XL_API_30");
    
    capabilities.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "io.appium.android.apis");
    capabilities.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "io.appium.android.apis.ApiDemos");
    
    
    AndroidDriver<MobileElement> driver = new AndroidDriver<MobileElement>(capabilities);

    driver.longPressKey((new KeyEvent(AndroidKey.HOME) ));

    WebDriverWait wait = new WebDriverWait(driver, 10000);
    wait.until(ExpectedConditions.presenceOfElementLocated(ByAccessibilityId.AccessibilityId("Apps list")));
    MobileElement elem = driver.findElementByAccessibilityId("Apps list");
    new TouchAction(driver).press(point(elem.getLocation())).moveTo(point(elem.getLocation().x, -500)).perform();
    

Explanation

Appium has keypress event but the key press event for "KEYCODE_ALL_APPS" is not working. so you have to goto home by clicking driver.longPressKey((new KeyEvent(AndroidKey.HOME)));

Once there, identify the element "arrow key" to swipe up, now use that element to swipe up using action class

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM