使用真正的Android设备的Appium错误

时间:2014-08-20 23:08:36

标签: selenium selenium-webdriver appium

我在appium中遇到错误。它在模拟器中工作正常,但在设备中没有。请参阅下面的代码和错误日志。谁能让我知道错误的原因。

//Code///////////////////////////////////////
public void setUp() throws Exception{
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/app");
File app = new File(appDir, "app.apk");

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("browserName", "");
capabilities.setCapability("platformVersion", "4.4");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("deviceName", "SCH-I535");

capabilities.setCapability("appPackage", "com.app");
capabilities.setCapability("appActivity", "com.justwink.homepage.HomePageActivity");
capabilities.setCapability("appWaitActivity",          "com.app.homepage.HomePageActivity");


try {
    driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);       
} catch (Exception e) {
    e.printStackTrace();
}

driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
}

3 个答案:

答案 0 :(得分:1)

我通过更改appActivity名称修复了它。 我正式使用层次结构查看器来查找活动名称。 当我使用命令时 aapt dump badging sample.apk它显示了原始活动名称。

答案 1 :(得分:1)

您可能首先需要先忽略以下代码

*File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/app");
File app = new File(appDir, "justwink-usa-2.3.2.218221.69.apk");*

将您的设置代码与此匹配

DesiredCapabilities capabilities = new DesiredCapabilities();
   capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
   capabilities.setCapability("deviceName","sony xperia Z");
   capabilities.setCapability("platformVersion", "4.4");
   capabilities.setCapability("platformName","Android");
   capabilities.setCapability("appPackage", "com.android.calculator2");
   capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");
   driver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

答案 2 :(得分:0)

通过运行以下adb命令

,您还可以通过其他方式获取当前活动
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'