|
@@ -1,5 +1,7 @@
|
|
|
package cn.com.ctop.crawler.modules.core.util;
|
|
|
|
|
|
+import cn.com.ctop.common.module.utils.ResultMapUtils;
|
|
|
+import cn.com.ctop.common.module.utils.StatusCode;
|
|
|
import cn.com.ctop.crawler.modules.appium.entity.AppiumTaskItem;
|
|
|
import com.google.gson.Gson;
|
|
|
import io.appium.java_client.TouchAction;
|
|
@@ -14,6 +16,7 @@ import org.openqa.selenium.remote.DesiredCapabilities;
|
|
|
import java.net.URL;
|
|
|
import java.time.Duration;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Slf4j
|
|
|
public class AppiumUtil {
|
|
@@ -134,55 +137,58 @@ public class AppiumUtil {
|
|
|
break;
|
|
|
}
|
|
|
} else if (pkg.equals("com.smile.gifmaker")) {
|
|
|
+ //干扰项
|
|
|
WebElement positive = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/positive");
|
|
|
if (positive != null) {
|
|
|
positive.click();
|
|
|
}
|
|
|
|
|
|
switch (activity) {
|
|
|
+ //干扰项
|
|
|
case "com.yxcorp.gifshow.webview.KwaiWebViewActivity":
|
|
|
-// WebElement leftTv = getElementById(androidDriver,"com.smile.gifmaker:id/left_tv");
|
|
|
WebElement leftBtn1 = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_btn");
|
|
|
if (leftBtn1 != null) {
|
|
|
leftBtn1.click();
|
|
|
}
|
|
|
-// if (leftTv != null){
|
|
|
-// leftTv.click();
|
|
|
-// }
|
|
|
break;
|
|
|
+ //TODO --- 首
|
|
|
+ // 1页
|
|
|
case "com.yxcorp.gifshow.HomeActivity":
|
|
|
|
|
|
WebElement loginText = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/login_text");
|
|
|
- WebElement leftText = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_text");
|
|
|
- WebElement phoneLoginBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/phone_login_view");
|
|
|
- WebElement leftBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_btn");
|
|
|
- WebElement closeBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/close_btn");
|
|
|
- if (closeBtn != null) {
|
|
|
- closeBtn.click();
|
|
|
- break;
|
|
|
- }
|
|
|
if (loginText != null) {
|
|
|
loginText.click();
|
|
|
break;
|
|
|
}
|
|
|
+ WebElement leftText = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_text");
|
|
|
if (leftText != null) {
|
|
|
leftText.click();
|
|
|
break;
|
|
|
}
|
|
|
+ WebElement phoneLoginBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/phone_login_view");
|
|
|
if (phoneLoginBtn != null) {
|
|
|
phoneLoginBtn.click();
|
|
|
break;
|
|
|
}
|
|
|
+ WebElement closeBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/close_btn");
|
|
|
+ if (closeBtn != null) {
|
|
|
+ closeBtn.click();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ WebElement leftBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_btn");
|
|
|
if (leftBtn != null) {
|
|
|
leftBtn.click();
|
|
|
Thread.sleep(5000);
|
|
|
+ //查询左侧是否存在头像
|
|
|
WebElement tabAvatar = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/tab_avatar");
|
|
|
if (tabAvatar != null) {
|
|
|
tabAvatar.click();
|
|
|
} else {
|
|
|
+ //不存在头像
|
|
|
Thread.sleep(3000);
|
|
|
tapPoint(androidDriver, 650, 1230);
|
|
|
Thread.sleep(3000);
|
|
|
+ // 点击我的
|
|
|
tapPoint(androidDriver, 650, 1230);
|
|
|
Thread.sleep(3000);
|
|
|
tapPoint(androidDriver, 650, 400);
|
|
@@ -196,6 +202,7 @@ public class AppiumUtil {
|
|
|
}
|
|
|
tapPoint(androidDriver, 650, 400);
|
|
|
break;
|
|
|
+ //TODO ---- 获取快手ID
|
|
|
case "com.yxcorp.plugin.qrcode.MyQRCodeActivity":
|
|
|
WebElement kwaiId = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/kwai_id");
|
|
|
if (kwaiId != null) {
|
|
@@ -204,10 +211,12 @@ public class AppiumUtil {
|
|
|
androidDriver.quit();
|
|
|
}
|
|
|
break;
|
|
|
+ //TODO ----
|
|
|
case "com.yxcorp.gifshow.activity.BrowseSettingsActivity":
|
|
|
//com.smile.gifmaker:id/browse_setting_new_btn 开启大屏模式 关闭大屏模式
|
|
|
//com.smile.gifmaker:id/left_btn 返回
|
|
|
break;
|
|
|
+ //TODO ----登录
|
|
|
case "com.yxcorp.login.userlogin.LoginActivity":
|
|
|
WebElement loginTitleTv = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/login_title_tv");
|
|
|
WebElement loginNameEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/login_name_et");
|
|
@@ -229,41 +238,11 @@ public class AppiumUtil {
|
|
|
nextView.click();
|
|
|
}
|
|
|
break;
|
|
|
+ //TODO ---- 重置密码
|
|
|
case "com.yxcorp.login.userlogin.RetrievePasswordActivity":
|
|
|
- WebElement nameEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/name_et");
|
|
|
- if (nameEt != null) {
|
|
|
- Thread.sleep(5000);
|
|
|
- WebElement verifyTv = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/verify_tv");
|
|
|
- if (verifyTv != null) {
|
|
|
- verifyTv.click();
|
|
|
- int i = 0;
|
|
|
- String msg = null;
|
|
|
- while (i < 20) {
|
|
|
- i++;
|
|
|
- if (msg != null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- try {
|
|
|
- msg = KuaimiUtil.getMessage(token, "2307", mobile);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("等待" + mobile + "短信验证码");
|
|
|
- Thread.sleep(5000);
|
|
|
- }
|
|
|
- }
|
|
|
- if (msg != null) {
|
|
|
- WebElement verifyEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/verify_et");
|
|
|
- if (verifyEt != null) {
|
|
|
- verifyEt.sendKeys(msg);
|
|
|
- Thread.sleep(5000);
|
|
|
- WebElement confirmBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/confirm_btn");
|
|
|
- if (confirmBtn != null) {
|
|
|
- confirmBtn.click();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+
|
|
|
break;
|
|
|
+ //TODO
|
|
|
case "com.yxcorp.login.userlogin.ResetSelectedAccountPasswordActivity":
|
|
|
WebElement confirmBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/confirm_btn");
|
|
|
WebElement loginPsdEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/login_psd_et");
|
|
@@ -306,23 +285,12 @@ public class AppiumUtil {
|
|
|
phoneOneKeyLoginBtn.click();
|
|
|
}
|
|
|
break;
|
|
|
+ //TODO ----
|
|
|
case "com.yxcorp.login.userlogin.CaptchaCodeLoginActivity":
|
|
|
WebElement captchaEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/captcha_et");
|
|
|
if (captchaEt != null) {
|
|
|
int i = 0;
|
|
|
- String msg = null;
|
|
|
- while (i < 20) {
|
|
|
- i++;
|
|
|
- if (msg != null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- try {
|
|
|
- msg = KuaimiUtil.getMessage(token, "2307", mobile);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("等待" + mobile + "短信验证码");
|
|
|
- Thread.sleep(5000);
|
|
|
- }
|
|
|
- }
|
|
|
+ String msg = getMobileCaptcha(token, mobile);
|
|
|
if (msg != null) {
|
|
|
captchaEt.sendKeys(msg);
|
|
|
Thread.sleep(5000);
|
|
@@ -333,6 +301,7 @@ public class AppiumUtil {
|
|
|
}
|
|
|
}
|
|
|
break;
|
|
|
+ //TODO
|
|
|
case "com.yxcorp.login.userlogin.PhoneLoginV2Activity":
|
|
|
WebElement phoneEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/phone_et");
|
|
|
if (phoneEt != null) {
|
|
@@ -343,20 +312,7 @@ public class AppiumUtil {
|
|
|
WebElement fetchCodeTv = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/fetch_code_tv");
|
|
|
if (fetchCodeTv != null) {
|
|
|
fetchCodeTv.click();
|
|
|
- int i = 0;
|
|
|
- String msg = null;
|
|
|
- while (i < 20) {
|
|
|
- i++;
|
|
|
- if (msg != null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- try {
|
|
|
- msg = KuaimiUtil.getMessage(token, "2307", mobile);
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("等待" + mobile + "短信验证码");
|
|
|
- Thread.sleep(5000);
|
|
|
- }
|
|
|
- }
|
|
|
+ String msg = getMobileCaptcha(token, mobile);
|
|
|
if (msg != null) {
|
|
|
WebElement captchaCodeEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/captcha_code_et");
|
|
|
if (captchaCodeEt != null) {
|
|
@@ -397,6 +353,238 @@ public class AppiumUtil {
|
|
|
return isContinue;
|
|
|
}
|
|
|
|
|
|
+ public Map<String, Object> checkMethod(AndroidDriver androidDriver, String activity, Map<String, Object> result) throws Exception {
|
|
|
+ Integer code = (Integer) result.get("code");
|
|
|
+ if (null != code && code != StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if ("com.yxcorp.gifshow.detail.PhotoDetailActivity".equals(activity)) {
|
|
|
+ WebElement element = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/back_btn");
|
|
|
+ element.click();
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if ("com.yxcorp.login.userlogin.ResetSelectedAccountPasswordActivity".equals(activity)) {
|
|
|
+ WebElement confirmBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/confirm_btn");
|
|
|
+ WebElement loginPsdEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/login_psd_et");
|
|
|
+ if (loginPsdEt != null) {
|
|
|
+ loginPsdEt.sendKeys("a123456");
|
|
|
+ Thread.sleep(5000);
|
|
|
+ if (confirmBtn != null) {
|
|
|
+ confirmBtn.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //首页
|
|
|
+ if ("com.yxcorp.gifshow.HomeActivity".equals(activity)) {
|
|
|
+ WebElement loginText = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/login_text");
|
|
|
+ if (loginText != null) {
|
|
|
+ loginText.click();
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ WebElement leftText = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_text");
|
|
|
+ if (leftText != null) {
|
|
|
+ leftText.click();
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ WebElement phoneLoginBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/phone_login_view");
|
|
|
+ if (phoneLoginBtn != null) {
|
|
|
+ phoneLoginBtn.click();
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ WebElement closeBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/close_btn");
|
|
|
+ if (closeBtn != null) {
|
|
|
+ closeBtn.click();
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ WebElement leftBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_btn");
|
|
|
+ if (leftBtn == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_ELEMENT_IS_NULL.getCode());
|
|
|
+ log.error("元素获取异常==>activity:{},id:{}", activity, "com.smile.gifmaker:id/left_btn");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Thread.sleep(2000);
|
|
|
+ leftBtn.click();
|
|
|
+ Thread.sleep(2000);
|
|
|
+ //查询左侧是否存在头像
|
|
|
+ WebElement tabAvatar = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/tab_avatar");
|
|
|
+ if (tabAvatar != null) {
|
|
|
+ tabAvatar.click();
|
|
|
+ } else {
|
|
|
+ //不存在头像
|
|
|
+ Thread.sleep(3000);
|
|
|
+ tapPoint(androidDriver, 650, 1230);
|
|
|
+ Thread.sleep(3000);
|
|
|
+ // 点击我的
|
|
|
+ tapPoint(androidDriver, 650, 1230);
|
|
|
+ Thread.sleep(3000);
|
|
|
+ tapPoint(androidDriver, 650, 400);
|
|
|
+ }
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //大屏模式
|
|
|
+ if ("com.yxcorp.gifshow.activity.BrowseSettingsActivity".equals(activity)) {
|
|
|
+ //com.smile.gifmaker:id/browse_setting_new_btn 开启大屏模式 关闭大屏模式
|
|
|
+ //com.smile.gifmaker:id/left_btn 返回
|
|
|
+ }
|
|
|
+ //登录
|
|
|
+ if ("com.yxcorp.login.userlogin.LoginActivity".equals(activity)) {
|
|
|
+ WebElement loginTitleTv = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/login_title_tv");
|
|
|
+ WebElement loginNameEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/login_name_et");
|
|
|
+ WebElement nextView = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/next_view");
|
|
|
+ if (loginTitleTv != null) {
|
|
|
+ System.out.println(loginTitleTv.getText());
|
|
|
+ if (loginTitleTv.getText().equals("输入密码")) {
|
|
|
+ WebElement forgetPsdBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/forget_psd_btn");
|
|
|
+ if (forgetPsdBtn != null) {
|
|
|
+ forgetPsdBtn.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (loginNameEt != null) {
|
|
|
+ String token = KuaimiUtil.kuaimiLogin();
|
|
|
+ String mobile = KuaimiUtil.getMobile(token, "2307");
|
|
|
+ result.put("token", token);
|
|
|
+ result.put("mobile", mobile);
|
|
|
+ loginNameEt.sendKeys(mobile);
|
|
|
+ Thread.sleep(5000);
|
|
|
+ nextView.click();
|
|
|
+ }
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //重置密码
|
|
|
+ if ("com.yxcorp.login.userlogin.RetrievePasswordActivity".equals(activity)) {
|
|
|
+ String token = (String) result.get("token");
|
|
|
+ String mobile = (String) result.get("mobile");
|
|
|
+ WebElement nameEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/name_et");
|
|
|
+ if (nameEt != null) {
|
|
|
+ Thread.sleep(5000);
|
|
|
+ WebElement verifyTv = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/verify_tv");
|
|
|
+ if (verifyTv != null) {
|
|
|
+ verifyTv.click();
|
|
|
+ String msg = getMobileCaptcha(token, mobile);
|
|
|
+ if (msg != null) {
|
|
|
+ WebElement verifyEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/verify_et");
|
|
|
+ if (verifyEt != null) {
|
|
|
+ verifyEt.sendKeys(msg);
|
|
|
+ Thread.sleep(5000);
|
|
|
+ WebElement confirmBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/confirm_btn");
|
|
|
+ if (confirmBtn != null) {
|
|
|
+ confirmBtn.click();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //验证码登录
|
|
|
+ if ("com.yxcorp.login.userlogin.CaptchaCodeLoginActivity".equals(activity)) {
|
|
|
+ String token = (String) result.get("token");
|
|
|
+ String mobile = (String) result.get("mobile");
|
|
|
+ WebElement captchaEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/captcha_et");
|
|
|
+ if (captchaEt == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_ELEMENT_IS_NULL.getCode());
|
|
|
+ log.error("元素获取异常==>activity:{},id:{}", activity, "com.smile.gifmaker:id/captcha_et");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ String captcha = getMobileCaptcha(token, mobile);
|
|
|
+ if (captcha == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_MOBILE_CODE_IS_NULL.getCode());
|
|
|
+ log.error("短信验证码获取异常==>activity:{}", activity);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ captchaEt.sendKeys(captcha);
|
|
|
+ Thread.sleep(5000);
|
|
|
+ WebElement captchaFinish = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/captcha_finish");
|
|
|
+ if (captchaFinish == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_ELEMENT_IS_NULL.getCode());
|
|
|
+ log.error("元素获取异常==>activity:{},id:{}", activity, "com.smile.gifmaker:id/captcha_finish");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ captchaFinish.click();
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //登录v2
|
|
|
+ if ("com.yxcorp.login.userlogin.PhoneLoginV2Activity".equals(activity)) {
|
|
|
+ String token = (String) result.get("token");
|
|
|
+ String mobile = (String) result.get("mobile");
|
|
|
+ WebElement phoneEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/phone_et");
|
|
|
+ if (phoneEt == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_ELEMENT_IS_NULL.getCode());
|
|
|
+ log.error("元素获取异常==>activity:{},id:{}", activity, "com.smile.gifmaker:id/fetch_code_tv");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ token = KuaimiUtil.kuaimiLogin();
|
|
|
+ mobile = KuaimiUtil.getMobile(token, "2307");
|
|
|
+ result.put("token", token);
|
|
|
+ result.put("mobile", mobile);
|
|
|
+ phoneEt.sendKeys(mobile);
|
|
|
+ Thread.sleep(5000);
|
|
|
+ WebElement fetchCodeTv = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/fetch_code_tv");
|
|
|
+ if (fetchCodeTv == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_ELEMENT_IS_NULL.getCode());
|
|
|
+ log.error("元素获取异常==>activity:{},id:{}", activity, "com.smile.gifmaker:id/fetch_code_tv");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ fetchCodeTv.click();
|
|
|
+ String msg = getMobileCaptcha(token, mobile);
|
|
|
+ if (msg == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_MOBILE_CODE_IS_NULL.getCode());
|
|
|
+ log.error("短信验证码获取异常==>activity:{}", activity);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ WebElement captchaCodeEt = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/captcha_code_et");
|
|
|
+ if (captchaCodeEt == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_ELEMENT_IS_NULL.getCode());
|
|
|
+ log.error("元素获取异常==>activity:{},id:{}", activity, "com.smile.gifmaker:id/captcha_code_et");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ captchaCodeEt.sendKeys(msg);
|
|
|
+ Thread.sleep(5000);
|
|
|
+ WebElement cfmBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/confirm_btn");
|
|
|
+ if (cfmBtn == null) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_ELEMENT_IS_NULL.getCode());
|
|
|
+ log.error("元素获取异常==>activity:{},id:{}", activity, "com.smile.gifmaker:id/confirm_btn");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ cfmBtn.click();
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getMobileCaptcha(String token, String mobile) throws Exception {
|
|
|
+ String msg = null;
|
|
|
+ int i = 0;
|
|
|
+ while (i < 20) {
|
|
|
+ i++;
|
|
|
+ if (msg != null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ msg = KuaimiUtil.getMessage(token, "2307", mobile);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("等待{}短信验证码", mobile);
|
|
|
+ Thread.sleep(5000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public WebElement getElementByType(AndroidDriver androidDriver, String type, String typeInfo) {
|
|
|
WebElement element = null;
|
|
|
try {
|
|
@@ -413,82 +601,6 @@ public class AppiumUtil {
|
|
|
return element;
|
|
|
}
|
|
|
|
|
|
- public void runTaskV2(AndroidDriver androidDriver) throws Exception {
|
|
|
- System.out.println(androidDriver.getCurrentPackage() + ":" + androidDriver.currentActivity());
|
|
|
- //1:先打开快手
|
|
|
- Thread.sleep(5000L);
|
|
|
-
|
|
|
- System.out.println(androidDriver.currentActivity());
|
|
|
- WebElement checkElement = getElementByType(androidDriver, FIND_ELEMENT_TYPE_CLASS, "android.widget.CheckedTextView");
|
|
|
- if (null != checkElement) {
|
|
|
- checkElement.click();
|
|
|
- }
|
|
|
- //2:查询《发现》按钮,然后点击
|
|
|
- Thread.sleep(3000L);
|
|
|
- WebElement findElement = getElementByType(androidDriver, FIND_ELEMENT_TYPE_XPATH, "//android.view.View[@content-desc=\"发现\"]");
|
|
|
- if (null != findElement) {
|
|
|
- findElement.click();
|
|
|
- }
|
|
|
- //外层轮询
|
|
|
- boolean loopout = true;
|
|
|
- while (loopout) {
|
|
|
- //3:查询当前页面subjectList
|
|
|
- List<WebElement> list = getElementsByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/subject");
|
|
|
- //4:轮询subjectlist 查询广告
|
|
|
- for (WebElement element : list) {
|
|
|
- Thread.sleep(1000L);
|
|
|
- String subjectText = element.getText();
|
|
|
- //6:发现广告 点击广告
|
|
|
- if (null != subjectText && subjectText.equals("广告")) {
|
|
|
- Point point = element.getLocation();
|
|
|
- tapPoint(androidDriver, point.getX() - 10, point.getY() - 10);
|
|
|
- log.info("x:{};y:{}", point.getX() - 10, point.getY() - 10);
|
|
|
- Thread.sleep(1000L);
|
|
|
- //7:上划页面 查询广告主名称
|
|
|
- swipeToUp(androidDriver);
|
|
|
- Thread.sleep(1000L);
|
|
|
- WebElement label = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/label");
|
|
|
- if (null != label) {
|
|
|
- String text = label.getText();
|
|
|
- if (null != text && text.startsWith("土巴兔")) {
|
|
|
- //表示广告筛选成功
|
|
|
- WebElement installElement = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/ad_simplified_style_enhanced_ad_install_text");
|
|
|
- if (null != installElement) {
|
|
|
- installElement.click();
|
|
|
- return;
|
|
|
- }
|
|
|
- System.out.println("install元素查询失败");
|
|
|
- WebElement downloadElement = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/ad_download_text");
|
|
|
- if (null != downloadElement) {
|
|
|
- downloadElement.click();
|
|
|
- for (int i = 0; i < 60; i++) {
|
|
|
- Thread.sleep(10000L);
|
|
|
- WebElement okButton = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.android.packageinstaller:id/ok_button");
|
|
|
- if (null != okButton) {
|
|
|
- okButton.click();
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- Thread.sleep(3000L);
|
|
|
- WebElement launchButton = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.android.packageinstaller:id/launch_button");
|
|
|
- if (null != launchButton) {
|
|
|
- launchButton.click();
|
|
|
- break;
|
|
|
- }
|
|
|
- return;
|
|
|
- }
|
|
|
- System.out.println("download元素查询失败");
|
|
|
- }
|
|
|
- }
|
|
|
- backToMain(androidDriver);
|
|
|
- Thread.sleep(1000L);
|
|
|
- }
|
|
|
- }
|
|
|
- swipeToUp(androidDriver);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
public void checkActivity(AndroidDriver androidDriver) {
|
|
|
try {
|
|
|
Thread.sleep(2000L);
|
|
@@ -507,7 +619,6 @@ public class AppiumUtil {
|
|
|
WebElement backButton = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_tv");
|
|
|
if (null != backButton) {
|
|
|
backButton.click();
|
|
|
-
|
|
|
}
|
|
|
//悬浮层??我知道了
|
|
|
WebElement positive = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/positive");
|
|
@@ -521,7 +632,77 @@ public class AppiumUtil {
|
|
|
negativeElement.click();
|
|
|
}
|
|
|
}
|
|
|
- public void runTask(AndroidDriver androidDriver, AppiumTaskItem appiumTaskItem, WebElement loopElement) throws Exception {
|
|
|
+
|
|
|
+ public Map<String, Object> runLoginTask(AndroidDriver androidDriver, AppiumTaskItem appiumTaskItem, Map<String, Object> result) throws Exception {
|
|
|
+ Integer code = (Integer) result.get("code");
|
|
|
+ if (null != code && code != StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode()) {
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ Thread.sleep(1000L);
|
|
|
+ String findKey = appiumTaskItem.getFindKey();
|
|
|
+ if (findKey.equals("exit")) {
|
|
|
+ androidDriver.quit();
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_EXIT.getCode());
|
|
|
+ log.error(StatusCode.KUAISHOU_CRAWLER_APP_EXIT.getDesc());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //1:获取元素信息
|
|
|
+ WebElement element = getElementByType(androidDriver, appiumTaskItem.getFindType(), appiumTaskItem.getFindKey());
|
|
|
+ if (null == element) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_ELEMENT_IS_NULL.getCode());
|
|
|
+ log.error("元素获取异常==>activity:{},key:{}", appiumTaskItem.getAppActivity(), "com.smile.gifmaker:id/confirm_btn");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //(1):滑动效果
|
|
|
+ String swipeType = appiumTaskItem.getSwapType();
|
|
|
+ if (null != swipeType && !"".equals(swipeType.trim())) {
|
|
|
+ swipeByType(androidDriver, swipeType);
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ //点击效果
|
|
|
+ String clickType = appiumTaskItem.getClickType();
|
|
|
+ if (null != clickType && !"".equals(clickType)) {
|
|
|
+ String getText = oprateElementByType(element, clickType, androidDriver, appiumTaskItem);
|
|
|
+ if (null != getText && !"".equals(getText)) {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_TASK_END.getCode());
|
|
|
+ result.put("kuaishouId", getText.replace("快手 ID:", ""));
|
|
|
+ } else {
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ ResultMapUtils.setResultMap(result, StatusCode.KUAISHOU_CRAWLER_APP_SUCCESS.getCode());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String oprateElementByType(WebElement element, String clickType, AndroidDriver androidDriver, AppiumTaskItem taskItem) {
|
|
|
+ String getText = null;
|
|
|
+ if ("element".equals(clickType)) {
|
|
|
+ element.click();
|
|
|
+ } else if ("point".equals(clickType)) {
|
|
|
+ Point point = element.getLocation();
|
|
|
+ System.out.println(point.getX() + ":" + point.getY());
|
|
|
+ Integer x = point.getX();
|
|
|
+ Integer y = point.getY();
|
|
|
+ if (null != taskItem.getOffsiteX()) {
|
|
|
+ x = taskItem.getOffsiteX();
|
|
|
+ }
|
|
|
+ if (null != taskItem.getOffsiteY()) {
|
|
|
+ y = taskItem.getOffsiteY();
|
|
|
+ }
|
|
|
+ tapPoint(androidDriver, x, y);
|
|
|
+ } else if (clickType.equals("send")) {
|
|
|
+ String text = taskItem.getTextEqualKey();
|
|
|
+ element.sendKeys(text);
|
|
|
+ } else if (clickType.equals("text")) {
|
|
|
+ getText = element.getText();
|
|
|
+ }
|
|
|
+ return getText;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String runTask(AndroidDriver androidDriver, AppiumTaskItem appiumTaskItem, WebElement loopElement) throws Exception {
|
|
|
+ String getText = null;
|
|
|
if (appiumTaskItem != null) {
|
|
|
System.out.println(new Gson().toJson(appiumTaskItem));
|
|
|
if (appiumTaskItem.getWaitTime() != null && appiumTaskItem.getWaitTime() > 0) {
|
|
@@ -541,16 +722,16 @@ public class AppiumUtil {
|
|
|
if (appiumTaskItem.getTextEqualType() != null) {
|
|
|
if (appiumTaskItem.getTextEqualType().equals("eq")) {
|
|
|
if (!element.getText().equals(appiumTaskItem.getTextEqualKey())) {
|
|
|
- return;
|
|
|
+ return getText;
|
|
|
}
|
|
|
} else if (appiumTaskItem.getTextEqualType().equals("neq")) {
|
|
|
if (element.getText() == null || element.getText().equals(appiumTaskItem.getTextEqualKey())) {
|
|
|
- return;
|
|
|
+ return getText;
|
|
|
}
|
|
|
} else if (appiumTaskItem.getTextEqualType().equals("start")) {
|
|
|
boolean check = checkAdvertiser(androidDriver, appiumTaskItem.getTextEqualKey());
|
|
|
if (!check) {
|
|
|
- return;
|
|
|
+ return getText;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -559,7 +740,13 @@ public class AppiumUtil {
|
|
|
element.click();
|
|
|
} else if (appiumTaskItem.getClickType().equals("point")) {
|
|
|
Point point = element.getLocation();
|
|
|
+ System.out.println(point.getX() + ":" + point.getY());
|
|
|
tapPoint(androidDriver, point.getX() + appiumTaskItem.getOffsiteX(), point.getY() + appiumTaskItem.getOffsiteY());
|
|
|
+ } else if (appiumTaskItem.getClickType().equals("send")) {
|
|
|
+ String text = appiumTaskItem.getTextEqualKey();
|
|
|
+ element.sendKeys(text);
|
|
|
+ } else if (appiumTaskItem.getClickType().equals("text")) {
|
|
|
+ getText = element.getText();
|
|
|
}
|
|
|
}
|
|
|
List<AppiumTaskItem> subTask = appiumTaskItem.getSubList();
|
|
@@ -575,7 +762,6 @@ public class AppiumUtil {
|
|
|
Thread.sleep(appiumTaskItem.getLoopRate());
|
|
|
}
|
|
|
runTask(androidDriver, appiumTaskItem, element);
|
|
|
- return;
|
|
|
}
|
|
|
//非必须执行情况下
|
|
|
if (appiumTaskItem.getClickType() != null && appiumTaskItem.getClickType().equals("point")) {
|
|
@@ -618,6 +804,7 @@ public class AppiumUtil {
|
|
|
this.isLoop = false;
|
|
|
}
|
|
|
}
|
|
|
+ return getText;
|
|
|
}
|
|
|
|
|
|
public void backToMain(AndroidDriver androidDriver) {
|