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

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

问题描述

我正在使用AWS设备场.在本地系统上运行时,我的测试脚本可以按预期运行,并在本地系统中的指定路径上生成报告.现在在设备场中运行代码时,无法获得报告生成了.我想念什么吗?

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?

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();
        }
    }
}


推荐答案

服务器场的设备主机中不存在代码引用的路径.用于Android测试的设备主机是一台Linux计算机,根据我的经验,我们可以访问tmp目录.使用自定义工件功能设备服务器场和tmp目录应该可以.尝试将html文件的路径更改为:

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";

然后,使用Web控制台显式标记要导出的目录.

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

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

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

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

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

  • extent reports
  • Allure reports

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

rather than writing your own from scratch.

HTH

-詹姆斯

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

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