AWS Device Farm.如何将测试用例后生成的自定义报告保存到我的本地空间 [英] AWS Device Farm.How can i save the custom report being generated after the test case into my local space

查看:15
本文介绍了AWS Device Farm.如何将测试用例后生成的自定义报告保存到我的本地空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AWS 设备群.我的测试脚本在本地系统上运行时按预期工作,并在本地系统中的指定路径生成报告.现在,当我在设备群中运行代码时,报告没有得到生成.我错过了什么吗?

这是我的测试代码,用于将测试用例写入 html 报告.

package testOutput;导入 java.io.File;导入 java.io.FileNotFoundException;导入 java.io.FileOutputStream;导入 java.io.IOException;导入 java.io.OutputStream;导入 java.io.OutputStreamWriter;导入 java.io.PrintWriter;导入 java.io.Writer;导入 java.text.DateFormat;导入 java.text.SimpleDateFormat;导入 java.util.Date;导入 java.util.List;导入 net.dongliu.apk.parser.ApkFile;导入 net.dongliu.apk.parser.bean.ApkMeta;导入报告.TestReportSteps;公共类 TestResultHtml {public static void WriteResultToHtml(List items, String getCurrentDateTime, String getCurrentTime) {试试 {String filePath="C:\\\\Appium\\\\app-qc-debug.apk";ApkFile apkFile = new ApkFile(new File(filePath));ApkMeta apkMeta = apkFile.getApkMeta();字符串版本=apkMeta.getVersionName();DateFormat df = new SimpleDateFormat("dd/MM/yy, HH:mm:ss");日期 dateobj = new Date();String currentDateTime = df.format(dateobj);StringBuilder 颜色 = new StringBuilder();StringBuilder status = new StringBuilder();//定义一个 HTML 字符串生成器StringBuilder actualResult = new StringBuilder();StringBuilder htmlStringBuilder = new StringBuilder();//附加 html 标题和标题htmlStringBuilder.append("<html><head><link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\"完整性=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"匿名\">\r\n"+ "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js\"integrity=\"sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1jUPVCoriVdlAy\""匿名\"></script><title>Appium Test </title></head>");//附加主体htmlStringBuilder.append("");//附加表//如果(计数== 0){htmlStringBuilder.append("");htmlStringBuilder.append("<tr><th style=\"background-color:#a6a6a6\">Date Time</th><td>"+ 当前日期时间+ "</td><th style=\"background-color:#a6a6a6\">环境测试</th><td>QC</td></tr>"+ "<tr><th style=\"background-color:#a6a6a6\">OS</th><td>Android</td><th style=\"background-color:#a6a6a6\">应用程序</th><td>app-qc-debug.apk</td></tr>"+ "<tr><th style=\"background-color:#a6a6a6\">脚本名称</th><td colspan=\""+ 3+ "\">Cityvan 工作流程"+ "<th style=\"background-color:#a6a6a6\">Build Version</th><td>"+Version+"</td></tr><tr><thstyle=\"background-color:#a6a6a6\">Objective</th><td colspan=\""+ 3 + "\">验证 cityvan 应用程序是否按预期工作</td><tr><tr></table>");}//追加行htmlStringBuilder.append("<table class=\"table table-striped\">");htmlStringBuilder.append("<thead style=\"background-color:#007acc\"><tr><th><b>TestObjective</b></th><th><b>StepName</b></th><th><b>StepDescription</b></th><th><b>预期结果</b></th><th<b>实际结果</b></th><th><b>状态</b></th><th><b>屏幕截图</b></th</tr>");//追加行for (TestReportSteps a : items) {如果 (!a.getActualResultFail().isEmpty()) {status.append("失败");color.append("红色");actualResult.append(a.getActualResultFail());} 别的 {status.append("通过");color.append("绿色");actualResult.append(a.getActualResultPass());}如果 (a.getScreenshotPath()!=null){htmlStringBuilder.append("<tr><td>" + a.getTestObjective() + "</td><td>" + a.getStepName()+ "</td><td>"+ a.getStepDescription() + "</td><td>"+ a.getExpectedResult() + "</td><td>"+ actualResult + "</td><td style=\"color:" + color + ";font-weight:bold;\">"+ 状态+ "</td><td><a href=\"" + a.getScreenshotPath() + "\">点击这里</a></td></tr>");}别的{htmlStringBuilder.append("<tr><td style=\"font-weight:bold\">" + a.getTestObjective() + "</td><td>"+ a.getStepName() + "</td><td>"+ a.getStepDescription() + "</td><td>"+ a.getExpectedResult() + "</td><td>"+ actualResult + "</td><td style=\"color:" + color+ ";font-weight:bolder;\">" + status + "</td><td></td></tr>");}actualResult.delete(0, actualResult.length());color.delete(0, color.length());status.delete(0, status.length());}//关闭html文件htmlStringBuilder.append("</tbody></table></body></html>");//将 html 字符串内容写入文件String htmlFilepath = "";htmlFilepath = "D:\\FinalAppiumWorkspace\\AppiumMavenProject2\\src\\test\\java\\testOutput\\HtmlReport\\" + getCurrentDateTime + "\\testfile"+ getCurrentTime + "\\testfile.html";WriteToFile(htmlStringBuilder.toString(), htmlFilepath);} catch (IOException e) {e.printStackTrace();}}public static void WriteToFile(String fileContent, String fileName) 抛出 IOException, FileNotFoundException {文件文件 = 新文件(文件名);file.getParentFile().mkdirs();PrintWriter out = null;如果 (file.exists() && !file.isDirectory()){out = new PrintWriter(new FileOutputStream(new File(fileName), true));out.append(fileContent);关闭();} 别的{//使用 OutputStreamWriter 写入文件OutputStream outputStream = new FileOutputStream(file.getAbsoluteFile(), false);Writer writer = new OutputStreamWriter(outputStream);writer.write(fileContent);writer.close();}}}

<小时>

解决方案

代码引用的路径在场的设备主机中不存在.用于 android 测试的设备主机是一台 Linux 机器,根据我的经验,我们可以访问 tmp 目录.通过使用

睾丸完成后,您应该会看到 customer artifacts 的链接.

此外,您可能对测试报告的其他选项感兴趣,例如

而不是从头开始编写自己的.

HTH

-詹姆斯

I am working with AWS device farm.My test script when run on my local system works as expected and generates a report in my local system at specified path.Now when i run the code in the device farm the report does not get generated.Am i missing something?

This is my test code to write the test cases to a html report.

package testOutput;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.ApkMeta;
import report.TestReportSteps;

public class TestResultHtml {
    public static void WriteResultToHtml(List<TestReportSteps> items, String getCurrentDateTime, String getCurrentTime) {
        try {String filePath="C:\\\\Appium\\\\app-qc-debug.apk";
     ApkFile apkFile = new ApkFile(new File(filePath));
        ApkMeta apkMeta = apkFile.getApkMeta();

        String Version=apkMeta.getVersionName();
            DateFormat df = new SimpleDateFormat("dd/MM/yy, HH:mm:ss");
            Date dateobj = new Date();
            String currentDateTime = df.format(dateobj);

            StringBuilder color = new StringBuilder();
            StringBuilder status = new StringBuilder();
            // define a HTML String Builder
            StringBuilder actualResult = new StringBuilder();
            StringBuilder htmlStringBuilder = new StringBuilder();
            // append html header and title
            htmlStringBuilder.append(
                    "<html><head><link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css\" integrity=\"sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm\" crossorigin=\"anonymous\">\r\n"
                            + "<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js\" integrity=\"sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl\" crossorigin=\"anonymous\"></script><title>Appium Test </title></head>");
            // append body
            htmlStringBuilder.append("<body>");
            // append table
            //if (count == 0) 
            {
                htmlStringBuilder.append("<table class=\"table table-striped table-bordered\">");
                htmlStringBuilder.append("<tr><th style=\"background-color:#a6a6a6\">Date Time</th><td>"
                        + currentDateTime
                        + "</td><th style=\"background-color:#a6a6a6\">Environment Tested</th><td>QC</td></tr>"
                        + "<tr><th style=\"background-color:#a6a6a6\">OS</th><td>Android</td><th style=\"background-color:#a6a6a6\">Application</th><td>app-qc-debug.apk</td></tr>"
                        + "<tr><th style=\"background-color:#a6a6a6\">Script Name</th><td colspan=\""
                        + 3
                        + "\">Cityvan Workflow</td>"
                        + "<th style=\"background-color:#a6a6a6\">Build Version</th><td>"+Version+"</td></tr><tr><th style=\"background-color:#a6a6a6\">Objective</th><td colspan=\""
                        + 3 + "\">To verify that cityvan app is working as expected</td><tr><tr></table>");
            }
            // append row
            htmlStringBuilder.append("<table class=\"table table-striped\">");
            htmlStringBuilder.append(
                    "<thead style=\"background-color:#007acc\"><tr><th><b>TestObjective</b></th><th><b>StepName</b></th><th><b>StepDescription</b></th><th><b>ExpectedResult</b></th><th><b>ActualResult</b></th><th><b>Status</b></th><th><b>Screenshot</b></th></tr></thead><tbody>");
            // append row
            for (TestReportSteps a : items) {

                if (!a.getActualResultFail().isEmpty()) {
                    status.append("Fail");
                    color.append("red");
                    actualResult.append(a.getActualResultFail());
                } else {
                    status.append("Pass");
                    color.append("green");
                    actualResult.append(a.getActualResultPass());
                }
                if (a.getScreenshotPath()!=null) 
                {
                    htmlStringBuilder.append("<tr><td>" + a.getTestObjective() + "</td><td>" + a.getStepName()
                            + "</td><td>" + a.getStepDescription() + "</td><td>" + a.getExpectedResult() + "</td><td>"
                            + actualResult + "</td><td style=\"color:" + color + ";font-weight:bolder;\">" + status
                            + "</td><td><a href=\"" + a.getScreenshotPath() + "\">Click here</a></td></tr>");
                }
                else 
                {
                    htmlStringBuilder.append("<tr><td style=\"font-weight:bold\">" + a.getTestObjective() + "</td><td>"
                            + a.getStepName() + "</td><td>" + a.getStepDescription() + "</td><td>"
                            + a.getExpectedResult() + "</td><td>" + actualResult + "</td><td style=\"color:" + color
                            + ";font-weight:bolder;\">" + status + "</td><td></td></tr>");
                }
                actualResult.delete(0, actualResult.length());
                color.delete(0, color.length());
                status.delete(0, status.length());
            }
            // close html file
            htmlStringBuilder.append("</tbody></table></body></html>");

            // write html string content to a file
            String htmlFilepath = "";

            htmlFilepath = "D:\\FinalAppiumWorkspace\\AppiumMavenProject2\\src\\test\\java\\testOutput\\HtmlReport\\" + getCurrentDateTime + "\\testfile"
                    + getCurrentTime + "\\testfile.html";

            WriteToFile(htmlStringBuilder.toString(), htmlFilepath);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void WriteToFile(String fileContent, String fileName) throws IOException, FileNotFoundException {

        File file = new File(fileName);
        file.getParentFile().mkdirs();

        PrintWriter out = null;
        if (file.exists() && !file.isDirectory()) 
        {
            out = new PrintWriter(new FileOutputStream(new File(fileName), true));
            out.append(fileContent);
            out.close();
        } else 
        {
            // write to file with OutputStreamWriter
            OutputStream outputStream = new FileOutputStream(file.getAbsoluteFile(), false);
            Writer writer = new OutputStreamWriter(outputStream);
            writer.write(fileContent);
            writer.close();
        }
    }
}


解决方案

The path the code is referencing doesn't exist in the device host for the farm. The Device Host for android tests is a Linux machine and from my experience we have access to the tmp directory. By using the custom artifacts feature of Device Farm and the tmp directory this should be possible. Try changing the path to the html file to:

htmlFilepath = "/tmp/reports/testfile.html";

Then, using the web console, explicitly mark that directory to be exported.

Once the testes finish, you should see a link for customer artifacts.

Additionally, you may be interested in other options for test reports like

rather than writing your own from scratch.

HTH

-James

这篇关于AWS Device Farm.如何将测试用例后生成的自定义报告保存到我的本地空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