appium test findElement按钮单击不起作用

时间:2014-12-29 15:58:16

标签: java android appium

我正在尝试使用appium for android在eclipse中运行测试。当测试开始并且应用程序启动时,它会在尝试按下按钮时在第一个命令上引发错误。我非常确定按钮的id是正确的,因为运行与selendroid相同的代码工作。失败跟踪时的错误显示java.lang.NullPointerException。这是我的代码:

package thePack;

import static org.junit.Assert.*;
import io.appium.java_client.AppiumDriver;

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

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class theTest {


static AppiumDriver driver;

@Before
public void setUp() throws MalformedURLException, InterruptedException, Exception
{
    WebDriver dr;

    File app = new File("C:\\development\\src\\main\\resources\\app.apk");
    DesiredCapabilities capabilities= new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
    capabilities.setCapability("deviceName", "Vodafone Smart 4G");
    capabilities.setCapability("platformVersion", "4.2.2");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("app", app.getAbsolutePath());       
    capabilities.setCapability("appium-version", "1.2.1");        
    capabilities.setCapability("appPackage", "mypackage.mine.net");       
    capabilities.setCapability("appActivity", "mypackage.mine.net.activities.mainActivity");


    dr = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities) ;


}

@Test
public void login() throws Exception

{
    Thread.sleep(0500);         
    driver.findElement(By.id("english")).click();
    Thread.sleep(0500);
}

有什么想法吗?谢谢!

2 个答案:

答案 0 :(得分:0)

行:

capabilities.setCapability(CapabilityType.BROWSER_NAME,“”);

表示您的测试将在浏览器上执行,这应该在开始测试时打开浏览器。因此,永远不会找到你的元素

答案 1 :(得分:0)

找出问题所在。对我来说问题是Appium版本本身。我正在运行1.3.4.1并使用Android 4.2.2设备。一旦我为Appium切换到1.2.4.1版本,我就没有问题了!