Exemple #1
0
    def startTest(self, test):
        self.a.retry_connection()
        self.a.push(self.option.jarpath)
        self.test_number += 1
        test.id = '%04d' % self.test_number
        test.logDirectory = os.path.join(self.report_dir, test.id)

        @hook(log)
        def log_directory():
            return test.id

        try:
            os.mkdir(test.logDirectory)
        except:
            log.error('mkdir log directory (%s) failed' % test.logDirectory)

        self.clearLog()
        self.running_process = [
            self.a.popen(command,
                         stdout=open(os.path.join(test.logDirectory, filename),
                                     "a+"))
            for command, filename in LOGCAT_RUNTEST
        ]
        print "running: %s" % (test.uicommand())
        runner = self.a.popen("uiautomator runtest %s" % (test.uicommand()),
                              stdout=open(
                                  os.path.join(test.logDirectory,
                                               log.uiautomator()), "a+"))
        runner.wait()
        title, steps, runtime, info, output, result = self.__captureResult(
            os.path.join(test.logDirectory, log.uiautomator()))
        print result, "\n"
        test.title = title
        test.result = result
        test.runtime = runtime
        test.steps += steps
        test.output += output
        if info != []: test.errorinfo = info

        self.__stopTest(test)
Exemple #2
0
    def startTest(self, test):
        self.test_number += 1
        test.logDirectory = '%03d' %self.test_number
        try:
            os.mkdir(os.path.join(self.report_dir, test.logDirectory))
        except:
            log.error('mkdir log directory (%s) failed' %os.path.join(self.report_dir, test.logDirectory))

        self.clearLog()
        self.running_process = [self.a.popen(command,stdout=open(os.path.join(os.path.join(self.report_dir, test.logDirectory),filename), "a+")) for command, filename in LOGCAT_RUNTEST]
        print "running: %s" %(test.uicommand())
        runner = self.a.popen("uiautomator runtest %s" %(test.uicommand()),stdout=open(os.path.join(os.path.join(self.report_dir, test.logDirectory), log.uiautomator()),"a+"))
        runner.wait()
        result, runtime, timecount, info, output = self.__captureResult(os.path.join(os.path.join(self.report_dir, test.logDirectory), log.uiautomator()))
        print result,"\n"
        test.name=test.getTestName()
        test.result = result
        test.runtime = runtime
        test.timecount = timecount
        test.output += output
        if info != []:test.errorinfo = info

        self.__stopTest(test, result)
        self.__exec('display.py')
