|
@@ -25,7 +25,7 @@ import static java.nio.charset.StandardCharsets.UTF_8;
|
|
public class MergeScript extends AbstractBaseScript {
|
|
public class MergeScript extends AbstractBaseScript {
|
|
|
|
|
|
public static final String TAG = Thread.currentThread() .getStackTrace()[1].getClassName();
|
|
public static final String TAG = Thread.currentThread() .getStackTrace()[1].getClassName();
|
|
-
|
|
|
|
|
|
+ private String flowDir = "OperationFlow"+File.separator;
|
|
private String udid;
|
|
private String udid;
|
|
private AndroidDriver driver;
|
|
private AndroidDriver driver;
|
|
private ApkInfo apkInfo;
|
|
private ApkInfo apkInfo;
|
|
@@ -73,6 +73,7 @@ public class MergeScript extends AbstractBaseScript {
|
|
this.driver = driver;
|
|
this.driver = driver;
|
|
this.apkInfo = apkInfo;
|
|
this.apkInfo = apkInfo;
|
|
this.appPackage = apkInfo.getPackageName();
|
|
this.appPackage = apkInfo.getPackageName();
|
|
|
|
+ this.flowDir = this.flowDir+appPackage+File.separator;
|
|
}
|
|
}
|
|
private void initWriter(File testScript, File testAction, File myTestLog){
|
|
private void initWriter(File testScript, File testAction, File myTestLog){
|
|
try {
|
|
try {
|
|
@@ -108,44 +109,42 @@ public class MergeScript extends AbstractBaseScript {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void run(){
|
|
public void run(){
|
|
- PrintUtil.print("MergeScript start", TAG, udid);
|
|
|
|
- //跑第一遍
|
|
|
|
- startTest();
|
|
|
|
- //读内容
|
|
|
|
- preRun();
|
|
|
|
//跑
|
|
//跑
|
|
try{
|
|
try{
|
|
int testNum=0;
|
|
int testNum=0;
|
|
if (resList != null) {
|
|
if (resList != null) {
|
|
for (int i = 0; i < nodeList.size(); i++) {
|
|
for (int i = 0; i < nodeList.size(); i++) {
|
|
try {
|
|
try {
|
|
|
|
+ //DFS中如果有覆盖到这里,就不用跑这条了
|
|
if (nodeList.get(i).isVisited()) {
|
|
if (nodeList.get(i).isVisited()) {
|
|
- System.out.println("第" + (i + 1) + "条路径 已被覆盖,继续下一条");
|
|
|
|
|
|
+ PrintUtil.print("the "+ (i + 1) + "path has been covered in DFS, skip to next", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
testNum++;
|
|
testNum++;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- } catch (Exception ex) {
|
|
|
|
- System.out.println(ex.getStackTrace());
|
|
|
|
- System.out.println("查询路线覆盖情况失败?");
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
|
+ PrintUtil.print("merge DFS and scripts failed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
|
|
+ //重置app
|
|
driver.resetApp();
|
|
driver.resetApp();
|
|
- System.out.println("第" + (i + 1) + "条路径");
|
|
|
|
- System.out.println("sleep 10s to reset APP");
|
|
|
|
|
|
+ PrintUtil.print("rerun the "+(i+1)+" path", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
|
|
+ PrintUtil.print("sleep 10s to reset APP", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
Thread.sleep(10000);
|
|
Thread.sleep(10000);
|
|
try {
|
|
try {
|
|
widgetMergeTools.runOnePath(resList.size(), nodeList.get(i), driver, this);
|
|
widgetMergeTools.runOnePath(resList.size(), nodeList.get(i), driver, this);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- System.out.println(e.getStackTrace());
|
|
|
|
- System.out.println("第" + (i + 1) + "条路径 复现失败");
|
|
|
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
|
+ PrintUtil.print("rerun the "+(i+1)+" path failed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
- System.out.println("路径复现完毕,3秒后开始自动化测试");
|
|
|
|
|
|
+ PrintUtil.print("sleep 3s to start DFS", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
Thread.sleep(3000);
|
|
Thread.sleep(3000);
|
|
try {
|
|
try {
|
|
setStopTestFlag(false);
|
|
setStopTestFlag(false);
|
|
|
|
+ //控制权转移
|
|
startTest();
|
|
startTest();
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- System.out.println(e.getStackTrace());
|
|
|
|
- System.out.println("第" + (i + 1) + "条路径 自动化测试失败");
|
|
|
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
|
+ PrintUtil.print("rerun the "+(i+1)+" times DFS failed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
for (int m = 0; m < resList.size(); m++) {
|
|
for (int m = 0; m < resList.size(); m++) {
|
|
@@ -156,16 +155,16 @@ public class MergeScript extends AbstractBaseScript {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } catch (Exception ex) {
|
|
|
|
- System.out.println(ex.getStackTrace());
|
|
|
|
- System.out.println("用户节点删减失败");
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
|
+ PrintUtil.print("delete covered widget failed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
- System.out.println("本次遍历完成,进入下一条路径");
|
|
|
|
|
|
+ PrintUtil.print("finish the "+(i+1)+" rerun, next", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
- System.out.println("跑完啦");
|
|
|
|
- System.out.println("经过的activity存储在/ActivityList中");
|
|
|
|
|
|
+ PrintUtil.print("success run all", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
//实验用数据
|
|
//实验用数据
|
|
|
|
+ /*
|
|
int num=0;
|
|
int num=0;
|
|
for(int m = 0;m<resList.size();m++){
|
|
for(int m = 0;m<resList.size();m++){
|
|
if(!resList.get(m).isVisited()){
|
|
if(!resList.get(m).isVisited()){
|
|
@@ -174,23 +173,27 @@ public class MergeScript extends AbstractBaseScript {
|
|
}
|
|
}
|
|
System.out.println(testNum+"个新Activity点在测试中被重复覆盖");
|
|
System.out.println(testNum+"个新Activity点在测试中被重复覆盖");
|
|
System.out.println("还有"+num+"个点未被覆盖");
|
|
System.out.println("还有"+num+"个点未被覆盖");
|
|
|
|
+ */
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
- System.out.println("复现人工脚本失败");
|
|
|
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
|
+ PrintUtil.print("rerun the path failed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
- //结尾
|
|
|
|
- afterRun();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
void preRun(){
|
|
void preRun(){
|
|
|
|
+ PrintUtil.print("MergeScript start", TAG, udid);
|
|
|
|
+ //跑第一遍
|
|
|
|
+ startTest();
|
|
//从res文件里读内容
|
|
//从res文件里读内容
|
|
- //TODO地址要改
|
|
|
|
try {
|
|
try {
|
|
- resList = widgetMergeTools.getResList("OperationFlow"+File.separator);
|
|
|
|
- widgetMergeTools.resList2Pic(resList);
|
|
|
|
|
|
+ File fdir = new File(flowDir);
|
|
|
|
+ if(!fdir.exists()) fdir.mkdirs();
|
|
|
|
+ resList = widgetMergeTools.getResList(flowDir);
|
|
nodeList = widgetMergeTools.getAllPath(resList);
|
|
nodeList = widgetMergeTools.getAllPath(resList);
|
|
}catch(Exception e){
|
|
}catch(Exception e){
|
|
- System.out.println("用户操作流读取失败");
|
|
|
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
|
+ PrintUtil.print("read rerun path failed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
//去重
|
|
//去重
|
|
try {
|
|
try {
|
|
@@ -203,16 +206,25 @@ public class MergeScript extends AbstractBaseScript {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
- System.out.println("第一次DFS去重失败");
|
|
|
|
|
|
+ PrintUtil.printException(TAG, udid, e);
|
|
|
|
+ PrintUtil.print("delete covered widget failed", TAG, udid, myTestLogWriter, PrintUtil.ANSI_WHITE);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
void afterRun(){
|
|
void afterRun(){
|
|
//跑的整个数据生成res文件
|
|
//跑的整个数据生成res文件
|
|
-
|
|
|
|
- //删掉旧的
|
|
|
|
|
|
+ widgetMergeTools.resList2Pic(wholeMap,flowDir);
|
|
|
|
+ long time = new Date().getTime();
|
|
|
|
+ for(int index = 0; index< pathList.size();index++){
|
|
|
|
+ List<WidgetInfo> res = pathList.get(index);
|
|
|
|
+ for (int i = 0; i < res.size(); i++) {
|
|
|
|
+ WidgetInfo wi = res.get(i);
|
|
|
|
+ String txtName = flowDir + File.separator + time +"_"+ index +".txt";
|
|
|
|
+ wi.recordWholeElement(txtName);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //删掉旧的 TODO
|
|
}
|
|
}
|
|
|
|
|
|
public void setStopTestFlag(boolean b){
|
|
public void setStopTestFlag(boolean b){
|
|
@@ -281,13 +293,13 @@ public class MergeScript extends AbstractBaseScript {
|
|
//flag开启的情况下,到了web界面则自动返回,防止无限前进
|
|
//flag开启的情况下,到了web界面则自动返回,防止无限前进
|
|
if(closeWebPageFlag){
|
|
if(closeWebPageFlag){
|
|
if(!isNativeApp()){
|
|
if(!isNativeApp()){
|
|
- System.out.println("not native App");
|
|
|
|
|
|
+ PrintUtil.print("not native app", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
executeKeyEvent("Click Return button because is WebPage", AndroidKey.BACK);
|
|
executeKeyEvent("Click Return button because is WebPage", AndroidKey.BACK);
|
|
currentActivity = driver.currentActivity();
|
|
currentActivity = driver.currentActivity();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//TODO 太慢
|
|
//TODO 太慢
|
|
- System.out.println("计算页面hash值");
|
|
|
|
|
|
+ PrintUtil.print("culculate Hash", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
int currentPageHash = driver.getPageSource().hashCode();
|
|
int currentPageHash = driver.getPageSource().hashCode();
|
|
currentNode.setName(currentActivity);
|
|
currentNode.setName(currentActivity);
|
|
//若当前子页面的activity在activityList中,currentActivityIndex为指向该对象的index,不在则为-1
|
|
//若当前子页面的activity在activityList中,currentActivityIndex为指向该对象的index,不在则为-1
|
|
@@ -397,13 +409,13 @@ public class MergeScript extends AbstractBaseScript {
|
|
//web开启则返回
|
|
//web开启则返回
|
|
if(closeWebPageFlag){
|
|
if(closeWebPageFlag){
|
|
if(!isNativeApp()){
|
|
if(!isNativeApp()){
|
|
- System.out.println("not native App");
|
|
|
|
|
|
+ PrintUtil.print("not native App", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
executeKeyEvent("Click Return button because is WebPage", AndroidKey.BACK);
|
|
executeKeyEvent("Click Return button because is WebPage", AndroidKey.BACK);
|
|
activityAfterClick = driver.currentActivity();
|
|
activityAfterClick = driver.currentActivity();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//TODO 太慢
|
|
//TODO 太慢
|
|
- System.out.println("计算页面hash值");
|
|
|
|
|
|
+ PrintUtil.print("culculate Hash", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
int pageHashAfterClick = driver.getPageSource().hashCode();
|
|
int pageHashAfterClick = driver.getPageSource().hashCode();
|
|
if(pageHashAfterClick == currentPageHash){
|
|
if(pageHashAfterClick == currentPageHash){
|
|
//点击控件后的页面的pageSource的hash值没变,页面没有任何改变
|
|
//点击控件后的页面的pageSource的hash值没变,页面没有任何改变
|
|
@@ -1488,7 +1500,7 @@ public class MergeScript extends AbstractBaseScript {
|
|
Set<String> contextNames = driver.getContextHandles();
|
|
Set<String> contextNames = driver.getContextHandles();
|
|
for (String contextName : contextNames) {
|
|
for (String contextName : contextNames) {
|
|
if (contextName.contains("WEBVIEW")) {
|
|
if (contextName.contains("WEBVIEW")) {
|
|
- System.out.println("is webview, return");
|
|
|
|
|
|
+ PrintUtil.print("is webview, return", TAG, udid, myTestLogWriter, PrintUtil.ANSI_GREEN);
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1496,7 +1508,9 @@ public class MergeScript extends AbstractBaseScript {
|
|
}
|
|
}
|
|
|
|
|
|
private void recordActivity(String act) {
|
|
private void recordActivity(String act) {
|
|
|
|
+ //no need now
|
|
//实验用,记录每一个到达过的activity
|
|
//实验用,记录每一个到达过的activity
|
|
|
|
+ /*
|
|
File f = new File("ActivityList");
|
|
File f = new File("ActivityList");
|
|
if(!f.exists()){
|
|
if(!f.exists()){
|
|
f.mkdirs();
|
|
f.mkdirs();
|
|
@@ -1509,5 +1523,6 @@ public class MergeScript extends AbstractBaseScript {
|
|
} catch (IOException e) {
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+ */
|
|
}
|
|
}
|
|
}
|
|
}
|