package org.tspring.atfwa.Test;

import io.appium.java_client.AppiumDriver;

import java.net.MalformedURLException;
import java.net.URL;

import org.openqa.selenium.By;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

public class App
{
public static void main(String args[]) throws MalformedURLException {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.BROWSER_NAME, "");
cap.setCapability("platformName", "Android");
cap.setCapability("deviceName", "Android Emulator");
cap.setCapability("platformVersion", "4.4");
cap.setCapability("appPackage", "com.android.calculator2");
cap.setCapability("appActivity", ".Calculator");

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

dr.findElement(By.id("com.android.calculator2:id/digit9")).click();
}
}

执行之后抛:
Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: A new session could not be created. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 172 milliseconds
Build info: version: '2.42.1', revision: '68b415adb11acca4286be45124325cc36cfc4a51', time: '2014-05-29 09:21:55'
System info: host: 'ivy-PC', ip: '172.16.32.79', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_60'
Driver info: io.appium.java_client.AppiumDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:127)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:154)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:43)
at org.tspring.atfwa.Test.App.main(App.java:27)


↙↙↙阅读原文可查看相关链接,并与作者交流