Exemple #3
0
def HtmlReport(suitetest, dictt):
    """generator html report for all testcases """

    TOTAL = 0
    SUCCESS = 0
    FAILED = 0
    ERROR = 0
    for test in suitetest:
        if test.result == "PASS":
            SUCCESS += 1
        elif test.result == "FAIL":
            FAILED += 1
        elif test.result == "ERROR":
            ERROR += 1
    TOTAL = len(suitetest)
    DEVICE = dictt.get('device')
    VERSION = dictt.get('version')
    PRODUCT = dictt.get('product')
    APK = dictt.get('apk')
    PACKAGE = dictt.get('apkPkg')

    f = open(os.path.join(dictt.get('runner').report_dir, 'index.html'), 'w')
    try:
        def output(s):
            f.write(s + '\n')
            s = re.sub(r'<.*?>', '', s)
            #if s != '': print (s)
        output('<html>')
        output('<head>')
        output('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />')
        output('<style type="text/css">')
        output('html{background:#D2D460;text-align:center;}')
        output('body{width:800px;margin:0 auto;background:#fff;text-align:left;}')
        output('.summary {width:650px; float:left;}')
        output('.meminfo {width:150px; float:left; margin-right:-150px;}')
        output('</style>')
        output('</head>')

        output('<body>')
        output('<div class="summary">')
        output('<table width="650" border="0" >')
        output('<tr style="background-color:PowderBlue;text-align:center;"><td colspan="2"><h1>AutoTest Summary Result</h1></td></tr>')
        output('<tr style="background-color:PowderBlue;"><td><h3>APK</h3></td><td><h3>%s</h3></td></tr>'%APK)
        output('<tr style="background-color:PowderBlue;"><td><h3>Package</h3></td><td><h3>%s</h3></td></tr>'%PACKAGE)
        output('<tr style="background-color:PowderBlue;"><td><h3>Id</h3></td><td><h3>%s</h3></td></tr>'%DEVICE)
        output('<tr style="background-color:PowderBlue;"><td><h3>Product</h3></td><td><h3>%s</h3></td></tr>'%PRODUCT)
        output('<tr style="background-color:PowderBlue;"><td><h3>SDK</h3></td><td><h3>%s</h3></td></tr>'%VERSION)
        output('<tr style="background-color:PowderBlue;"><td><h3>Total</h3></td><td><h3>%s</h3></td></tr>'%TOTAL)
        output('<tr style="background-color:green;"><td><h3>Pass</h3></td><td><h3>%s</h3></td></td></tr>'%SUCCESS)
        output('<tr style="background-color:red;"><td><h3>Fail</h3></td><td><h3>%s</h3></td></tr>'%FAILED)
        output('<tr style="background-color:yellow;"><td><h3>Error</h3></td><td><h3>%s</h3></td></tr>'%ERROR)
        output('</table>')
        output('</div>')

        output('<div class="meminfo">')
        output('<br/><br/><br/><br/>')
        output('<h3>内存信息:</h3>')
        output('<a href="%s">Total_Pss</a><br/><br/>' %log.total_pss())
        output('<a href="%s">Top_10_Pss</a>' %log.top_10_pss())
        output('</div>')


        output('<br />')

        output('<table heigh="500" width="800" border="0">')
        output('<tr style="background-color:PowderBlue;text-align:center;"><td colspan="5"><h1>AutoTest Detail Result</h1></td></tr>')
        output('<tr style="background-color:PowderBlue;">')
        output('<td><h3>%5s</h3></td> <td><h3>%-80s</h3></td> <td><h3>%-10s</h3></td> <td><h3>%-6s</h3></td> <td><h3>%-10s</h3></td>' %
            ('ID', 'Test Name', 'ExecuteTime(s)', 'Result', 'TimeCount(ms)'))
        output('</tr>')
        for s in suitetest:
            output('<tr style="background-color:PowderBlue;height:40px;">')
            if(s.result == 'FAIL'):
                caseName = s.name.split("#")[1]
                #print('casename=%s'%caseName)
                failPhoto=s.logDirectory+'/'+caseName+'.png'
                #print('failPhoto=%s'%failPhoto)
                output('<td>%05s</td> <td><a href="%s">%-80s</a></td> <td>%-10s</td> <td><a href="%s">%s</a></td> <td>%-10s</td>' %(
                    os.path.basename(s.logDirectory), os.path.join(s.logDirectory, log.uiautomator()), ','.join(s.names), s.runtime, failPhoto, s.result, s.timecount
                    ))
            else:
                output('<td>%05s</td> <td><a href="%s">%-80s</a></td> <td>%-10s</td> <td>%s</td> <td>%-10s</td>' %(
                    os.path.basename(s.logDirectory), os.path.join(s.logDirectory, log.uiautomator()), ','.join(s.names), s.runtime, s.result, s.timecount
                    ))
            output('</tr>')

            """
            #display
            if os.path.exists(os.path.join(s.resultDirectory, s.logDirectory, "display.txt")):
                output('<tr style="background-color:#EE7600">')
                output('<td colspan="4">')
                with open(os.path.join(s.resultDirectory, s.logDirectory, "display.txt")) as fp:
                    for line in fp:
                        output("<div>"+line+"</div>")
                output("</td>")
                output("</tr>")
            """

#             if s.output != []:
#                 output('<tr style="background-color:#EE7600">')
#                 output('<td colspan="5">')
#                 for line in s.output:
#                     output("<div>"+line+"</div>")
#                 output("</td>")
#                 output("</tr>")

            if s.errorinfo != "":
                output('<tr style="background-color:#EE7600">')
                output('<td colspan="5">')
                for line in s.errorinfo:
                    output("<div>"+line+"</div>")
                output("</td>")
                output("</tr>")

        output('</table>')
        output('</body>')
        output('</html>')

    except Exception, e:
        print e
Exemple #4
0
    def startTest(self, test):
        self.test_number += 1
        test.logDirectory = '%03d' %self.test_number
        try:
            os.mkdir(os.path.join(self.report_dir, test.logDirectory))
        except:
            log.error('mkdir log directory (%s) failed' %os.path.join(self.report_dir, test.logDirectory))

        self.clearLog()
        self.running_process = [self.a.popen(command,stdout=open(os.path.join(os.path.join(self.report_dir, test.logDirectory),filename), "a+")) for command, filename in LOGCAT_RUNTEST]
        print "running: %s" %(test.uicommand())
        runner = self.a.popen("uiautomator runtest %s" %(test.uicommand()),stdout=open(os.path.join(os.path.join(self.report_dir, test.logDirectory), log.uiautomator()),"a+"))
        runner.wait()
        result, runtime, info, output = self.__captureResult(os.path.join(os.path.join(self.report_dir, test.logDirectory), log.uiautomator()))
        print result,"\n"
        test.result = result
        test.runtime = runtime
        test.output += output
        if info != []:test.errorinfo = info

        self.__stopTest(test)
        self.__exec('display.py')
