<repo_name>jhyhhmail/appium<file_sep>/src/main/java/com/jhyhh/appium/utils/BooleanUtils.java
package com.jhyhh.appium.utils;


public class BooleanUtils {

    /**
     * true|y|1|yes|on
     */
    public static boolean isTrue(String str) {

        return ("yes".equalsIgnoreCase(str) || "1".equalsIgnoreCase(str)
                || "true".equalsIgnoreCase(str) || "on".equalsIgnoreCase(str)
                || "y".equalsIgnoreCase(str));
    }

    public static boolean isTrue(Object obj) {
        if (obj == null) {
            return false;
        }
        if (obj instanceof Boolean) {
            return ((Boolean) obj).booleanValue();
        }
        if (obj instanceof Number) {
            return (((Number) obj).intValue() != 0);
        }
        String str = String.valueOf(obj);
        return isTrue(str);
    }

    /**
     * true|y|1|yes|on
     */
    public static boolean isTrue(String str, boolean defaultValue) {
        if (str == null) {
            return defaultValue;
        }
        return isTrue(str);
    }
}
<file_sep>/src/main/java/com/jhyhh/appium/android/T12306/launcher/TestAppium.java
package com.jhyhh.appium.android.T12306.launcher;

import io.appium.java_client.android.AndroidDriver;

import java.util.List;

import org.openqa.selenium.WebElement;

import com.jhyhh.appium.AndroidDriverManager;
import com.jhyhh.appium.AndroidDriverWait;
import com.jhyhh.appium.ExpectedCondition;

public class TestAppium {

	public static void main(String[] args) {
		AndroidDriverManager app = new AndroidDriverManager();
		AndroidDriver<WebElement> driver = app
				.getAndroidDriver("LGD857d51963f0");

		app.waitTime(20000);
		// 如果有升级执行升级动作
		WebElement el = new AndroidDriverWait(driver, 60)
				.until(new ExpectedCondition<WebElement>() {
					public WebElement apply(AndroidDriver d) {
						return d.findElementByAndroidUIAutomator("new UiSelector().text(\"升级\")");
					}
				});
		el.click();

		new AndroidDriverWait(driver, 60)
				.until(new ExpectedCondition<WebElement>() {
					public WebElement apply(AndroidDriver d) {
						return d.findElementByAndroidUIAutomator("new UiSelector().descriptionContains(\"温馨提示\")");
					}
				});
		// 等待加载完成后点目的站文本框，选择目的站。
		List<WebElement> editTexts = new AndroidDriverWait(driver, 60)
				.until(new ExpectedCondition<List<WebElement>>() {
					public List<WebElement> apply(AndroidDriver d) {
						return d.findElementsByClassName("android.widget.EditText");
					}
				});
		editTexts.get(1).click();
		// 选择车站列表Tab
		List<WebElement> mudiButtons = new AndroidDriverWait(driver, 60)
				.until(new ExpectedCondition<List<WebElement>>() {
					public List<WebElement> apply(AndroidDriver d) {
						return d.findElementsByClassName("android.widget.Button");
					}
				});
		mudiButtons.get(3).click();
		app.waitTime(5000);
		// 切换到J 开头的List
		new AndroidDriverWait(driver, 60).until(
				new ExpectedCondition<WebElement>() {
					public WebElement apply(AndroidDriver d) {
						return d.findElementByAndroidUIAutomator("new UiSelector().descriptionContains(\"j\")");
					}
				}).click();
		// 根据下标找到佳木斯view
		new AndroidDriverWait(driver, 60)
				.until(new ExpectedCondition<List<WebElement>>() {
					public List<WebElement> apply(AndroidDriver d) {
						return d.findElementsByClassName("android.view.View");
					}
				}).get(9).click();

		List<WebElement> buttons = new AndroidDriverWait(driver, 60)
				.until(new ExpectedCondition<List<WebElement>>() {
					public List<WebElement> apply(AndroidDriver d) {
						return d.findElementsByClassName("android.widget.Button");
					}

				});
		buttons.get(buttons.size() - 1).click();
		System.out.println("end");
	}

}<file_sep>/src/main/java/com/jhyhh/appium/AndroidADBUtils.java
package com.jhyhh.appium;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import org.apache.commons.lang3.StringUtils;

public class AndroidADBUtils {

	synchronized static public List<String> getDevices() {
		Process process = null;
		try {
			process = Runtime.getRuntime().exec("adb devices");
			process.waitFor();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		InputStreamReader isr = new InputStreamReader(process.getInputStream());
		Scanner sc = new Scanner(isr);
		List<String> devices = new ArrayList<String>();
		while (sc.hasNext()) {
			String device = sc.nextLine();
			if(StringUtils.isEmpty(device)){
				continue;
			} 
			if(device.endsWith("device")){
				device = device.replace("device", "").trim();
				devices.add(device);
			}
		}
		sc.close();
		return devices;
	}

	public static void main(String[] args) {
		System.out.println(AndroidADBUtils.getDevices());
	}
}
<file_sep>/src/main/java/com/jhyhh/appium/ExpectedCondition.java
package com.jhyhh.appium;


import io.appium.java_client.android.AndroidDriver;

import com.google.common.base.Function;


/**
 * Models a condition that might reasonably be expected to eventually evaluate to something that is
 * neither null nor false. Examples would include determining if a web page has loaded or that an
 * element is visible.
 * <p>
 * Note that it is expected that ExpectedConditions are idempotent. They will be called in a loop by
 * the {@link WebDriverWait} and any modification of the state of the application under test may
 * have unexpected side-effects.
 * 
 * @param <T> The return type
 */
public interface ExpectedCondition<T> extends Function<AndroidDriver, T> {}<file_sep>/target/m2e-wtp/web-resources/META-INF/maven/com.jhy.phone/appium/pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.jhy.phone</groupId>
	<artifactId>appium</artifactId>
	<packaging>war</packaging>
	<version>0.0.1-SNAPSHOT</version>
	<name>appium Maven Webapp</name>
	<url>http://maven.apache.org</url>
	<dependencies>
		<!--dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> 
			<version>2.2.4</version> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> 
			<artifactId>selenium-java</artifactId> <version>2.47.1</version> </dependency> 
			<dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> 
			<scope>test</scope> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> 
			<artifactId>httpclient</artifactId> <version>4.3.3</version> </dependency> 
			<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> 
			<version>17.0</version> </dependency> <dependency> <groupId>cglib</groupId> 
			<artifactId>cglib</artifactId> <version>3.1</version> </dependency> <dependency> 
			<groupId>commons-validator</groupId> <artifactId>commons-validator</artifactId> 
			<version>1.4.1</version> </dependency -->

		<dependency>
			<groupId>commons-lang</groupId>
			<artifactId>commons-lang</artifactId>
			<version>2.6</version>
		</dependency>
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.4</version>
		</dependency>
		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
			<version>1.2.9</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>io.appium</groupId>
			<artifactId>java-client</artifactId>
			<version>3.1.0</version>
		</dependency>

	</dependencies>
	<build>
		<finalName>appium</finalName>
	</build>
</project>
