当前位置 : 主页 > 网络安全 > 测试自动化 >

appium自动化报表自定义并且截图-补充

来源:互联网 收集:自由互联 发布时间:2021-06-19
获取设备号 public static String formatDate(long date) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return formatter.format(date); }/** * get result of command, after execute dos command * 通过执行dos命
获取设备号
public static String formatDate(long date) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return formatter.format(date);
    }

/**
     * get result of command, after execute dos command
     * 通过执行dos命令获取结果
     *
     * @param :dos command,String
     * @return List<String>
     */
    public static List<String> execCmdConsole(String cmdString) {
        List<String> dosRes = new ArrayList<String>();
        Process process = null;
        try {
            LogUtil.info(cmdString);
            if (osName.toLowerCase().contains("mac")) {
                String[] command = {"/bin/sh", "-c", cmdString};
                process = Runtime.getRuntime().exec(command);
            } else if (osName.toLowerCase().contains("win")) {
                process = Runtime.getRuntime().exec("cmd /c " + cmdString);
            }
            InputStream in = process.getInputStream();
            BufferedReader inr = new BufferedReader(new InputStreamReader(in));
            String line = null;
            while ((line = inr.readLine()) != null) {
                dosRes.add(line);
            }
            try {
                process.waitFor();
                process.destroy();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            log.debug("get result of command after execute dos command " + cmdString + " Succeed ");
        } catch (IOException e) {
            log.error("get result of command after execute dos command " + cmdString + " Failure", e);
        }
        return dosRes;
    }

    /**
     * 获取手机版本
     *
     * @return
     */
    public static String getMobileModel() {
        /**
         * 获取手机版本
         */
        String mobileModel = "adb shell getprop ro.product.model";
        String s = OperationalCmd.execReturnAndWait(mobileModel);
        return s;
    }

    /**
     * 获取手机系统版本
     * 版本号
     *
     * @return
     */
    public static String getVersionNameInfo() {
        /**
         * 版本号
         */
        String versionName = "adb shell dumpsys package com.jingdong.th.app | findstr versionName";
        /**
         * 获取手机系统版本
         */
        String versionRelease = "adb shell getprop ro.build.version.release";
        List<String> devList = OperationalCmd.execCmdConsole(versionName);
        String s = devList.get(0).split("=")[1] + "/Android:" + OperationalCmd.execReturnAndWait(versionRelease);
        return s;
    }
网友评论