<!-- appium -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server-standalone</artifactId>
<version>2.53.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
上jar包
pojo类
package com.ssm.pojo;
import org.openqa.selenium.WebElement;
import io.appium.java_client.android.AndroidDriver;
public class Appview {
private String code;
private String resourceid;
private String classname;
private String textname;
private String content;
private String apkname;
private String bundleid;
private String devicename;
private String platformversion;
private Integer num;
private Integer during;
private Integer spacing;
private AndroidDriver<WebElement> driver;
private Integer id;
private String home;
private String name;
private String url;
private String text;
private String strdirpath;
private String parentresourceid;
private String sonresourceid;
}
自己生成get set吧
Controller层
package com.ssm.controller;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import com.ssm.common.ExcelUtils;
import com.ssm.pojo.Appview;
import com.ssm.service.AppiumAutoTextService;
@Controller
@RequestMapping("/appAutoText")
public class AppiumAutoTextController {
@Autowired
private AppiumAutoTextService appiumAutoTextService;
/**
* 解析Excel文件
*
* @param inpStartfile
* @param request
* @return
*/
@RequestMapping("/appAutoTextFileAnalysis")
@ResponseBody
public String appAutoTextFileAnalysis(MultipartFile inpStartfile, HttpServletRequest request) {
// 获取Web项目的全路径
String strDirPath = request.getSession().getServletContext().getRealPath("/");
List<Object> excelForList = ExcelUtils.ExcelForList(inpStartfile, Appview.class, true);
return appiumAutoTextService.appAutoTextFileAnalysis(excelForList, strDirPath,inpStartfile.getOriginalFilename());
}
/**
* 解析python脚本
*
* @param PyPath
* @param request
* @return
*/
@RequestMapping("/appAutoTextPythonAnalysis")
@ResponseBody
public String appAutoTextPythonAnalysis(String PyPath, HttpServletRequest request) {
// 获取Web项目的全路径
String strDirPath = request.getSession().getServletContext().getRealPath("/");
return appiumAutoTextService.appAutoTextPythonAnalysis(PyPath, strDirPath);
}
}
serviceImpl层
package com.ssm.service.impl;
import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.WebElement;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.google.gson.Gson;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.rtf.RtfWriter2;
import com.ssm.mapper.AppiumAutoTextMapper;
import com.ssm.pojo.Appview;
import com.ssm.service.AppiumAutoTextService;
import io.appium.java_client.android.AndroidDriver;
@Service
public class AppiumAutoTextServiceImpl implements AppiumAutoTextService {
@Autowired
private AppiumAutoTextMapper appiumAutoTextMapper;
@Override
public String appAutoTextPythonAnalysis(String pyPath, String strDirPath) {
Process proc = null;
InputStreamReader stdin = null;
LineNumberReader input = null;
try {
String command = "python " + pyPath;
String[] split = pyPath.split("\\");
String fileName = split[split.length - 1];
proc = Runtime.getRuntime().exec(command); // 执行py文件
stdin = new InputStreamReader(proc.getInputStream());
input = new LineNumberReader(stdin);
String line;
Gson gson = new Gson();
List<Appview> excelForList = new ArrayList<>();
while ((line = input.readLine()) != null) {
excelForList.add(gson.fromJson(line, Appview.class));
}
if (excelForList == null || excelForList.size() == 0) {
return "1";
}
XiaoyaAppTextServiceImpl appTextService = new XiaoyaAppTextServiceImpl();
// 第一行加载驱动
Appview app = (Appview) excelForList.get(0);
if (driver == null) {
return "1";
}
for (int i = 1; i < excelForList.size(); i++) {
Appview appv = (Appview) excelForList.get(i);
// 按文件中的code查询数据库
Appview appview = appiumAutoTextMapper.getAppviewByCode(appv.getCode());
// 把参数加入对象
appview.setDriver(driver);
appview.setStrdirpath(strDirPath);
if (appv.getClassname() != null && !"".equals(appv.getClassname())) {
appview.setClassname(appv.getClassname());
}
if (appv.getResourceid() != null && !"".equals(appv.getResourceid())) {
appview.setResourceid(appv.getResourceid());
}
if (appv.getTextname() != null && !"".equals(appv.getTextname())) {
appview.setTextname(appv.getTextname());
}
if (appv.getContent() != null && !"".equals(appv.getContent())) {
if (appv.getContent().contains("#")) {
appview.setContent(appv.getContent().replace("#", ""));
} else
appview.setContent(appv.getContent());
}
if (appv.getApkname() != null && !"".equals(appv.getApkname())) {
appview.setApkname(appv.getApkname());
}
if (appv.getDevicename() != null && !"".equals(appv.getDevicename())) {
appview.setDevicename(appv.getDevicename());
}
if (appv.getBundleid() != null && !"".equals(appv.getBundleid())) {
appview.setBundleid(appv.getBundleid());
}
if (appv.getDuring() != null && appv.getDuring() > 0) {
appview.setDuring(appv.getDuring());
}
if (appv.getNum() != null && appv.getNum() > 0) {
appview.setNum(appv.getNum());
}
if (appv.getSpacing() != null && appv.getSpacing() > 0) {
appview.setSpacing(appv.getSpacing());
}
System.out.println("getCode=== " + appview.getCode());
// 开始调用方法
String imgPath = methodInvocation(appTextService, appview);
}
return "0";
} catch (Exception e) {
e.printStackTrace();
return "1";
} finally {
try {
if (proc != null) {
proc.destroy();
}
if (input != null) {
input.close();
}
if (stdin != null) {
stdin.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public String appAutoTextFileAnalysis(List<Object> excelForList, String strDirPath, String fileName) {
if (excelForList.size() == 0 || excelForList == null) {
return "1";
}
try {
XiaoyaAppTextServiceImpl appTextService = new XiaoyaAppTextServiceImpl();
// 第一行加载驱动
Appview app = (Appview) excelForList.get(0);
if (driver == null) {
return "1";
}
for (int i = 1; i < excelForList.size(); i++) {
Appview appv = (Appview) excelForList.get(i);
// 按文件中的code查询数据库
Appview appview = appiumAutoTextMapper.getAppviewByCode(appv.getCode());
// 把参数加入对象
appview.setDriver(driver);
appview.setStrdirpath(strDirPath);
if (appv.getClassname() != null && !"".equals(appv.getClassname())) {
appview.setClassname(appv.getClassname());
}
if (appv.getResourceid() != null && !"".equals(appv.getResourceid())) {
appview.setResourceid(appv.getResourceid());
}
if (appv.getTextname() != null && !"".equals(appv.getTextname())) {
appview.setTextname(appv.getTextname());
}
if (appv.getContent() != null && !"".equals(appv.getContent())) {
if (appv.getContent().contains("#")) {
appview.setContent(appv.getContent().replace("#", ""));
} else
appview.setContent(appv.getContent());
}
if (appv.getApkname() != null && !"".equals(appv.getApkname())) {
appview.setApkname(appv.getApkname());
}
if (appv.getDevicename() != null && !"".equals(appv.getDevicename())) {
appview.setDevicename(appv.getDevicename());
}
if (appv.getBundleid() != null && !"".equals(appv.getBundleid())) {
appview.setBundleid(appv.getBundleid());
}
if (appv.getDuring() != null && appv.getDuring() > 0) {
appview.setDuring(appv.getDuring());
}
if (appv.getNum() != null && appv.getNum() > 0) {
appview.setNum(appv.getNum());
}
if (appv.getSpacing() != null && appv.getSpacing() > 0) {
appview.setSpacing(appv.getSpacing());
}
System.out.println("getCode=== " + appview.getCode());
// 开始调用方法
String imgPath = methodInvocation(appTextService, appview);
}
return "0";
} catch (Exception e) {
e.printStackTrace();
return "1";
}
}
/**
* 用id判断跳转方法
*
* @param appTextService
* @param appview
*/
private String methodInvocation(XiaoyaAppTextServiceImpl appTextService, Appview appview) {
String path = "";
switch (appview.getId()) {
case 4:
appTextService.appInstall(appview);
break;
case 5:
appTextService.removeApp(appview);
break;
case 6:
appTextService.swipeToUp(appview);
break;
case 7:
appTextService.swipeToDown(appview);
break;
case 8:
appTextService.swipeToLeft(appview);
break;
case 9:
appTextService.swipeToRight(appview);
break;
case 10:
appTextService.lockDevice(appview);
break;
case 11:
path = appTextService.takeScreenShot(appview);
break;
case 12:
appTextService.launchApp(appview);
break;
case 13:
appTextService.closeApp(appview);
break;
case 14:
appTextService.back(appview);
break;
case 15:
appTextService.forward(appview);
break;
case 16:
appTextService.homeLoginButtonClick(appview);
break;
case 17:
appTextService.homeBtnRegisterClick(appview);
break;
case 18:
appTextService.impowerBtnSsoAuthorizeClick(appview);
break;
case 19:
appTextService.greetViewGuide1Click(appview);
break;
case 20:
appTextService.greetViewGuide2Click(appview);
break;
case 21:
appTextService.navigationTvSessionClick(appview);
break;
case 22:
appTextService.navigationTvContentClick(appview);
break;
case 23:
appTextService.navigationTvSkillClick(appview);
break;
case 24:
appTextService.navigationTvMeClick(appview);
break;
case 25:
appTextService.getMessageByNewestQuery(appview);
break;
case 26:
appTextService.messageNewestQueryClick(appview);
break;
case 27:
appTextService.getMessageByNewestOtherWeatherDate(appview);
break;
case 28:
appTextService.getMessageByNewestOtherWeatherWendu(appview);
break;
case 29:
appTextService.getMessageByNewestOtherWeatherAir(appview);
break;
case 30:
appTextService.getMessageByNewestTodayWeatherWenduMinMax(appview);
break;
case 31:
appTextService.getMessageByNewestTodayWeatherWenduCur(appview);
break;
case 32:
appTextService.getMessageByNewestTodayWeatherWenduAir(appview);
break;
case 33:
appTextService.getMessageByNewestTodayWeatherAirPm(appview);
break;
case 34:
appTextService.getMessageByNewestTodayWeatherAirStatus(appview);
break;
case 35:
appTextService.getMessageByNewestClockTime(appview);
break;
case 36:
appTextService.getMessageByNewestClockDate(appview);
break;
case 37:
appTextService.getMessageByNewestPayTitle(appview);
break;
case 38:
appTextService.getMessageByNewestPayCount(appview);
break;
case 39:
appTextService.getMessageByNewestPayMoney(appview);
break;
case 40:
appTextService.messageNewestPayNowBtnClick(appview);
break;
case 41:
appTextService.getMessageByNewestTTS(appview);
break;
case 42:
appTextService.getMessageByNewestVoiceTitle(appview);
break;
case 43:
appTextService.getMessageByNewestVoiceDesc(appview);
break;
case 44:
appTextService.messageTvRightClick(appview);
break;
case 45:
appTextService.skillAICommandClick(appview);
break;
case 46:
appTextService.skillAICommandAddClick(appview);
break;
case 47:
appTextService.skillAICommandShowClick(appview);
break;
case 48:
appTextService.skillAICommandSettingWordSendKeys(appview);
break;
case 49:
appTextService.skillAICommandNextStepClick(appview);
break;
case 50:
appTextService.skillAICommandLayoutXiaoyaSayClick(appview);
break;
case 51:
appTextService.skillAICommandLayoutPlayMusicClick(appview);
break;
case 52:
appTextService.skillAICommandLayoutPlayProgramClick(appview);
break;
case 53:
appTextService.skillAICommandLayoutPlayRadioClick(appview);
break;
case 54:
appTextService.skillAICommandXiaoyaSayWordSendKeys(appview);
break;
case 55:
appTextService.skillAICommandGenerateClick(appview);
break;
case 56:
appTextService.skillAICommandAccomplishClick(appview);
break;
case 57:
appTextService.meTvRightClick(appview);
break;
case 58:
appTextService.meViewAddDeviceClick(appview);
break;
case 59:
appTextService.meViewVoxSettingClick(appview);
break;
case 60:
appTextService.meViewAccountsFavoritesClick(appview);
break;
case 61:
appTextService.meViewAccountsAlarmClick(appview);
break;
case 62:
appTextService.meViewAccountsEquipmentClick(appview);
break;
case 63:
appTextService.meViewAccountsHelpClick(appview);
break;
case 64:
appTextService.meViewFeedbackClick(appview);
break;
case 65:
appTextService.meViewContactUsClick(appview);
break;
case 66:
appTextService.meViewLogoutClick(appview);
break;
case 67:
appTextService.meCollectTabTitleMusic(appview);
break;
case 68:
appTextService.meCollectTabTitleProgram(appview);
break;
case 69:
appTextService.meCollectTabTitleChants(appview);
break;
case 70:
appTextService.meCollectTabTitleChantsAction(appview);
break;
case 71:
appTextService.meCollectTabTitleChantsChoice(appview);
break;
case 72:
appTextService.meCollectTabTitleChantsChoose(appview);
break;
case 73:
appTextService.meCollectTabTitleChantsRemove(appview);
break;
case 74:
appTextService.meAlarmTvRightClick(appview);
break;
case 75:
appTextService.meAlarmBtnAddClick(appview);
break;
case 76:
appTextService.meAlarmSeetingRingClick(appview);
break;
case 77:
appTextService.meAlarmTypeLayoutClick(appview);
break;
case 78:
appTextService.meAlarmTextSaveClick(appview);
break;
case 79:
appTextService.meAlarmRingBroadcastingClick(appview);
break;
case 80:
appTextService.meAlarmRingScripturesClick(appview);
break;
case 81:
appTextService.meAlarmRepetitionSundayClick(appview);
break;
case 82:
appTextService.meAlarmRepetitionMondayClick(appview);
break;
case 83:
appTextService.meAlarmRepetitionTuesdayClick(appview);
break;
case 84:
appTextService.meAlarmRepetitionWednesdayClick(appview);
break;
case 85:
appTextService.meAlarmRepetitionThursdayClick(appview);
break;
case 86:
appTextService.meAlarmRepetitionFridayClick(appview);
break;
case 87:
appTextService.meAlarmRepetitionSaturdayClick(appview);
break;
case 88:
appTextService.meAlarmRingTextSavesClick(appview);
break;
case 89:
appTextService.meAlarmRepetitionTimeOkbuttonClick(appview);
break;
case 90:
appTextService.meAlarmRepetitionCancelButtonClick(appview);
break;
case 91:
appTextService.meAlarmChoiceClick(appview);
break;
case 92:
appTextService.meHelpStartClick(appview);
break;
case 93:
appTextService.meHelpDeviceIntroClick(appview);
break;
case 94:
appTextService.meHelpTvWifiClick(appview);
break;
case 95:
appTextService.meHelpTvNlpClick(appview);
break;
case 96:
appTextService.meHelpAwakenHelpClick(appview);
break;
case 97:
appTextService.meHelpBlueHelpClick(appview);
break;
case 98:
appTextService.meHelpCallLayoutClick(appview);
break;
case 99:
appTextService.meSpitslotTvRightClick(appview);
break;
case 100:
appTextService.meSpitslotProblemSendKeys(appview);
break;
case 101:
appTextService.meSpitslotConnectionSendKeys(appview);
break;
case 102:
appTextService.meSpitslotDrunkClick(appview);
break;
case 103:
appTextService.meSpitslotMissWakeUpClick(appview);
break;
case 104:
appTextService.meSpitslotDiscernErrorClick(appview);
break;
case 105:
appTextService.meSpitslotNetworkNoGoodClick(appview);
break;
case 106:
appTextService.meSpitslotBluetoothNotEvenClick(appview);
break;
case 107:
appTextService.meSpitslotTvSubmitClick(appview);
break;
case 108:
appTextService.meSpitslotTvSubmitAscertainClick(appview);
break;
case 109:
appTextService.meContactViewWeiboClick(appview);
break;
case 110:
appTextService.meContactViewTelClick(appview);
break;
case 111:
appTextService.meContactQcodeSubTitleClick(appview);
break;
case 112:
appTextService.meContactIvQcodeClick(appview);
break;
case 113:
appTextService.meContactBtnSaveClick(appview);
break;
case 114:
appTextService.meContactSwitchoverOfficialClick(appview);
break;
case 115:
appTextService.meContactSwitchoverProbationClick(appview);
break;
case 116:
appTextService.meViewLogoutCancelClick(appview);
break;
case 117:
appTextService.meViewLogoutExitClick(appview);
break;
case 118:
appTextService.PhysicalButtonsCALL(appview);
break;
case 119:
appTextService.PhysicalButtonsENDCALL(appview);
break;
case 120:
appTextService.PhysicalButtonsHome(appview);
break;
case 121:
appTextService.PhysicalButtonsMENU(appview);
break;
case 122:
appTextService.PhysicalButtonsBACK(appview);
break;
case 123:
appTextService.PhysicalButtonsPOWER(appview);
break;
case 124:
appTextService.PhysicalButtonsVOLUMEUP(appview);
break;
case 125:
appTextService.PhysicalButtonsVOLUMEDOWN(appview);
break;
case 126:
appTextService.findElementByXPathClick(appview);
break;
case 127:
appTextService.findElementsByXPathClick(appview);
break;
case 128:
appTextService.findElementByIdClick(appview);
break;
case 129:
appTextService.findElementByIdSendKeys(appview);
break;
case 130:
appTextService.findElementsByIdClick(appview);
break;
case 131:
appTextService.findElementsByIdSendKeys(appview);
break;
case 132:
appTextService.findElementByClassNameClick(appview);
break;
case 133:
appTextService.findElementByClassNameSendKeys(appview);
break;
case 134:
appTextService.findElementsByClassNameClick(appview);
break;
case 135:
appTextService.findElementsByClassNameSendKeys(appview);
break;
case 136:
appTextService.messageNewestAlarmSettingClick(appview);
break;
case 137:
appTextService.meCollectTabTitleChantsCancel(appview);
break;
case 138:
appTextService.meSmartHomeBtRetry(appview);
break;
case 139:
appTextService.threadSleep(appview);
break;
}
return path;
}
}
具体方法的封装
package com.ssm.service.impl;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.stereotype.Service;
import com.ssm.pojo.Appview;
import com.ssm.service.XiaoyaAppTextService;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidKeyCode;
@Service
public class XiaoyaAppTextServiceImpl implements XiaoyaAppTextService {
@Override
public AndroidDriver<WebElement> setUp(Appview appview) {
AndroidDriver<WebElement> driver;
try {
String serverURL = "http://127.0.0.1:4723/wd/hub";// appium测试服务的地址
// 新建一个DesiredCapabilities对象,是importorg.openqa.selenium.remote.DesiredCapabilities;作者个人赶脚是用来收集驱动初始化信息用的;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, ""); // 指定浏览器的名字,我们测试的是APK所以没有浏览器,故而为空;
capabilities.setCapability("platformName", "Android"); // 指定平台,为安卓
capabilities.setCapability("deviceName", appview.getDevicename()); // 指定设备,"621QACQC38Z5K"这个属性作者认为是“安卓设备即可”
capabilities.setCapability("platformVersion", appview.getPlatformversion()); // 指定版本,作者的模拟器是4.4.2的
File classpathRoot = new File(appview.getStrdirpath());// 获得项目路径
File appDir = new File(classpathRoot, "apps");// 获得APK所在文件夹名称
File app = new File(appDir, appview.getApkname());// 获得APK文件
capabilities.setCapability("app", app.getAbsolutePath()); // 指定需要测试的APK,也就是需要安装的APK文件;
capabilities.setCapability("autoLaunch", "false"); // Appium是否需要自动安装和启动应用。
// support Chinese
capabilities.setCapability("unicodeKeyboard", "True");
capabilities.setCapability("resetKeyboard", "True");
// no need sign
capabilities.setCapability("noSign", "True");
// 核心关键步骤,创建驱动,指定服务地址,和初始化信息;
driver = new AndroidDriver<WebElement>(new URL(serverURL), capabilities);
return driver;
} catch (MalformedURLException e) {
e.printStackTrace();
return null;
}
}
@Override
public void appInstall(Appview appview) {
// apkName = "小雅APP_v1.4.8.apk"; // 安卓的安装包,被测软件
// bundleId = "com.orion.xiaoya.speakerclient";// 对应app的应用包
if (appview.getDriver().isAppInstalled(appview.getBundleid())) {
// 从设备中删除一个应用
appview.getDriver().removeApp(appview.getBundleid());
}
// java 安装应用到设备中去
appview.getDriver().installApp(
new File(appview.getStrdirpath(), File.separator + "apps" + File.separator + appview.getApkname())
.getAbsolutePath());
}
@Override
public void removeApp(Appview appview) {
if (appview.getDriver().isAppInstalled(appview.getBundleid())) {
// 从设备中删除一个应用
appview.getDriver().removeApp(appview.getBundleid());
}
}
@Override
public void launchApp(Appview appview) {
appview.getDriver().launchApp();
}
@Override
public void closeApp(Appview appview) {
appview.getDriver().closeApp();
}
@Override
public void forward(Appview appview) {
appview.getDriver().navigate().forward();
}
@Override
public void back(Appview appview) {
appview.getDriver().navigate().back();
}
@Override
public void swipeToUp(Appview appview) {
int width = appview.getDriver().manage().window().getSize().width;
int height = appview.getDriver().manage().window().getSize().height;
for (int i = 0; i < appview.getNum(); i++) {
appview.getDriver().swipe(width / 2, height * 3 / 4, width / 2, height / 4, appview.getDuring());
}
try {
Thread.sleep(appview.getSpacing() * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void swipeToDown(Appview appview) {
int width = appview.getDriver().manage().window().getSize().width;
int height = appview.getDriver().manage().window().getSize().height;
// System.out.println(width);
// System.out.println(height);
for (int i = 0; i < appview.getNum(); i++) {
appview.getDriver().swipe(width / 2, height / 4, width / 2, height * 3 / 4, appview.getDuring());
}
try {
Thread.sleep(appview.getSpacing() * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void swipeToLeft(Appview appview) {
// System.out.println(during);
int width = appview.getDriver().manage().window().getSize().width;
int height = appview.getDriver().manage().window().getSize().height;
for (int i = 0; i < appview.getNum(); i++) {
appview.getDriver().swipe(width * 3 / 4, height / 2, width / 4, height / 2, appview.getDuring());
}
try {
Thread.sleep(appview.getSpacing() * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void swipeToRight(Appview appview) {
int width = appview.getDriver().manage().window().getSize().width;
int height = appview.getDriver().manage().window().getSize().height;
for (int i = 0; i < appview.getNum(); i++) {
appview.getDriver().swipe(width / 4, height / 2, width * 3 / 4, height / 2, appview.getDuring());
}
try {
Thread.sleep(appview.getSpacing() * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void lockDevice(Appview appview) {
appview.getDriver().lockDevice();
}
// @Override
// public void pressKeyCode(Appview appview) {
// appview.getDriver().pressKeyCode(Integer.parseInt(appview.getKey()));
// }
@Override
public String takeScreenShot(Appview appview) {
String path = "C:\\eclipse-oriontest\\TestProject" + File.separator
+ new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date()) + ".jpg";
try {
// 获取screenshot文件
File screenShot = appview.getDriver().getScreenshotAs(OutputType.FILE);
// 文件copy到指定的文件夹
FileUtils.copyFile(screenShot, new File(path));
} catch (WebDriverException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return path;
}
@Override
public void homeLoginButtonClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void homeBtnRegisterClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void impowerBtnSsoAuthorizeClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void greetViewGuide1Click(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void greetViewGuide2Click(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void navigationTvContentClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void navigationTvMeClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void navigationTvSessionClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void navigationTvSkillClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public String getMessageByNewestQuery(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public void messageNewestQueryClick(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getResourceid());
findElements.get(findElements.size() - 1).click();
}
@Override
public String getMessageByNewestOtherWeatherAir(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestOtherWeatherDate(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestOtherWeatherWendu(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestTodayWeatherWenduAir(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestTodayWeatherWenduCur(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestTodayWeatherWenduMinMax(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestTodayWeatherAirPm(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
WebElement findElement = findElements.get(findElements.size() - 1)
.findElement(By.id(appview.getSonresourceid()));
return findElement.findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestTodayWeatherAirStatus(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
WebElement findElement = findElements.get(findElements.size() - 1)
.findElement(By.id(appview.getSonresourceid()));
return findElement.findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestClockDate(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public void messageNewestAlarmSettingClick(Appview appview) {
appview.getDriver().findElementsById(appview.getResourceid()).get(appview.getNum()).click();
}
@Override
public String getMessageByNewestClockTime(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestPayCount(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestPayMoney(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public String getMessageByNewestPayTitle(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getParentresourceid());
return findElements.get(findElements.size() - 1).findElement(By.id(appview.getResourceid())).getText();
}
@Override
public void messageNewestPayNowBtnClick(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getResourceid());
findElements.get(findElements.size() - 1).click();
}
@Override
public String getMessageByNewestTTS(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getResourceid());
return findElements.get(findElements.size() - 1).getText();
}
@Override
public String getMessageByNewestVoiceDesc(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getResourceid());
return findElements.get(findElements.size() - 1).getText();
}
@Override
public String getMessageByNewestVoiceTitle(Appview appview) {
List<WebElement> findElements = (List<WebElement>) appview.getDriver()
.findElementsById(appview.getResourceid());
return findElements.get(findElements.size() - 1).getText();
}
@Override
public void messageTvRightClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void skillAICommandClick(Appview appview) {
List<WebElement> findElementsByClassName = (List<WebElement>) appview.getDriver()
.findElementsByClassName(appview.getClassname());
findElementsByClassName.get(1).click();
}
@Override
public void skillAICommandAddClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void skillAICommandShowClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void skillAICommandSettingWordSendKeys(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).sendKeys(appview.getContent());
}
@Override
public void skillAICommandLayoutPlayMusicClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void skillAICommandLayoutPlayProgramClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void skillAICommandLayoutPlayRadioClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void skillAICommandNextStepClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void skillAICommandLayoutXiaoyaSayClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void skillAICommandXiaoyaSayWordSendKeys(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).sendKeys(appview.getContent());
}
@Override
public void skillAICommandGenerateClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void skillAICommandAccomplishClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meTvRightClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewAccountsAlarmClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewAccountsEquipmentClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewAccountsFavoritesClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewAccountsHelpClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewAddDeviceClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewContactUsClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewFeedbackClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewLogoutClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meViewVoxSettingClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meCollectTabTitleChants(Appview appview) {
appview.getDriver().findElementById(appview.getParentresourceid())
.findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meCollectTabTitleMusic(Appview appview) {
appview.getDriver().findElementById(appview.getParentresourceid())
.findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meCollectTabTitleProgram(Appview appview) {
appview.getDriver().findElementById(appview.getParentresourceid())
.findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meCollectTabTitleChantsAction(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meCollectTabTitleChantsChoice(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meCollectTabTitleChantsCancel(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meCollectTabTitleChantsChoose(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meCollectTabTitleChantsRemove(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmBtnAddClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meAlarmSeetingRingClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meAlarmTextSaveClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meAlarmTvRightClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meAlarmTypeLayoutClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meAlarmRingBroadcastingClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRingScripturesClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRingTextSavesClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meAlarmRepetitionFridayClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRepetitionMondayClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRepetitionSaturdayClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRepetitionSundayClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRepetitionThursdayClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRepetitionTuesdayClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRepetitionWednesdayClick(Appview appview) {
appview.getDriver().findElement(By.xpath("//*[contains(@text,'" + appview.getTextname() + "')]")).click();
}
@Override
public void meAlarmRepetitionCancelButtonClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meAlarmRepetitionTimeOkbuttonClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meAlarmChoiceClick(Appview appview) {
appview.getDriver().findElementsById(appview.getResourceid()).get(appview.getNum()).click();
}
@Override
public void meSmartHomeBtRetry(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meHelpAwakenHelpClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meHelpBlueHelpClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meHelpCallLayoutClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meHelpDeviceIntroClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meHelpStartClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meHelpTvNlpClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meHelpTvWifiClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meSpitslotTvRightClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meSpitslotConnectionSendKeys(Appview appview) {
appview.getDriver().findElementsByClassName(appview.getClassname()).get(1).sendKeys(appview.getContent());
}
@Override
public void meSpitslotProblemSendKeys(Appview appview) {
appview.getDriver().findElementsByClassName(appview.getClassname()).get(0).sendKeys(appview.getContent());
}
@Override
public void meSpitslotBluetoothNotEvenClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meSpitslotDiscernErrorClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meSpitslotDrunkClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meSpitslotMissWakeUpClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meSpitslotNetworkNoGoodClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meSpitslotTvSubmitClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meSpitslotTvSubmitAscertainClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meContactBtnSaveClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meContactIvQcodeClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
// @Override
// public void meContactLogoClick(Appview appview) {
// WebElement findElementById =
// appview.getDriver().findElementById(appview.getResourceid());
// for (int i = 0; i < 10; i++) {
// findElementById.click();
// }
// }
@Override
public void meContactQcodeSubTitleClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meContactViewTelClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meContactViewWeiboClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void meContactSwitchoverOfficialClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meContactSwitchoverProbationClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meViewLogoutCancelClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void meViewLogoutExitClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void PhysicalButtonsCALL(Appview appview) {
appview.getDriver().pressKeyCode(AndroidKeyCode.KEYCODE_CALL);
}
@Override
public void PhysicalButtonsBACK(Appview appview) {
appview.getDriver().pressKeyCode(AndroidKeyCode.KEYCODE_BACK);
}
@Override
public void PhysicalButtonsENDCALL(Appview appview) {
appview.getDriver().pressKeyCode(AndroidKeyCode.KEYCODE_ENDCALL);
}
@Override
public void PhysicalButtonsHome(Appview appview) {
appview.getDriver().pressKeyCode(AndroidKeyCode.KEYCODE_HOME);
}
@Override
public void PhysicalButtonsMENU(Appview appview) {
appview.getDriver().pressKeyCode(AndroidKeyCode.KEYCODE_MENU);
}
@Override
public void PhysicalButtonsPOWER(Appview appview) {
appview.getDriver().pressKeyCode(AndroidKeyCode.KEYCODE_POWER);
}
@Override
public void PhysicalButtonsVOLUMEDOWN(Appview appview) {
appview.getDriver().pressKeyCode(AndroidKeyCode.KEYCODE_VOLUME_DOWN);
}
@Override
public void PhysicalButtonsVOLUMEUP(Appview appview) {
appview.getDriver().pressKeyCode(AndroidKeyCode.KEYCODE_VOLUME_UP);
}
@Override
public void findElementByXPathClick(Appview appview) {
appview.getDriver().findElementByXPath("//*[contains(@text,'" + appview.getTextname() + "')]").click();
}
@Override
public void findElementsByXPathClick(Appview appview) {
appview.getDriver().findElementsByXPath("//*[contains(@text,'" + appview.getTextname() + "')]")
.get(appview.getNum()).click();
}
@Override
public void findElementByIdClick(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).click();
}
@Override
public void findElementByIdSendKeys(Appview appview) {
appview.getDriver().findElementById(appview.getResourceid()).sendKeys(appview.getContent());
}
@Override
public void findElementsByIdClick(Appview appview) {
appview.getDriver().findElementsById(appview.getResourceid()).get(appview.getNum()).click();
}
@Override
public void findElementsByIdSendKeys(Appview appview) {
appview.getDriver().findElementsById(appview.getResourceid()).get(appview.getNum())
.sendKeys(appview.getContent());
}
@Override
public void findElementByClassNameClick(Appview appview) {
appview.getDriver().findElementByClassName(appview.getResourceid()).click();
}
@Override
public void findElementByClassNameSendKeys(Appview appview) {
appview.getDriver().findElementByClassName(appview.getResourceid()).sendKeys(appview.getContent());
}
@Override
public void findElementsByClassNameClick(Appview appview) {
appview.getDriver().findElementsByClassName(appview.getResourceid()).get(appview.getNum()).click();
}
@Override
public void findElementsByClassNameSendKeys(Appview appview) {
appview.getDriver().findElementsByClassName(appview.getResourceid()).get(appview.getNum())
.sendKeys(appview.getContent());
}
@Override
public void threadSleep(Appview appview) {
try {
Thread.sleep(appview.getSpacing() * 1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
方法封装的比较死,只是一个思路,自己看着改吧。。
Excel的格式
使用adb shell dumpsys window | findstr mCurrentFocus 命令查看当前运行的包名和Activity