能够安装亚马逊应用程序但无法打开它

时间:2016-10-27 19:59:31

标签: java selenium mobile appium

enter image description here在apk文件的帮助下我可以安装Android应用程序,但它没有打开。请看一次我的代码:

package Test1;

import io.appium.java_client.android.AndroidDriver;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class Amazon_LogIn_Test {
private static AndroidDriver driver;

@BeforeMethod
@Test
public void setUp() throws Exception  {

File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "/Apps/Amazon/");
File app = new File(appDir, "com.amazon.mShop.android.shopping-5.2.3-502030-  minAPI9.apk");

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability("deviceName", "BECUPJTWGA7HAQQK");
capabilities.setCapability("platformVersion", "5");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "com.amazon.mShop.android.shopping");
capabilities.setCapability("appActivity",   "com.amazon.mShop.splashscreen.StartupActivity");

driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(10000);

    // Click on Shop by Deparment link
     driver.findElement(By.id("com.amazon.mShop.android.shopping:id/search_edit_text")).click();
    // Click on Main menu
    driver.findElementByClassName("android.widget.ImageView").click();
    // Click on Home link under Main menu
    driver.findElement(By.name("Home")).click();
    // Click on Sign In link on the Home Screen
    driver.findElementByName("Sign inHello. Link").click();

    Thread.sleep(10000);
    driver.findElement(By.xpath("//*[@content-desc='Hello. Sign in']"));

}

使用上面的代码,我可以安装亚马逊应用程序并且能够打开应用程序,但是点击登录选项的最后一行没有被点击,我尝试了很多方法来做到这一点。请帮助我。

2 个答案:

答案 0 :(得分:0)

在所需的功能而不是登录活动中,请使用启动活动,您需要更改以下行代码中的活动:

capabilities.setCapability("appActivity","com.amazon.mShop.sso.SigninPromptActivity")

答案 1 :(得分:0)

试试这个appActivity:

capabilities.setCapability("appPackage", "in.amazon.mShop.android.shopping");
capabilities.setCapability("appActivity",   "com.amazon.mShop.splashscreen.StartupActivity");

我认为您的包裹名称错误应该是“in.amazon.mShop.android.shopping”而不是“com.amazon.mShop.android.shopping”