In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
Effect picture:
Code:
Package com.rpoter
Import java.io.File
Import java.io.FileWriter
Import java.io.IOException
Import java.nio.file.Files
Import java.nio.file.Paths
Import java.nio.file.StandardOpenOption
Import java.text.SimpleDateFormat
Import java.util.Calendar
Import java.util.Date
Import java.util.List
Import java.util.Map
Import java.util.Set
Import org.testng.IReporter
Import org.testng.ISuite
Import org.testng.ISuiteResult
Import org.testng.ITestContext
Import org.testng.ITestResult
Import org.testng.reporters.HtmlHelper
Import org.testng.xml.XmlSuite
Public class Reporter implements IReporter {
Private String reportPath
/ * Mobile phone model * /
Private String Mobile_phone = "Xiaomi Mobile phone"
/ * * Test package name * /
Private String package_name = "com.systoon.beijingtoon"
/ * * version number * /
Private String versionName = "1.8.1"
/ * * Mobile system version * /
Private String MobileSystem = "Android 5.6"
/ * through * /
Public int Passed = 0
/ * failed * /
Public int Failed = 0
/ * * Skip * /
Public int Skipped = 0
/ * Total use cases * /
Public int CountNum = 0
/ * * pass the result * /
Public String PassgetName PassgetName
/ * * start time * /
Public Date StartDate
/ * end time * /
Public Date EndDate
@ Override
Public void generateReport (List xmlSuites, List suites, String outputDirectory) {
File htmlReportDir = new File ("test-output/Test-report")
If (! htmlReportDir.exists ()) {
HtmlReportDir.mkdirs ()
}
String reportName = formateDate () + ".html"
ReportPath = htmlReportDir + "/" + reportName
File report = new File (htmlReportDir, reportName)
If (report.exists ()) {
Try {
Report.createNewFile ()
} catch (IOException e) {
E.printStackTrace ()
}
}
StringBuffer sb = new StringBuffer ()
String title = "UI Automation Test case run result list"
Sb.append ("\ nUI Automated Test report")
.append (HtmlHelper.getCssString ("."))
.append ("\ n")
.append (") .append (title) .append ("
\ n ")
.append ("")
.append ("Mobile Brand name Mobile system version Test package name version number passes the number of failures skip the total start time and end time\ n")
String res = sb.toString ()
Try {
Files.write (Paths.get (reportPath)), res.getBytes ("utf-8"))
} catch (IOException e) {
E.printStackTrace ()
}
StringBuilder sb1 = new StringBuilder ()
For (ISuite suite: suites) {
Map tests = suite.getResults ()
For (ISuiteResult r: tests.values ()) {
ITestContext overview = r.getTestContext ()
System.err.println ("suite:" + overview.getName ())
System.err.println ("Stard Time:" + overview.getStartDate ())
StartDate = overview.getStartDate ()
System.err.println ("End Time:" + overview.getEndDate ())
EndDate = overview.getEndDate ()
CountNum = overview.getAllTestMethods () .length
System.err.println ("all methods num:" + overview.getAllTestMethods () .length)
/ / passed
Passed = overview.getPassedTests () .size ()
System.err.println ("passed:" + overview.getPassedTests () .size ())
Set passedSet = overview.getPassedTests () .getAllResults ()
For (ITestResult p: passedSet) {
System.err.println ("class:" + p.getTestClass () .getName () + "| method:" + p.getName ())
}
/ / failed
Failed = overview.getFailedTests () .size ()
System.err.println ("failed:" + overview.getFailedTests () .size ())
Set failedSet = overview.getFailedTests () .getAllResults ()
For (ITestResult f: failedSet) {
System.err.println ("class:" + f.getTestClass () .getName () + "| method:" + f.getName () + "| error:" + f.getThrowable ())
}
/ / skipped
Skipped = overview.getSkippedTests () .size ()
System.err.println ("skipped:" + overview.getSkippedTests () .size ())
Set skippedSet = overview.getSkippedTests () .getAllResults ()
For (ITestResult s: skippedSet) {
System.err.println ("- -" + s.getName ())
System.err.println (s.getThrowable ())
}
System.err.println ("=")
}
}
String reportN = "/" + formateDate () + "index" + ".html"
Sb1.append ("" + Mobile_phone+ "" + MobileSystem+ "" + versionName+ "" + package_name+ "")
Sb1.append ("" + Passed+ "" + Failed+ "" + Skipped+ "" + CountNum+ "" + StartDate+ "" + EndDate+ "\ n")
Sb1.append ("")
.append ("")
.append ("")
.append ("+" execution use case: "+ CountNum+")
.append ("")
.append ("details")
.append ("")
.append ("screenshot of serial number profile use case class name details\ n")
/ * * number of detailed passes * /
For (ISuite suite: suites) {
Map tests = suite.getResults ()
For (ISuiteResult r: tests.values ()) {
ITestContext overview = r.getTestContext ()
CountNum = overview.getAllTestMethods () .length
Set passedSet = overview.getPassedTests () .getAllResults ()
Int iTunes 0
For (ITestResult p: passedSet) {
System.err.println ("class:" + p.getTestClass () .getName () + "| method:" + p.getName ())
P***esuTmp = p.getTestClass () .getName ()
PassgetName = p.getName ()
Sb1.append ("+ I +" pass through "+ Packers accounts" Tmp+ "+" details: "+ PassgetName+" pass number without screenshot ")
ITunes +
}
}
}
Sb1.append ("screenshot of serial number profile use case class name details\ n")
/ * * detailed number of failures * /
For (ISuite suite: suites) {
Map tests = suite.getResults ()
For (ISuiteResult r: tests.values ()) {
ITestContext overview = r.getTestContext ()
CountNum = overview.getAllTestMethods () .length
Int iTunes 0
Set failedSet = overview.getFailedTests () .getAllResults ()
For (ITestResult f: failedSet) {
System.err.println ("class:" + f.getTestClass () .getName () + "| method:" + f.getName () + "| error:" + f.getThrowable ())
Sb1.append ("+ I +" failure "+ f.getTestClass (). GetName () +" + "test method name:" + f.getName () + "failure details:" + f.getThrowable () + "screenshot path:")
ITunes +
}
}
}
Sb1.append ("screenshot of serial number profile use case class name details\ n")
/ * * detailed number of skips * /
For (ISuite suite: suites) {
Map tests = suite.getResults ()
For (ISuiteResult r: tests.values ()) {
ITestContext overview = r.getTestContext ()
CountNum = overview.getAllTestMethods () .length
Set skippedSet = overview.getSkippedTests () .getAllResults ()
Int iTunes 0
For (ITestResult s: skippedSet) {
System.err.println ("- -" + s.getName ())
System.err.println (s.getThrowable ())
Sb1.append ("+ I +" skip "+ s.getName () +" + "details:" + s.getThrowable () + "this use case skips without screenshots")
ITunes +
}
}
}
Sb1.append ("")
Sb1.append ("Automated Test Department\ n")
String res1 = sb1.toString ()
Try {
Files.write ((Paths.get (reportPath)), res1.getBytes ("utf-8"), StandardOpenOption.APPEND)
FileWriter writer = new FileWriter (". / / test-output//results.txt", false)
Writer.write (Passed+ ":")
Writer.write (Failed+ ":")
Writer.write (Skipped+ "")
Writer.close ()
} catch (IOException e) {
E.printStackTrace ()
}
}
Public static String formateDate () {
SimpleDateFormat sf = new SimpleDateFormat ("yyyy-MM-dd-HH-mm-ss")
Calendar cal = Calendar.getInstance ()
Date date = cal.getTime ()
Return sf.format (date)
}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.