Skip to content

Commit

Permalink
error step screenshot
Browse files Browse the repository at this point in the history
  • Loading branch information
soloPi committed Sep 5, 2019
1 parent 29478bd commit 03cbfd1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ void *(**On*Event);
-keep class com.alipay.hulu.common.utils.ClassUtil$PatchVersionInfo { *; }
-keep class com.alipay.hulu.common.utils.patch.PatchDescription {*;}

-keep class com.alipay.hulu.common.utils.DeviceInfoUtil {*;}

#内部方法
-keepattributes EnclosingMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.text.TextUtils;

import com.alibaba.fastjson.JSON;
import com.alipay.hulu.R;
import com.alipay.hulu.activity.MyApplication;
import com.alipay.hulu.bean.AdvanceCaseSetting;
import com.alipay.hulu.bean.CaseParamBean;
Expand All @@ -31,6 +32,7 @@
import com.alipay.hulu.shared.io.bean.RecordCaseInfo;
import com.alipay.hulu.shared.io.util.OperationStepUtil;
import com.alipay.hulu.shared.node.OperationService;
import com.alipay.hulu.shared.node.action.OperationContext;
import com.alipay.hulu.shared.node.action.OperationExecutor;
import com.alipay.hulu.shared.node.action.OperationMethod;
import com.alipay.hulu.shared.node.action.PerformActionEnum;
Expand All @@ -49,6 +51,8 @@
import java.util.Locale;
import java.util.Map;
import java.util.Stack;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;

import static com.alipay.hulu.shared.node.utils.LogicUtil.CHECK_PARAM;
Expand Down Expand Up @@ -446,6 +450,7 @@ public boolean reportErrorStep(OperationStep step, String reason, List<String> s
loopParams.pop();
} else {
this.errorReason = reason + "\n" + StringUtil.join("\n", stack);
takeScreenshot();
return true;
}

Expand All @@ -454,9 +459,42 @@ public boolean reportErrorStep(OperationStep step, String reason, List<String> s
}

this.errorReason = reason + "\n" + StringUtil.join("\n", stack);
takeScreenshot();
return true;
}

/**
* 进行截图
*/
protected void takeScreenshot() {
// 执行失败,进行截图
OperationMethod method = new OperationMethod(PerformActionEnum.SCREENSHOT);

// 生成文件名
Date now = new Date();
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS_" +
StringUtil.getString(R.string.step_provider__error_step, currentIdx), Locale.CHINA);
String newFileName = format.format(now);
method.putParam(OperationExecutor.INPUT_TEXT_KEY, newFileName);
screenshotFiles.put(StringUtil.getString(R.string.step_provider__error_step, currentIdx), newFileName);

final CountDownLatch latch = new CountDownLatch(1);
// 执行截图操作
operationService.doSomeAction(method, null, new OperationContext.OperationListener() {
@Override
public void notifyOperationFinish() {
latch.countDown();
}
});

// 等5s截图保存
try {
latch.await(5000, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
LogUtil.e(TAG, "Catch java.lang.InterruptedException: " + e.getMessage(), e);
}
}

@Override
public void onStepInfo(ReplayStepInfoBean bean) {
currentStepInfo.put(currentIdx - 1, bean);
Expand Down
1 change: 1 addition & 0 deletions src/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,5 @@
<string name="function_group__control">流程</string>
<string name="function_group__logic">逻辑</string>
<string name="float__toast_title">SoloPi悬浮窗正在运行</string>
<string name="step_provider__error_step">故障步骤_%d</string>
</resources>

0 comments on commit 03cbfd1

Please sign in to comment.