简体   繁体   中英

Not able to click on permission pop-up (Access Contact List) in appium

I am new to Appium. I am trying to automate an application which on launch asks to allow to access Contact List. I did research on various websites for the solution but couldn`t resole this issue.

Code:

public class TestSuiteBase {
WebDriver driver = null;

//Element Variables
String deviceIdTextbox = "et_Registration_DeviceID";

@BeforeClass
public void setup() throws MalformedURLException, InterruptedException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("platformVersion", "4.4.2");
    capabilities.setCapability("deviceName", "0ef3c26f");
    capabilities.setCapability("browserName", "");
    capabilities.setCapability("app", "D:\\Ashish\\AppiumProject\\Mobile Framework\\apk\\androidApplication.apk");
    capabilities.setCapability("appPackage", "com.atyati.rbl.mfi");
    capabilities.setCapability("appActivity", "com.atyati.rbl.mfi.Activity.SplashScreenActivity");

    AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
    Thread.sleep(10000);        
}


@Test
public void Test() throws Exception {
    Thread.sleep(2000);
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("appWaitPackage", "com.android.packageinstaller");
    capabilities.setCapability("appWaitActivity", ".permission.ui.GrantPermissionsActivity");

    System.out.println("Trying to click Allow");

    driver.findElement(MobileBy.id("permission_allow_button")).click();
    driver.findElement(By.id(deviceIdTextbox)).sendKeys("123456789");
}

@AfterClass
public void tearDown() throws Exception {
    driver.quit();
}

Output: My code launches the app but when permission pop-up surfaces, it is unable to click.

Issue: Not able click on permission pop-up.

Query: Do I need to specify "appActivity" before moving to each screen?

Let me know if any other details needed.

I have figured it out where I was going wrong.

Solution: I have to specify the complete resource id for the Edit Textbox

String deviceIdTextbox = "com.atyati.rbl.mfi:id/et_Registration_DeviceID";

Also, it is not needed to specify the activity.

@Test
public void Test() throws Exception {
    Thread.sleep(1000);
    if(androidDriver!=null){
        System.out.println("driver does not == null");
        System.out.println("Trying to click Allow");

        androidDriver.findElement(By.id(contactListAllowPermissionBtn)).click();
        Thread.sleep(1000);
        androidDriver.findElement(By.id(deviceIdTextbox)).sendKeys("123456789");
        androidDriver.findElement(By.id(registerUserBtn)).click();
    } else {
        System.out.println("driver == null");
    }
}

You can use this JAVA CODE for clicking on allow app permission button as many times it appears. just add the method and in your class file and call the method in your test case. This code is taken from example on THIS POST

public void allowAppPermission(){
 while (driver.findElements(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).size()>0) 

 {  driver.findElement(MobileBy.xpath("//*[@class='android.widget.Button'][2]")).click();
 }
}

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