我正在使用Appium 1.6.3和带有Android 7.1.1的Google Pixel。
我正在尝试加载已安装在手机上的Waze应用并接受初始位置许可请求。
我尝试了以下内容:
capabilities.setCapability("autoGrantPermissions", "true");
此外:
capabilities.SetCapability("autoAcceptAlerts", true);
但这些似乎并没有成功。
我在其他网站上看过,自动授予权限仅适用于iOS?
我目前的代码:
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();
}
}
谢谢!
答案 0 :(得分:0)
实际上,我找到了解决问题的方法:
WebElement allow_location = driver.findElement(By.id("com.android.packageinstaller:id/permission_allow_button"));
allow_location.click();
Thread.sleep(1000);
这很有魅力!
答案 1 :(得分:0)
driver.switchTo().alert().accept();
或
driver.switchTo().alert().dismiss();
不要忘记等到警报出现,然后点击它。
答案 2 :(得分:0)
此功能对我有用:
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”
致谢。
答案 3 :(得分:0)
尝试使用 AndroidMobileCapabilityType。它将启用 apk 所需的所有权限。
capabilities.setCapability(AndroidMobileCapabilityType.AUTO_GRANT_PERMISSIONS, "true");