|
@@ -86,13 +86,71 @@ public class AppiumUtil {
|
|
try {
|
|
try {
|
|
// AndroidDriver androidDriver = appiumUtil.initAndroidDriver("http://39.106.184.70:4723/wd/hub", "183.131.157.66:10005", "com.smile.gifmaker", "com.yxcorp.login.userlogin.QuickLoginActivity");
|
|
// AndroidDriver androidDriver = appiumUtil.initAndroidDriver("http://39.106.184.70:4723/wd/hub", "183.131.157.66:10005", "com.smile.gifmaker", "com.yxcorp.login.userlogin.QuickLoginActivity");
|
|
AndroidDriver androidDriver = appiumUtil.initAndroidDriver("http://39.106.184.70:4723/wd/hub", "183.131.157.66:10005", "com.smile.gifmaker", "com.yxcorp.gifshow.HomeActivity");
|
|
AndroidDriver androidDriver = appiumUtil.initAndroidDriver("http://39.106.184.70:4723/wd/hub", "183.131.157.66:10005", "com.smile.gifmaker", "com.yxcorp.gifshow.HomeActivity");
|
|
- appiumUtil.loginKuaishou(androidDriver);
|
|
|
|
|
|
+// appiumUtil.loginKuaishou(androidDriver);
|
|
|
|
+ appiumUtil.loginTask(androidDriver, null, null);
|
|
// appiumUtil.test(androidDriver);
|
|
// appiumUtil.test(androidDriver);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
-
|
|
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public Boolean loginTask(AndroidDriver androidDriver, String settoken, String setmobile) throws Exception {
|
|
|
|
+ Thread.sleep(5000);
|
|
|
|
+ String token = settoken;
|
|
|
|
+ String mobile = setmobile;
|
|
|
|
+ String pkg = androidDriver.getCurrentPackage();
|
|
|
|
+ String activity = androidDriver.currentActivity();
|
|
|
|
+ System.out.println("当前包:" + pkg);
|
|
|
|
+ System.out.println("当前activity:" + activity);
|
|
|
|
+ Boolean isContinue = true;
|
|
|
|
+ if (pkg.equals("com.android.packageinstaller")) {
|
|
|
|
+ switch (activity) {
|
|
|
|
+ case ".permission.ui.GrantPermissionsActivity":
|
|
|
|
+ WebElement permissionAllowBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.android.packageinstaller:id/permission_allow_button");
|
|
|
|
+ if (permissionAllowBtn != null) {
|
|
|
|
+ permissionAllowBtn.click();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case ".PackageInstallerActivity":
|
|
|
|
+ WebElement okBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.android.packageinstaller:id/ok_button");
|
|
|
|
+ if (okBtn != null) {
|
|
|
|
+ okBtn.click();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case ".InstallAppProgress":
|
|
|
|
+ WebElement centerText = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.android.packageinstaller:id/center_text");
|
|
|
|
+ WebElement doneBtn = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.android.packageinstaller:id/done_button");
|
|
|
|
|
|
|
|
+ if (centerText != null) {
|
|
|
|
+ System.out.println(centerText.getText());
|
|
|
|
+ }
|
|
|
|
+ if (doneBtn != null) {
|
|
|
|
+ doneBtn.click();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ isContinue = false;
|
|
|
|
+ System.out.println("当前activity无法处理");
|
|
|
|
+ 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 leftBtn1 = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/left_btn");
|
|
|
|
+ if (leftBtn1 != null) {
|
|
|
|
+ leftBtn1.click();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case "com.yxcorp.gifshow.HomeActivity":
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
|
|
|
|
public void test(AndroidDriver androidDriver) throws Exception {
|
|
public void test(AndroidDriver androidDriver) throws Exception {
|
|
@@ -780,7 +838,7 @@ public class AppiumUtil {
|
|
Thread.sleep(3000);
|
|
Thread.sleep(3000);
|
|
tapPoint(androidDriver, 650, 400);
|
|
tapPoint(androidDriver, 650, 400);
|
|
Thread.sleep(3000);
|
|
Thread.sleep(3000);
|
|
-// WebElement qrCode = getElementByType(androidDriver,"com.smile.gifmaker:id/qr_code_image");
|
|
|
|
|
|
+// WebElement qrCode = getElementById(androidDriver,"com.smile.gifmaker:id/qr_code_image");
|
|
// qrCode.click();
|
|
// qrCode.click();
|
|
WebElement kwid = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/kwai_id");
|
|
WebElement kwid = getElementByType(androidDriver, FIND_ELEMENT_TYPE_ID, "com.smile.gifmaker:id/kwai_id");
|
|
System.out.println(kwid.getText());
|
|
System.out.println(kwid.getText());
|
|
@@ -952,18 +1010,14 @@ public class AppiumUtil {
|
|
|
|
|
|
public WebElement getElementByType(AndroidDriver androidDriver, String type, String typeInfo) {
|
|
public WebElement getElementByType(AndroidDriver androidDriver, String type, String typeInfo) {
|
|
WebElement element = null;
|
|
WebElement element = null;
|
|
- try {
|
|
|
|
- if (type.equals(FIND_ELEMENT_TYPE_ID)) {
|
|
|
|
- element = androidDriver.findElementById(typeInfo);
|
|
|
|
- }
|
|
|
|
- if (type.equals(FIND_ELEMENT_TYPE_CLASS)) {
|
|
|
|
- element = androidDriver.findElementByClassName(typeInfo);
|
|
|
|
- }
|
|
|
|
- if (type.equals(FIND_ELEMENT_TYPE_XPATH)) {
|
|
|
|
- element = androidDriver.findElementByXPath(typeInfo);
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("元素不存在:findType:{},keywords:{}", type, typeInfo);
|
|
|
|
|
|
+ if (type.equals(FIND_ELEMENT_TYPE_ID)) {
|
|
|
|
+ element = androidDriver.findElementById(typeInfo);
|
|
|
|
+ }
|
|
|
|
+ if (type.equals(FIND_ELEMENT_TYPE_CLASS)) {
|
|
|
|
+ element = androidDriver.findElementByClassName(typeInfo);
|
|
|
|
+ }
|
|
|
|
+ if (type.equals(FIND_ELEMENT_TYPE_XPATH)) {
|
|
|
|
+ element = androidDriver.findElementByXPath(typeInfo);
|
|
}
|
|
}
|
|
return element;
|
|
return element;
|
|
}
|
|
}
|
|
@@ -1028,7 +1082,6 @@ public class AppiumUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public void runTask(AndroidDriver androidDriver, AppiumTaskItem appiumTaskItem, WebElement loopElement) throws Exception {
|
|
public void runTask(AndroidDriver androidDriver, AppiumTaskItem appiumTaskItem, WebElement loopElement) throws Exception {
|
|
- System.out.println(androidDriver.getCurrentPackage() + ":" + androidDriver.currentActivity());
|
|
|
|
if (appiumTaskItem != null) {
|
|
if (appiumTaskItem != null) {
|
|
System.out.println(new Gson().toJson(appiumTaskItem));
|
|
System.out.println(new Gson().toJson(appiumTaskItem));
|
|
if (appiumTaskItem.getWaitTime() != null && appiumTaskItem.getWaitTime() > 0) {
|
|
if (appiumTaskItem.getWaitTime() != null && appiumTaskItem.getWaitTime() > 0) {
|
|
@@ -1097,7 +1150,6 @@ public class AppiumUtil {
|
|
System.out.println("loop:" + isLoop);
|
|
System.out.println("loop:" + isLoop);
|
|
if (appiumTaskItem.getFindType() != null) {
|
|
if (appiumTaskItem.getFindType() != null) {
|
|
List<WebElement> list = getElementsByType(androidDriver, appiumTaskItem.getFindType(), appiumTaskItem.getFindKey());
|
|
List<WebElement> list = getElementsByType(androidDriver, appiumTaskItem.getFindType(), appiumTaskItem.getFindKey());
|
|
- ;
|
|
|
|
if (list != null && list.size() > 0) {
|
|
if (list != null && list.size() > 0) {
|
|
for (WebElement element : list) {
|
|
for (WebElement element : list) {
|
|
if (!isLoop) {
|
|
if (!isLoop) {
|
|
@@ -1141,18 +1193,12 @@ public class AppiumUtil {
|
|
|
|
|
|
private List<WebElement> getElementsByType(AndroidDriver androidDriver, String findType, String findKey) {
|
|
private List<WebElement> getElementsByType(AndroidDriver androidDriver, String findType, String findKey) {
|
|
List<WebElement> elements = null;
|
|
List<WebElement> elements = null;
|
|
- try {
|
|
|
|
- if (findType.equals(FIND_ELEMENT_TYPE_ID)) {
|
|
|
|
- elements = androidDriver.findElementsById(findKey);
|
|
|
|
- }
|
|
|
|
- if (findType.equals(FIND_ELEMENT_TYPE_CLASS)) {
|
|
|
|
- elements = androidDriver.findElementsByClassName(findKey);
|
|
|
|
- }
|
|
|
|
- if (findType.equals(FIND_ELEMENT_TYPE_XPATH)) {
|
|
|
|
- elements = androidDriver.findElementsByXPath(findKey);
|
|
|
|
- }
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("元素不存在:findType:{},keywords:{}", findType, findKey);
|
|
|
|
|
|
+ if (findType.equals(FIND_ELEMENT_TYPE_ID)) {
|
|
|
|
+ elements = androidDriver.findElementsById(findKey);
|
|
|
|
+ } else if (findType.equals(FIND_ELEMENT_TYPE_CLASS)) {
|
|
|
|
+ elements = androidDriver.findElementsByClassName(findKey);
|
|
|
|
+ } else if (findKey.equals(FIND_ELEMENT_TYPE_XPATH)) {
|
|
|
|
+ elements = androidDriver.findElementsByXPath(findKey);
|
|
}
|
|
}
|
|
return elements;
|
|
return elements;
|
|
}
|
|
}
|