Exemple #5
0
def HtmlReport(suitetest, dictt):
    """generator html report for all testcases """

    TOTAL = 0
    SUCCESS = 0
    FAILED = 0
    ERROR = 0
    for test in suitetest:
        if test.result == "PASS":
            SUCCESS += 1
        elif test.result == "FAIL":
            FAILED += 1
        elif test.result == "ERROR":
            ERROR += 1
    TOTAL = len(suitetest)
    VERSION = dictt.get('version')
    PRODUCT = dictt.get('product')

    f = open(os.path.join(dictt.get('runner').report_dir, 'index.html'), 'w')
    try:
        def output(s):
            f.write(s + '\n')
            s = re.sub(r'<.*?>', '', s)
            #if s != '': print (s)
        output('<html>')
        output('<head>')
        output('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />')
        output('<style type="text/css">')
        output('html{background:#D2D460;text-align:center;}')
        output('body{width:800px;margin:0 auto;background:#fff;text-align:left;}')
        output('.summary {width:650px; float:left;}')
        output('.meminfo {width:150px; float:left; margin-right:-150px;}')
        output('</style>')
        output('</head>')

        output('<body>')
        output('<div class="summary">')
        output('<table width="650" border="0" >')
        output('<tr style="background-color:PowderBlue;text-align:center;"><td colspan="2"><h1>AutoSmoke Summary Result</h1></td></tr>')
        output('<tr style="background-color:PowderBlue;"><td><h3>Product</h3></td><td><h3>%s</h3></td></tr>'%PRODUCT)
        output('<tr style="background-color:PowderBlue;"><td><h3>Version</h3></td><td><h3>%s</h3></td></tr>'%VERSION)
        output('<tr style="background-color:PowderBlue;"><td><h3>Total</h3></td><td><h3>%s</h3></td></tr>'%TOTAL)
        output('<tr style="background-color:green;"><td><h3>Pass</h3></td><td><h3>%s</h3></td></td></tr>'%SUCCESS)
        output('<tr style="background-color:red;"><td><h3>Fail</h3></td><td><h3>%s</h3></td></tr>'%FAILED)
        output('<tr style="background-color:yellow;"><td><h3>Error</h3></td><td><h3>%s</h3></td></tr>'%ERROR)
        output('</table>')
        output('</div>')

        output('<div class="meminfo">')
        output('<br/><br/><br/><br/>')
        output('<h3>内存信息:</h3>')
        output('<a href="%s">Total_Pss</a><br/><br/>' %log.total_pss())
        output('<a href="%s">Top_10_Pss</a>' %log.top_10_pss())
        output('</div>')


        output('<br />')

        output('<table heigh="500" width="800" border="0">')
        output('<tr style="background-color:PowderBlue;text-align:center;"><td colspan="4"><h1>AutoSmoke Detail Result</h1></td></tr>')
        output('<tr style="background-color:PowderBlue;">')
        output('<td><h3>%5s</h3></td> <td><h3>%-80s</h3></td> <td><h3>%-10s</h3></td> <td><h3>%-6s</h3></td>' %
            ('ID', 'TEST NAME', 'EXECUTE TIME', 'RESULT'))
        output('</tr>')
        for s in suitetest:
            output('<tr style="background-color:PowderBlue;height:40px;">')
            output('<td>%05s</td> <td><a href="%s">%-80s</a></td> <td>%-10s</td> <td><a href="%s">%s</a></td>' %(
                os.path.basename(s.logDirectory), os.path.join(s.logDirectory, log.uiautomator()), ','.join(s.names), s.runtime, s.logDirectory, s.result
                ))
            output('</tr>')

            """
            #display
            if os.path.exists(os.path.join(s.resultDirectory, s.logDirectory, "display.txt")):
                output('<tr style="background-color:#EE7600">')
                output('<td colspan="4">')
                with open(os.path.join(s.resultDirectory, s.logDirectory, "display.txt")) as fp:
                    for line in fp:
                        output("<div>"+line+"</div>")
                output("</td>")
                output("</tr>")
            """

            if s.output != []:
                output('<tr style="background-color:#EE7600">')
                output('<td colspan="4">')
                for line in s.output:
                    output("<div>"+line+"</div>")
                output("</td>")
                output("</tr>")

            if s.errorinfo != "":
                output('<tr style="background-color:#EE7600">')
                output('<td colspan="4">')
                for line in s.errorinfo:
                    output("<div>"+line+"</div>")
                output("</td>")
                output("</tr>")

        output('</table>')
        output('</body>')
        output('</html>')

    except Exception, e:
        print e