应用程序在通过appium启动后没有执行

时间:2015-06-11 12:55:09

标签: selenium selenium-webdriver appium

请查看以下代码,因为我正在尝试自动化原生Android应用程序,即Policybazaar.apk,下面的代码用selenium + appium编写

问题是应用程序启动但无法单击登录按钮。

package policybazaar;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.*;

public class Policylogin {

    AppiumDriver driver;

    @BeforeClass
    public void setUp() throws MalformedURLException {

        // Set up desired capabilities and pass the Android app-activity and
        // app-package to Appium

        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.VERSION, "5.1.1");
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME,"Android");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"V00776140945009");
        capabilities.setCapability(MobileCapabilityType.APP_PACKAGE,"com.policybazaar"); // This is package name of your app (you
                                        // can get it from apk info app
        capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY,"com.policybazaar.login.Splash_DashBoard"); 
        // This is Launcher activity of your app (you can get it from apk info  app)
        // Create AndroidDriver instance and connect to the Appium server.
        // It will launch the Calculator App in Android Device using the
        // configurations specified in Desired Capabilities

        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
    }

    @Test
    public Policylogin() throws Exception {

            // locate the Text on the policybazaar by using By.name()
            WebElement Login = driver.findElement(By.id("com.policybazaar:id/dashboard_profile"));
            Login.click();

        } 

1 个答案:

答案 0 :(得分:0)

我使用下一个代码

DesiredCapabilities capabilities = new DesiredCapabilities().android();
        capabilities.setCapability("deviceName", "V00776140945009");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("platformVersion", "5.1.1");
        capabilities.setCapability("app", "here_is_the_path_to_apk_file");
        capabilities.setCapability("appPackage", "com.policybazaar");
        capabilities.setCapability("appActivity", ".MainActivity");
        driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);