无法执行appium android本机代码

时间:2016-02-17 11:18:07

标签: android appium

对于appium非常新:

我想在我的设备中运行代码,通过appium使用UIAutomater查看器,但无法在控制台上继续获取错误。 我尝试使用资源ID和文本。

package Policybazaar;

import java.net.MalformedURLException;
import java.net.URL;
import org.junit.Before;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test; 

public class login {

    private RemoteWebDriver driver;

    @Before
    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("BROWSER_NAME", "Android");
        capabilities.setCapability("VERSION", "5.0.2"); 
        capabilities.setCapability("deviceName","ZX1D64M6BG");
        capabilities.setCapability("platformName","Android");
        capabilities.setCapability("appPackage", "com.policybazaar");
        capabilities.setCapability("appActivity","com.policybazaar.login.Splash_DashBoard");
        driver = new RemoteWebDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
    }

    @Test
    public void login() throws Exception {
        WebElement MobileNo= driver.findElement(By.name("Enter Your Mobile No."));
        MobileNo.sendKeys("9000022222");
        WebElement submitbutton=driver.findElement(By.id("com.policybazaar:id/mobile_num_submit_button"));
        submitbutton.click();
        Thread.sleep(2000);
    }   

    @AfterClass
    public void teardown(){
        close the app
        driver.quit();
    }
}

但收到以下错误:

FAILED: login
java.lang.NullPointerException
    at Policybazaar.login.login(login.java:37)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:773)
    at org.testng.TestRunner.run(TestRunner.java:623)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:352)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:310)
    at org.testng.SuiteRunner.run(SuiteRunner.java:259)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1185)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1110)
    at org.testng.TestNG.run(TestNG.java:1018)
    at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)   

1 个答案:

答案 0 :(得分:0)

如果定位器未映射到您正在处理的视图上的相应元素,则可以调试和评估submitbuttonMobileNo元素的值,该值可能等于null