Reputation: 35
I am using Appium 1.6.3 and a Google Pixel with Android 7.1.1.
I am trying to load the Waze app which is already installed on the phone and accept the initial location permission request.
I have tried the following:
capabilities.setCapability("autoGrantPermissions", "true");
Also:
capabilities.SetCapability("autoAcceptAlerts", true);
But these doesn't seem to do the trick.
I have read on other sites, that the auto granting of permission is only available on iOS?
The code I have currently:
import io.appium.java_client.MobileBy;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.*;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.html5.Location;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class mapTests {
AndroidDriver driver;
Dimension size;
String destDir;
DateFormat dateFormat;
@BeforeTest
public void setup() throws Exception{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "FA6C90301474");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "7.1.1");
capabilities.setCapability("appPackage", "com.waze");
capabilities.setCapability("appActivity", "com.waze.FreeMapAppActivity");
capabilities.setCapability("noSign", true);
capabilities.setCapability("autoGrantPermissions", "true");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testOne()throws Exception {
Location location = new Location(53.7775174,-1.800881200000049,224);
driver.setLocation(location);
takeScreenShot();
}
public void takeScreenShot() {
destDir = "screenshots";
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
dateFormat = new SimpleDateFormat("dd-MMM-yyyy__hh_mm_ssaa");
new File(destDir).mkdirs();
String destFile = dateFormat.format(new Date()) + ".png";
try {
FileUtils.copyFile(scrFile, new File(destDir + "/" + destFile));
} catch (IOException e) {
e.printStackTrace();
}
}
@AfterTest
public void tearDown() throws Exception{
driver.quit();
}
}
Thank you!
Upvotes: 0
Views: 3628
Reputation: 39
try to use the AndroidMobileCapabilityType.It will enable all permissions that apk requires.
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, "true");
Upvotes: 0
Reputation: 1
This capabilities worked for me:
caps = {}
caps[“platformName”] = "Android"
caps[“platformVersion”] = "7.0"
caps[“deviceName”] = "Pixel_C_API_24"
caps[“automationName”] = "UiAutomator2"
caps[“app”] = "/home/tests/app-debug.apk"
caps[“noReset”] = False
caps[“autoGrantPermissions”] = True
caps[“appPackage”] = "com.mypackage"
caps[“appActivity”] = “.MyActivity”
Regards.
Upvotes: 0
Reputation: 19
driver.switchTo().alert().accept();
or
driver.switchTo().alert().dismiss();
And don't forget to wait until the alert is present and then click on it.
Upvotes: 0
Reputation: 35
Actually, I have found an solution to my problem:
WebElement allow_location = driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button"));
allow_location.click();
Thread.sleep(1000);
This works a charm!
Upvotes: 1