|
@@ -0,0 +1,906 @@
|
|
|
+package net.mooctest.www.android_auto_test.Scripts;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.sinaapp.msdxblog.apkUtil.entity.ApkInfo;
|
|
|
+import io.appium.java_client.TouchAction;
|
|
|
+import io.appium.java_client.android.AndroidDriver;
|
|
|
+import io.appium.java_client.android.AndroidTouchAction;
|
|
|
+import io.appium.java_client.android.nativekey.AndroidKey;
|
|
|
+import io.appium.java_client.android.nativekey.KeyEvent;
|
|
|
+import io.appium.java_client.touch.TapOptions;
|
|
|
+import io.appium.java_client.touch.WaitOptions;
|
|
|
+import io.appium.java_client.touch.offset.PointOption;
|
|
|
+import net.mooctest.www.android_auto_test.common.constant.Consts;
|
|
|
+import net.mooctest.www.android_auto_test.models.Action;
|
|
|
+import net.mooctest.www.android_auto_test.models.Activity;
|
|
|
+import net.mooctest.www.android_auto_test.models.Component;
|
|
|
+import net.mooctest.www.android_auto_test.models.IgnoreComponent;
|
|
|
+import net.mooctest.www.android_auto_test.utils.*;
|
|
|
+import org.apache.commons.io.FileUtils;
|
|
|
+import org.openqa.selenium.*;
|
|
|
+
|
|
|
+import java.io.*;
|
|
|
+import java.time.Duration;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import static java.nio.charset.StandardCharsets.*;
|
|
|
+
|
|
|
+
|
|
|
+ * @author henrylee
|
|
|
+ */
|
|
|
+public class DefaultScript extends AbstractBaseScript {
|
|
|
+
|
|
|
+ public static final String TAG = Thread.currentThread() .getStackTrace()[1].getClassName();
|
|
|
+
|
|
|
+ private String udid;
|
|
|
+ private AndroidDriver driver;
|
|
|
+ private ApkInfo apkInfo;
|
|
|
+ private String traceId;
|
|
|
+
|
|
|
+ private BufferedWriter scriptWriter;
|
|
|
+ private BufferedWriter myTestLogWriter;
|
|
|
+ private BufferedWriter actionWriter;
|
|
|
+ private List<Activity> activityList = new ArrayList<>();
|
|
|
+
|
|
|
+ private List<String> fatherComponentList = new ArrayList<>();
|
|
|
+ private HashMap<String, IgnoreComponent> ignoreMap;
|
|
|
+
|
|
|
+ private boolean hasTakenScreenshot = false;
|
|
|
+
|
|
|
+ public DefaultScript(String udid, AndroidDriver driver, ApkInfo apkInfo, String traceId) {
|
|
|
+ this.traceId = traceId;
|
|
|
+ this.udid = udid;
|
|
|
+ this.driver = driver;
|
|
|
+ this.apkInfo = apkInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initWriter(File testScript, File testAction, File myTestLog){
|
|
|
+ try {
|
|
|
+ scriptWriter = new BufferedWriter(new FileWriter(testScript,true));
|
|
|
+ myTestLogWriter = new BufferedWriter(new FileWriter(myTestLog,true));
|
|
|
+ actionWriter = new BufferedWriter(new FileWriter(testAction, true));
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void prepare(){
|
|
|
+ File myTestLog = new File(AddressUtil.getMyTestLogPath(traceId, udid));
|
|
|
+ File testScript = new File(AddressUtil.getTestScript(traceId, udid));
|
|
|
+ File testAction = new File(AddressUtil.getTestAction(traceId, udid));
|
|
|
+ FileUtil.newFiles(Arrays.asList(myTestLog, testAction, testScript));
|
|
|
+ initWriter(testScript, testAction, myTestLog);
|
|
|
+ File pageXmlDir = new File(AddressUtil.getPageXmlDir(traceId, udid));
|
|
|
+ File pageSourceDir = new File(AddressUtil.getPageSourceDir(traceId, udid));
|
|
|
+ File pageImgDir = new File(AddressUtil.getPageImgDir(traceId, udid));
|
|
|
+ FileUtil.newDirs(Arrays.asList(pageXmlDir, pageImgDir, pageSourceDir));
|
|
|
+ loadConfiguration();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void run(){
|
|
|
+ PrintUtil.print("Mock run!", TAG, udid);
|
|
|
+ String rootActivity = "root";
|
|
|
+ DFS(rootActivity, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 深度优先遍历APP
|
|
|
+ * @param depth 遍历深度
|
|
|
+ */
|
|
|
+ private void DFS(String fatherActivity, int depth){
|
|
|
+ if (this.stopFlag){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ handleAndroidAlertOnLaunch();
|
|
|
+ threadSleep(2);
|
|
|
+ List<Component> componentList = getCurrentClickableComList(depth, true);
|
|
|
+ if (componentList.size() == 0){
|
|
|
+ handleNoClickableComWhenFirstLaunch(componentList, depth);
|
|
|
+ }
|
|
|
+
|
|
|
+ componentList = getCurrentClickableComList(depth, false);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ boolean isOutOfAppPackage = isOutOfAppPackage(componentList, depth);
|
|
|
+ if (isOutOfAppPackage){
|
|
|
+ PrintUtil.print("Have tried 2 times, still not in appPackage", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ PrintUtil.print("Change isEnd to true", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ this.endScript();
|
|
|
+ return;
|
|
|
+ } else if (driver.currentActivity().equals(fatherActivity)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String currentActivityName = driver.currentActivity();
|
|
|
+ int currentHash = driver.getPageSource().hashCode();
|
|
|
+ int index = activityIndexOfActivityList(currentActivityName);
|
|
|
+ if (index < 0){
|
|
|
+
|
|
|
+ threadSleep(2);
|
|
|
+ takeScreenShotAndSavePageImg();
|
|
|
+ savePageXml();
|
|
|
+ Activity currentActivity = new Activity(currentActivityName, fatherActivity, currentHash, componentList);
|
|
|
+ activityList.add(currentActivity);
|
|
|
+ index = activityList.size() - 1;
|
|
|
+ }else {
|
|
|
+
|
|
|
+ Activity activity = activityList.get(index);
|
|
|
+ String oldFather = activity.getFatherActivity();
|
|
|
+ if (!oldFather.equals(fatherActivity)){
|
|
|
+ String msg = String.format("Previous Activity is %s, but %s's father is %s, change father.", fatherActivity, currentActivityName, oldFather);
|
|
|
+ PrintUtil.print(msg, TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ activity.setFatherActivity(fatherActivity);
|
|
|
+ }
|
|
|
+ int oldHash = activity.getHash();
|
|
|
+ if (oldHash != currentHash){
|
|
|
+ activity.setHash(currentHash);
|
|
|
+ List<Component> oldComponent = activity.getComList();
|
|
|
+ componentList = setTestedComInList(oldComponent, componentList);
|
|
|
+ activity.setComList(componentList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Activity activity4Test = activityList.get(index);
|
|
|
+ if (activity4Test.isDone()){
|
|
|
+ PrintUtil.print("Going to return because this page is over", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ returnPrevActivity();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int comIndex=0;comIndex<componentList.size();++comIndex){
|
|
|
+ if (this.stopFlag){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ PrintUtil.print(String.format("%s's index is %s/%s.", currentActivityName, comIndex, componentList.size()), TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ Component component = componentList.get(comIndex);
|
|
|
+
|
|
|
+ if(judgeTestedComponent(component) || judgeIgnoreComponent(component)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (component.getFatherComponent() != null){
|
|
|
+ executeClickFatherComponent(component.getFatherComponent());
|
|
|
+ }
|
|
|
+ String locator = component.getLocator();
|
|
|
+ if (locator == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ WebElement elementForTest = null;
|
|
|
+ PrintUtil.print("Try to locate " + locator, TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ try {
|
|
|
+ if(locator.startsWith("//")) {
|
|
|
+ elementForTest = driver.findElementByXPath(locator);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ elementForTest = driver.findElementById(locator);
|
|
|
+ }
|
|
|
+ }catch(Exception exception){
|
|
|
+
|
|
|
+ PrintUtil.print("Can't locate component " + component.getLocator(), TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ handleAndroidAlert();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ component.setHasBeenTested(true);
|
|
|
+ if (judgeFatherComponent(component, currentActivityName)){
|
|
|
+ executeClick(component, elementForTest);
|
|
|
+ List<Component> comListAfterClickFatherCom = getCurrentClickableComList(depth, true);
|
|
|
+ for(int i = 0;i < comListAfterClickFatherCom.size();i++){
|
|
|
+ if(!componentList.contains(comListAfterClickFatherCom.get(i))){
|
|
|
+ comListAfterClickFatherCom.get(i).setFatherComponent(component);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ componentList = setTestedComInList(componentList, comListAfterClickFatherCom);
|
|
|
+ PrintUtil.print("After set father component", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ printComponentList(componentList);
|
|
|
+ executeKeyEvent("Click Return button because handled father components", AndroidKey.BACK);
|
|
|
+ comIndex = -1;
|
|
|
+ activityList.get(index).setComList(componentList);
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String fatherOfCurrentActivity = activity4Test.getFatherActivity();
|
|
|
+ if (component.getClassname().contains("EditText")){
|
|
|
+ executeInput(component, elementForTest);
|
|
|
+ }else {
|
|
|
+
|
|
|
+ executeClick(component, elementForTest);
|
|
|
+ if(stopFlag) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(driver.currentActivity().equals(".ui.video.VideoPlayerActivity")){
|
|
|
+ if(!hasTakenScreenshot){
|
|
|
+ takeScreenShotAndSavePageImg();
|
|
|
+ hasTakenScreenshot = true;
|
|
|
+ }
|
|
|
+ executeKeyEvent("Click Return button cause only enter VideoPlayerActivity", AndroidKey.BACK);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ handleAndroidAlert();
|
|
|
+ headleAndroidMessage();
|
|
|
+ String activityAfterClick = driver.currentActivity();
|
|
|
+ int pageHashAfterClick = driver.getPageSource().hashCode();
|
|
|
+ if(stopFlag) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (pageHashAfterClick == currentHash){
|
|
|
+ PrintUtil.print("The page has not changed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (activityAfterClick.equals(currentActivityName)){
|
|
|
+ PrintUtil.print("The UI components have changed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ List<Component> comListAfterClick = getCurrentClickableComList(depth, true);
|
|
|
+ if (comListAfterClick.hashCode() == componentList.hashCode()){
|
|
|
+ PrintUtil.print("The component list hash code has not changed, continue to test current comList", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ } else {
|
|
|
+ componentList = setTestedComInList(componentList, comListAfterClick);
|
|
|
+
|
|
|
+ comIndex = -1;
|
|
|
+ activityList.get(index).setComList(componentList);
|
|
|
+ activityList.get(index).setHash(pageHashAfterClick);
|
|
|
+ }
|
|
|
+ printComponentList(componentList);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ PrintUtil.print("The page has changed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ PrintUtil.print("Current activity is " + activityAfterClick, TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ if(activityAfterClick.equals(fatherOfCurrentActivity)){
|
|
|
+
|
|
|
+ PrintUtil.print("I'm going to return because of my dad.\r\n", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(stopFlag) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ DFS(currentActivityName, depth+1);
|
|
|
+
|
|
|
+ if(stopFlag) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ PrintUtil.print("Has returned", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+
|
|
|
+
|
|
|
+ headleAndroidMessage();
|
|
|
+ boolean outOfAppPackageFlag = judgeOutOfAppPackage(componentList);
|
|
|
+ if(outOfAppPackageFlag) {
|
|
|
+
|
|
|
+ PrintUtil.print("Change isEnd to true because not in AppPackage", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ stopFlag = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try{
|
|
|
+ PrintUtil.print("Current activity is " + driver.currentActivity(), TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ }catch(Exception e){
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ List<Component> comListAfterReturn = getCurrentClickableComList(depth, true);
|
|
|
+ if(componentList.hashCode() != comListAfterReturn.hashCode()){
|
|
|
+
|
|
|
+ PrintUtil.print("Update the activity's component , because current comList is different with before", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ componentList = setTestedComInList(componentList, comListAfterReturn);
|
|
|
+ comIndex = -1;
|
|
|
+ activityList.get(index).setComList(comListAfterReturn);
|
|
|
+ activityList.get(index).setHash(driver.currentActivity().hashCode());
|
|
|
+ printComponentList(componentList);
|
|
|
+ }
|
|
|
+ PrintUtil.print("After return, current index is " + comIndex + "/" + componentList.size(), TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ PrintUtil.print("Going to return because this page has done.\r\n", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ activityList.get(index).setDone(true);
|
|
|
+ returnPrevActivity();
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Component> getCurrentClickableComList(int i, boolean printFlag){
|
|
|
+ String pageSource = driver.getPageSource();
|
|
|
+ String path = savePageSource(i, pageSource);
|
|
|
+ ParseXml xmlParser = new ParseXml();
|
|
|
+ List<Component> comList = xmlParser.run(path);
|
|
|
+ if (comList.size() == 0){
|
|
|
+ comList = getCurrentComList(i);
|
|
|
+ }
|
|
|
+ if(printFlag){
|
|
|
+ printComponentList(comList);
|
|
|
+ }
|
|
|
+ return comList;
|
|
|
+ }
|
|
|
+ private List<Component> getCurrentComList(int depth){
|
|
|
+ List<Component> comList = parseAndSavePageSource(depth);
|
|
|
+ printComponentList(comList);
|
|
|
+ return comList;
|
|
|
+ }
|
|
|
+ private void executeInput(Component component, WebElement element){
|
|
|
+ String inputValue = null;
|
|
|
+ PrintUtil.print("This is an editText , trying to find input value", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ InputFinder finder = new InputFinder();
|
|
|
+ try {
|
|
|
+ inputValue = finder.getInputValue(AddressUtil.getHumanScriptPath(),component.getResource_id());
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.print("Find input value error!", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if(inputValue != null){
|
|
|
+ PrintUtil.print("Input " + component.getLocator() + " use vaule " + inputValue, TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ String activityBeforeAction = driver.currentActivity();
|
|
|
+ String timeBeforeAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+
|
|
|
+ element.sendKeys(inputValue);
|
|
|
+ String timeAfterAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ String activityAfterAction = driver.currentActivity();
|
|
|
+ try {
|
|
|
+ String type = "INPUT";
|
|
|
+ String msg = "Input " + component.getLocator() + " use vaule " + inputValue;
|
|
|
+ if(!component.getLocator().contains("bounds")) {
|
|
|
+ msg = msg + ", bounds: \'" + component.getBounds() + "\'";
|
|
|
+ }
|
|
|
+ recordAction(new Action(timeBeforeAction, timeAfterAction, type, msg, activityBeforeAction, activityAfterAction));
|
|
|
+ String locator = component.getLocator();
|
|
|
+ if(locator.startsWith("//")) {
|
|
|
+ scriptWriter.write("driver.findElementByXPath(\"" + locator + "\").sendKeys(\"" + inputValue + "\");\n");
|
|
|
+ } else {
|
|
|
+ scriptWriter.write("driver.findElementById(\"" + locator + "\").sendKeys(\"" + inputValue + "\");\n");
|
|
|
+ }
|
|
|
+ scriptWriter.flush();
|
|
|
+ } catch (IOException e1) {
|
|
|
+ PrintUtil.printException(TAG, udid, e1);
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }else {PrintUtil.print("Can't find input value for this editText", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);}
|
|
|
+ }
|
|
|
+ private void executeClick(Component component, WebElement element){
|
|
|
+ String locator = component.getLocator();
|
|
|
+ PrintUtil.print("Click component " + locator, TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ String activityBeforeAction = driver.currentActivity();
|
|
|
+ String timeBeforeAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ String componentType = component.getClassname();
|
|
|
+
|
|
|
+ if (!componentType.contains("TextView")){
|
|
|
+ element.click();
|
|
|
+ } else {
|
|
|
+
|
|
|
+ Point p = element.getLocation();
|
|
|
+ int x = p.x + element.getSize().getWidth() / 2;
|
|
|
+ int y = p.y + element.getSize().getHeight() / 4;
|
|
|
+ new TouchAction<>(driver).tap(PointOption.point(x, y)).perform();
|
|
|
+ }
|
|
|
+
|
|
|
+ String timeAfterAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ threadSleep(6);
|
|
|
+ String activityAfterAction = driver.currentActivity();
|
|
|
+ try {
|
|
|
+ String type = "CLICK";
|
|
|
+ String msg = "Click widget " + locator;
|
|
|
+ if(!locator.contains("bounds")) {
|
|
|
+ msg = msg + ", bounds: \'" + component.getBounds() + "\'";
|
|
|
+ }
|
|
|
+ recordAction(new Action(timeBeforeAction, timeAfterAction, type, msg, activityBeforeAction, activityAfterAction));
|
|
|
+ if(locator.startsWith("//")) {
|
|
|
+ scriptWriter.write("driver.findElementByXPath(\"" + locator + "\").click();\n");
|
|
|
+ } else {
|
|
|
+ scriptWriter.write("driver.findElementById(\"" + locator + "\").click();\n");
|
|
|
+ }
|
|
|
+ scriptWriter.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void executeSwipe(){
|
|
|
+ int screenWidth = driver.manage().window().getSize().width;
|
|
|
+ int screenHeight = driver.manage().window().getSize().height;
|
|
|
+ int startx = screenWidth * 3 / 4;
|
|
|
+ int starty = screenHeight / 3;
|
|
|
+ int endx = screenWidth / 4;
|
|
|
+ int endy = starty;
|
|
|
+ try {
|
|
|
+ threadSleep(1);
|
|
|
+ String activityBeforeAction = driver.currentActivity();
|
|
|
+ String timeBeforeAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ AndroidTouchAction touchAction = new AndroidTouchAction(driver);
|
|
|
+ touchAction.press(PointOption.point(startx, starty))
|
|
|
+ .waitAction(WaitOptions.waitOptions(Duration.ofMillis(200)))
|
|
|
+ .moveTo(PointOption.point(endx, endy))
|
|
|
+ .release().perform();
|
|
|
+ String timeAfterAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ threadSleep(3);
|
|
|
+ String activityAfterAction = driver.currentActivity();
|
|
|
+ String type = "SWIPE";
|
|
|
+ String msg = String.format("startX: %s, startY: %s, endX: %s, endY: %s, duration: 500ms", startx, starty, endx, endy);
|
|
|
+ recordAction(new Action(timeBeforeAction, timeAfterAction, type, msg, activityBeforeAction, activityAfterAction));
|
|
|
+ String script = String.format("AndroidTouchAction touchAction = new AndroidTouchAction(driver);\n" +
|
|
|
+ " touchAction.press(PointOption.point(%s, %s))\n" +
|
|
|
+ " .waitAction(WaitOptions.waitOptions(Duration.ofMillis(%s)))\n" +
|
|
|
+ " .moveTo(PointOption.point(%s, %s))\n" +
|
|
|
+ " .release().perform();", startx, starty, endx, endy, 500);
|
|
|
+ scriptWriter.write(script);
|
|
|
+ scriptWriter.flush();
|
|
|
+ } catch (InvalidElementStateException e){
|
|
|
+ PrintUtil.print("WTF How to solve this exception!", TAG);
|
|
|
+ } catch (Exception e1) {
|
|
|
+ PrintUtil.printException(TAG, udid, e1);
|
|
|
+ e1.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void executeKeyEvent(String msg, AndroidKey androidKey){
|
|
|
+ String activityBeforeAction;
|
|
|
+ String activityAfterAction;
|
|
|
+ String timeBeforeAction;
|
|
|
+ String timeAfterAction;
|
|
|
+ try{
|
|
|
+ PrintUtil.print(msg, TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ activityBeforeAction = driver.currentActivity();
|
|
|
+ timeBeforeAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ driver.pressKey(new KeyEvent(androidKey));
|
|
|
+ timeAfterAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ threadSleep(2);
|
|
|
+ activityAfterAction = driver.currentActivity();
|
|
|
+ }catch(Exception e){
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String type = "CLICK";
|
|
|
+ recordAction(new Action(timeBeforeAction, timeAfterAction, type, msg, activityBeforeAction, activityAfterAction));
|
|
|
+ scriptWriter.write("driver.sendKeyEvent(" + androidKey.getCode() + ");\n");
|
|
|
+ scriptWriter.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void executeClickFatherComponent(Component component){
|
|
|
+ String locator = component.getLocator();
|
|
|
+ PrintUtil.print("Click father component " + locator, TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ WebElement element;
|
|
|
+ try {
|
|
|
+ if(locator.startsWith("//")) {
|
|
|
+ element = driver.findElementByXPath(locator);
|
|
|
+ } else {
|
|
|
+ element = driver.findElementById(locator);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ PrintUtil.print("Can't locate father component " + locator, TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ executeClick(component, element);
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isOutOfAppPackage(List<Component> componentList, int depth){
|
|
|
+ boolean isOutOfPackage = judgeOutOfAppPackage(componentList);
|
|
|
+ List<Component> tempComs;
|
|
|
+ int threshold = 3;
|
|
|
+ int attemptCount = 0;
|
|
|
+ while (isOutOfPackage && attemptCount < threshold){
|
|
|
+ executeKeyEvent("Click Return button because not in appPackage and ready to check again", AndroidKey.BACK);
|
|
|
+ tempComs = getCurrentClickableComList(depth, false);
|
|
|
+ isOutOfPackage = judgeOutOfAppPackage(tempComs);
|
|
|
+ attemptCount ++;
|
|
|
+ }
|
|
|
+ return isOutOfPackage;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean judgeOutOfAppPackage(List<Component> comList){
|
|
|
+ for(Component component : comList){
|
|
|
+ if(component.getPackagename().equals(apkInfo.getPackageName())) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean handleAndroidAlert(){
|
|
|
+ boolean haveAlert = false;
|
|
|
+ List<Component> components = parseAndSavePageSource(-1);
|
|
|
+ for (Component com: components){
|
|
|
+ String resourceId = com.getResource_id();
|
|
|
+ if (resourceId == null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String packageName = com.getPackagename();
|
|
|
+ boolean isComponentAlert = (resourceId.contains("alertTitle") || resourceId.contains("event_title"))
|
|
|
+ || packageName != null && (packageName.contains("packageinstaller") || packageName.contains("permissioncontroller"));
|
|
|
+ if (isComponentAlert){
|
|
|
+ haveAlert = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (haveAlert){
|
|
|
+ clickAndroidAlert();
|
|
|
+ threadSleep(2);
|
|
|
+ return true;
|
|
|
+ }else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void headleAndroidMessage(){
|
|
|
+ boolean isAndroidMsg = false;
|
|
|
+ List<Component> components = parseAndSavePageSource(-1);
|
|
|
+ for (Component component : components) {
|
|
|
+ if ("android:id/message".equals(component.getResource_id())) {
|
|
|
+
|
|
|
+ isAndroidMsg = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(isAndroidMsg) {
|
|
|
+ clickAndroidMsg();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void handleAndroidAlertOnLaunch() {
|
|
|
+ PrintUtil.print("Handle AndroidAlert On Launch", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ int index = 0;
|
|
|
+ while (true){
|
|
|
+ PrintUtil.print("Try to handle AndroidAlert times " + index, TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ if (index >= 6){
|
|
|
+ PrintUtil.print("Can't handle AndroidAlert On Launch", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ boolean goOn = handleAndroidAlert();
|
|
|
+ if (goOn) {
|
|
|
+ PrintUtil.print("Handled AndroidAlert " + index, TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ index++;
|
|
|
+ }else {
|
|
|
+ PrintUtil.print("No AndroidAlert. Continue test.", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Component> handleNoClickableComWhenFirstLaunch(List<Component> coms, int depth){
|
|
|
+ int swipeCount = 0;
|
|
|
+ while (coms.size() == 0 && swipeCount < 8){
|
|
|
+ PrintUtil.print("Ready to swipe because there is no clickable component", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ executeSwipe();
|
|
|
+ coms = getCurrentClickableComList(depth, true);
|
|
|
+ swipeCount++;
|
|
|
+ }
|
|
|
+ return coms;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void clickAndroidAlert(){
|
|
|
+ for (String label: Consts.ANDROID_ALERT_LABELS) {
|
|
|
+ String printMessage = "Click button1 for AndroidAlert";
|
|
|
+ String actionType = "CLICK";
|
|
|
+ String actionMsg = "Click Confirm button for AndroidAlert";
|
|
|
+ String scriptFormat = "driver.findElementById(%s).click();\n";
|
|
|
+ if (!label.contains("android")){
|
|
|
+ printMessage = "Click allow button for AndroidAlert";
|
|
|
+ scriptFormat = "driver.findElementByXPath(\"//android.widget.Button[contains(@text,'%s')]\").click();\n";
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ PrintUtil.print(printMessage, TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ String activityBeforeAction = driver.currentActivity();
|
|
|
+ String timeBeforeAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ if (label.contains("android")) {
|
|
|
+ driver.findElementById(label).click();
|
|
|
+ }else {
|
|
|
+ driver.findElementByXPath("//android.widget.Button[contains(@text,'" + label + "')]").click();
|
|
|
+ }
|
|
|
+ String timeAfterAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ String activityAfterAction = driver.currentActivity();
|
|
|
+
|
|
|
+ recordAction(new Action(timeBeforeAction, timeAfterAction, actionType, actionMsg, activityBeforeAction, activityAfterAction));
|
|
|
+ scriptWriter.write(String.format(scriptFormat, label));
|
|
|
+ scriptWriter.flush();
|
|
|
+ } catch (NoSuchElementException e){
|
|
|
+ PrintUtil.print("Can't locate AndroidAlert component", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ continue;
|
|
|
+ } catch (Exception e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void clickAndroidMsg(){
|
|
|
+ try{
|
|
|
+ PrintUtil.print("Click cancel button for AndroidMsg", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ String activityBeforeAction = driver.currentActivity();
|
|
|
+ String timeBeforeAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ driver.findElementById("android:id/button2").click();
|
|
|
+ String timeAfterAction = DeviceUtil.getDeviceTime(udid);
|
|
|
+ String activityAfterAction = driver.currentActivity();
|
|
|
+ try {
|
|
|
+ String type = "CLICK";
|
|
|
+ String msg = "Click Cancel button for AndroidMsg";
|
|
|
+ recordAction(new Action(timeBeforeAction, timeAfterAction, type, msg, activityBeforeAction, activityAfterAction));
|
|
|
+ scriptWriter.write("driver.findElementById(\"android:id/button2\").click();\n");
|
|
|
+ scriptWriter.flush();
|
|
|
+ } catch (IOException e1) {
|
|
|
+ PrintUtil.printException(TAG, udid, e1);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ PrintUtil.print("Can't locate AndroidMsg component", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ }
|
|
|
+ threadSleep(2);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String savePageSource(int depth, String content){
|
|
|
+ String path = AddressUtil.getPageSourcePath(traceId, udid, depth);
|
|
|
+ try {
|
|
|
+ FileUtil.saveFile(content, path);
|
|
|
+ }catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return path;
|
|
|
+ }
|
|
|
+ private void recordAction(Action action){
|
|
|
+ try {
|
|
|
+ actionWriter.write(new Gson().toJson(action) + "\n");
|
|
|
+ actionWriter.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void threadSleep(int seconds){
|
|
|
+ try {
|
|
|
+ PrintUtil.print(String.format("Sleep %s seconds.", String.valueOf(seconds)), TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ Thread.sleep(seconds * 1000);
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ String script = String.format(" try {\nThread.sleep(%s);\n} catch (InterruptedException e) {\ne.printStackTrace();\n}\n", String.valueOf(seconds*1000));
|
|
|
+ scriptWriter.write(script);
|
|
|
+ scriptWriter.flush();
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void printComponentList(List<Component> comList){
|
|
|
+ for(Component component: comList){
|
|
|
+ String father = "Null";
|
|
|
+ if(component.getFatherComponent() != null ){
|
|
|
+ father = component.getFatherComponent().getLocator();
|
|
|
+ }
|
|
|
+ String msg = String.format("%s, Tested: %s, Father: %s.", component.getLocator(), component.isHasBeenTested(), father);
|
|
|
+ PrintUtil.print(msg, TAG, udid, myTestLogWriter, PrintUtil.ANSI_YELLOW);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void takeScreenShotAndSavePageImg(){
|
|
|
+ int count = 0;
|
|
|
+ FileReader fr;
|
|
|
+ File newFile = new File(AddressUtil.getPageImgPath(traceId, udid, driver.currentActivity()));
|
|
|
+ while (count < 10){
|
|
|
+ try {
|
|
|
+ File screenShotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
|
|
|
+ FileUtils.copyFile(screenShotFile, newFile);
|
|
|
+ fr = new FileReader(newFile);
|
|
|
+ if (fr.read() != -1){
|
|
|
+ PrintUtil.print("Screenshot saved successful.", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.print("Screenshot error ", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PrintUtil.print("Screenshot saved failed.", TAG, udid, myTestLogWriter, PrintUtil.ANSI_RED);
|
|
|
+ }
|
|
|
+ private void savePageXml(){
|
|
|
+ String activityName = driver.currentActivity();
|
|
|
+ String xmlPath = AddressUtil.getPageXmlPath(traceId, udid, activityName);
|
|
|
+ String pageXml = driver.getPageSource();
|
|
|
+ FileOutputStream writerStream;
|
|
|
+ try {
|
|
|
+ writerStream = new FileOutputStream(xmlPath);
|
|
|
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(writerStream, UTF_8));
|
|
|
+ writer.write(pageXml);
|
|
|
+ writer.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void returnPrevActivity(){
|
|
|
+ String returnStartActivity = driver.currentActivity();
|
|
|
+ String currentActivity = returnStartActivity;
|
|
|
+ int returnCount = 0;
|
|
|
+
|
|
|
+ while(currentActivity.equals(returnStartActivity)) {
|
|
|
+ returnCount++;
|
|
|
+ if(returnCount >= 3 ) {
|
|
|
+
|
|
|
+
|
|
|
+ executeKeyEvent("Click Home button because has tried more than 3 times", AndroidKey.HOME);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ executeKeyEvent("Click Return button because this page has done", AndroidKey.BACK);
|
|
|
+ currentActivity = driver.currentActivity();
|
|
|
+ PrintUtil.print("Current activity is " + currentActivity, TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ PrintUtil.print("Return start activity is" + returnStartActivity, TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private List<Component> parseAndSavePageSource(int depth){
|
|
|
+ String pageSource = driver.getPageSource();
|
|
|
+ String path = savePageSource(depth, pageSource);
|
|
|
+ DoXml parseXml = new DoXml();
|
|
|
+ return parseXml.run(path);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * @description
|
|
|
+ * 作用:更新当前页面控件集
|
|
|
+ * 被调用时刻:1、当前测试页面UI变化 2、从其他页面返回后发现当前页面变化 3、进入已测试过页面发现页面变化
|
|
|
+ * 更新机制:先把comList4Update中的所有控件放插入到newComList的最前面(但这些控件若在comList中出现过,那么hasBeenTested属性设置为comList中对应的,即该控件可能已被测试过),放在newComList的最前面是因为comList4Update中控件代表了实时的页面控件集,优先进行这些控件的测试;
|
|
|
+ * 接下来再把comList中其他的和comList4Update不相交的控件插入newComList
|
|
|
+ * --采用这种机制的原因是为了避免一个Activity上会出现多个页面覆盖的问题(为了保留住该页面上所有出现过的控件的hasBeenTested属性)--
|
|
|
+ * 比如某Acticity上初始页面是一组控件 <a,b,c,d>,点击控件a后,页面上弹出了一个新的组件覆盖了此页面(Activity没变,<a,b,c,d>被完全覆盖住),这时候页面上可以获取到的控件为<e,f,g,h>,那么如果直接将此Activity控件集更新为<e,f,g,h>,那在测试完<e,f,g,h>,如果又回到之前的初始页面也就是<a,b,c,d>,理应继续测试控件b,但由于此时控件集里只有<e,f,g,h>的测试状态,所以会认为,控件a并没有被测试过,所以会继续测试控件a,导致程序陷入一个死循环
|
|
|
+ * @param comList 变化前页面控件集
|
|
|
+ * @param comList4Update 当前实时解析的页面控件集
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<Component> setTestedComInList(List<Component> comList, List<Component> comList4Update){
|
|
|
+ List<Component> newComList = new ArrayList<Component>();
|
|
|
+ for(Component component : comList4Update){
|
|
|
+ if(comList.contains(component)){
|
|
|
+ int index = comList.indexOf(component);
|
|
|
+ component.setHasBeenTested(comList.get(index).isHasBeenTested());
|
|
|
+ if(comList.get(index).getFatherComponent() != null) {
|
|
|
+ component.setFatherComponent(comList.get(index).getFatherComponent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ newComList.add(component);
|
|
|
+ }
|
|
|
+ for(Component component : comList){
|
|
|
+ if(!comList4Update.contains(component)) {
|
|
|
+ newComList.add(component);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return newComList;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int activityIndexOfActivityList(String activityName){
|
|
|
+ for (int i=0;i<activityList.size();++i){
|
|
|
+ if (activityList.get(i).getName().equals(activityName)){
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadConfiguration(){
|
|
|
+ this.ignoreMap = new HashMap<>(Consts.IGNORE_KEYWORD.length);
|
|
|
+ for (String keyword: Consts.IGNORE_KEYWORD){
|
|
|
+ ignoreMap.put(keyword, new IgnoreComponent(keyword));
|
|
|
+ }
|
|
|
+ readIgnoreComponent();
|
|
|
+ readFatherComponent();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void readIgnoreComponent(){
|
|
|
+ BufferedReader br = null;
|
|
|
+ try {
|
|
|
+ br = new BufferedReader(new FileReader(AddressUtil.getIgnoreConfigurationPath()));
|
|
|
+
|
|
|
+ * component in ignore.conf file will be ignored.
|
|
|
+ * component identifier can only be id/content-desc/text, and use method equals/startsWith/contains
|
|
|
+ * must write in order equals, startsWith, contains
|
|
|
+ */
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String strLine = "";
|
|
|
+ try {
|
|
|
+ String mode = "unknown";
|
|
|
+ while((strLine = br.readLine()) != null){
|
|
|
+ if (strLine.isEmpty() || strLine.startsWith("//")){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if ("*equals*".equals(strLine)){
|
|
|
+ mode = "equals";
|
|
|
+ continue;
|
|
|
+ }else if ("*startsWith*".equals(strLine)){
|
|
|
+ mode = "startsWith";
|
|
|
+ continue;
|
|
|
+ }else if ("*contains*".equals(strLine)){
|
|
|
+ mode = "contains";
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String[] temp = strLine.split("#");
|
|
|
+ if (temp.length != 2){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String modeKeyword = temp[0];
|
|
|
+ String componentSign = temp[1];
|
|
|
+ IgnoreComponent ic = ignoreMap.get(modeKeyword);
|
|
|
+ if (ic != null){
|
|
|
+ ic.add(mode, componentSign);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void readFatherComponent(){
|
|
|
+ BufferedReader br = null;
|
|
|
+ try {
|
|
|
+ br = new BufferedReader(new FileReader(AddressUtil.getFatherComponentConfigurationPath()));
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String strLine = "";
|
|
|
+ try {
|
|
|
+ while((strLine = br.readLine()) != null){
|
|
|
+ if(strLine.contains("#")) {
|
|
|
+ fatherComponentList.add(strLine);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean judgeIgnoreComponent(Component component){
|
|
|
+ boolean ignoreFlag = false;
|
|
|
+ String contentDesc = component.getContent_desc();
|
|
|
+ String resourceId = component.getResource_id();
|
|
|
+ String text = component.getText();
|
|
|
+ try {
|
|
|
+ ignoreFlag = ignoreMap.get("content_desc").check(contentDesc)
|
|
|
+ || ignoreMap.get("id").check(resourceId)
|
|
|
+ || ignoreMap.get("text").check(text);
|
|
|
+ } catch (Exception e) {
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
+ }
|
|
|
+ if(ignoreFlag) {
|
|
|
+ PrintUtil.print(component.getLocator() + " is a component in ignore file, skip to next one", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ }
|
|
|
+ return ignoreFlag;
|
|
|
+ }
|
|
|
+ private boolean judgeTestedComponent(Component component){
|
|
|
+ if(component.isHasBeenTested()){
|
|
|
+ PrintUtil.print(component.getLocator() + " has been tested, skip to next one", TAG, udid, myTestLogWriter, PrintUtil.ANSI_BLUE);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean judgeFatherComponent(Component component, String currentActivity){
|
|
|
+ for(String fatherComponent : fatherComponentList){
|
|
|
+ String locator = fatherComponent.split("#")[0];
|
|
|
+ String activity = fatherComponent.split("#")[1];
|
|
|
+ if(locator.equals(component.getLocator()) && currentActivity.contains(activity)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterRun(){
|
|
|
+ try {
|
|
|
+ scriptWriter.close();
|
|
|
+ myTestLogWriter.close();
|
|
|
+ actionWriter.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|