Appium - Find appPackage and appActivity

Steps



  • Make sure the emulator is up and running 
  • Make sure the app for which you want to find appPackage and appActivity should be up and running in the emulator
  • Go to CMD
  • Run command: adb shell
  • Run dumpsys window windows | grep -E ‘mCurrentFocus’
  • Refer the screenshot to get the appPackage and appActivity


  • Now you can use the same in code
@BeforeClass
  public void beforeClass() throws MalformedURLException {
     
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(MobileCapabilityType.DEVICE_NAME, "Pixel_2_XL_API_27");
    caps.setCapability(MobileCapabilityType.UDID, "emulator-5554"); //DeviceId from "adb devices" command
          //caps.setCapability("platformName", "Android");
          //caps.setCapability("platformVersion", "8.1");
          //caps.setCapability("skipUnlock","true");
          caps.setCapability("appPackage", "com.android.calculator2");
          caps.setCapability("appActivity","com.android.calculator2.Calculator");

          caps.setCapability("noReset","false");
     
    driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), caps);
  }

No comments:

Post a Comment