appiumappium-androidtestng-eclipse

Unable to select the side menu button in TestNG (Appium, Android)


The red box contains the button i want to access using driverI am new to this, but as far as i have searched there isn't a generic manner to click the side bars of your application.

I am currently trying to test Piazza application(for College Assignment). Firstly there isn't any resource_id for menu/list items, the methods I have tried aren't working for me. Can anyone please guide me regarding selection of such buttons appearing on the side bar

All the lines commented are existing solutions online which i have already tried.

 @BeforeSuite
  public void setupAppium() throws MalformedURLException {
        final String URL_STRING = "http://0.0.0.0:4723/wd/hub";  
        url = new URL(URL_STRING);
        capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Android Device");
        capabilities.setCapability(MobileCapabilityType.APP, "/Users/nomi/Desktop/piazza.apk");
        capabilities.setCapability(MobileCapabilityType.NO_RESET, true);
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
        driver = new AndroidDriver<MobileElement>(url, capabilities);
        driver.resetApp();
  }




  @Test ( enabled=true) public void logIn() throws InterruptedException   {

      driver.findElement(By.id("com.piazza.android:id/Login_editText_email")).sendKeys("l154053@lhr.nu.edu.pk");
      driver.findElement(By.id( "com.piazza.android:id/Login_editText_password")).sendKeys("viscabarca");
      driver.findElement(By.id( "com.piazza.android:id/Login_button_login" )).click();


  }




  @Test (enabled=true) public void getList() throws InterruptedException {
      //driver.findElementsByAccessibilityId("Open navigation drawer").get(0).click();
      //driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //driver.findElement(By.xpath("//*[@content-desc='"+"Open drawer"+"']")).click();
      // driver.manage().timeouts().wait(2);
      // driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

        //driver.findElement(By.id( "com.piazza.android:id/AddClassMenu_addButton" )).click();
          //List<MobileElement> list = driver.findElements(By.id("com.piazza.android:id/list"));
          //list.get(0).click();
          //  System.out.print(list.size());
          //List nameOfList = driver.findElements(By.id("id of relative layout"));
        List<MobileElement> list = driver.findElements(By.id("com.piazza.android:id/list"));
          //list.get(0).click();
    System.out.print(list.size());
      }



}

The list.size() in get list function returns size=0 it executes before the login function. I used the depends on keyword but it still returns 0. Furthermore, I don't know what list is being fetched by this id.


Solution

  • Since there is content desc in the element, you can access the element using findElementByAccessibilityId().

    driver.findElementByAccessibilityId("Open Navigation drawer")click();
    

    I suggest you to use Appium Desktop Inspector instead of uiautomatorviewer. It will show you any unique id of the element as well as xpath.