mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
feat: save json case to results directory
This commit is contained in:
@@ -22,6 +22,7 @@ const (
|
|||||||
SummaryFileName = "hrp_summary.json" // $PWD/results/20060102150405/hrp_summary.json
|
SummaryFileName = "hrp_summary.json" // $PWD/results/20060102150405/hrp_summary.json
|
||||||
LogFileName = "hrp.log" // $PWD/results/20060102150405/hrp.log
|
LogFileName = "hrp.log" // $PWD/results/20060102150405/hrp.log
|
||||||
ReportFileName = "report.html" // $PWD/results/20060102150405/report.html
|
ReportFileName = "report.html" // $PWD/results/20060102150405/report.html
|
||||||
|
CaseFileName = "case.json" // $PWD/results/20060102150405/case.json
|
||||||
|
|
||||||
// mobile device path
|
// mobile device path
|
||||||
DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
|
DeviceActionLogFilePath = "/sdcard/Android/data/io.appium.uiautomator2.server/files/hodor"
|
||||||
@@ -36,6 +37,7 @@ type Config struct {
|
|||||||
summaryFilePath string
|
summaryFilePath string
|
||||||
logFilePath string
|
logFilePath string
|
||||||
reportFilePath string
|
reportFilePath string
|
||||||
|
caseFilePath string
|
||||||
actionLogDirPath string
|
actionLogDirPath string
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
}
|
}
|
||||||
@@ -179,3 +181,17 @@ func (c *Config) ReportFilePath() string {
|
|||||||
c.reportFilePath = filepath.Join(c.resultsPathUnlocked(), ReportFileName)
|
c.reportFilePath = filepath.Join(c.resultsPathUnlocked(), ReportFileName)
|
||||||
return c.reportFilePath
|
return c.reportFilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// $PWD/results/20060102150405/case.json
|
||||||
|
func (c *Config) CaseFilePath() string {
|
||||||
|
c.mu.Lock()
|
||||||
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
|
if c.caseFilePath != "" {
|
||||||
|
return c.caseFilePath
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure directory creation and set cached path
|
||||||
|
c.caseFilePath = filepath.Join(c.resultsPathUnlocked(), CaseFileName)
|
||||||
|
return c.caseFilePath
|
||||||
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2506241700
|
v5.0.0-beta-2506241946
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/httprunner/funplugin"
|
"github.com/httprunner/funplugin"
|
||||||
"github.com/httprunner/httprunner/v5/code"
|
"github.com/httprunner/httprunner/v5/code"
|
||||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||||
|
"github.com/httprunner/httprunner/v5/internal/config"
|
||||||
"github.com/httprunner/httprunner/v5/internal/sdk"
|
"github.com/httprunner/httprunner/v5/internal/sdk"
|
||||||
"github.com/httprunner/httprunner/v5/internal/version"
|
"github.com/httprunner/httprunner/v5/internal/version"
|
||||||
"github.com/httprunner/httprunner/v5/mcphost"
|
"github.com/httprunner/httprunner/v5/mcphost"
|
||||||
@@ -677,6 +678,13 @@ func (r *SessionRunner) Start(givenVars map[string]interface{}) (summary *TestCa
|
|||||||
summary.InOut.ExportVars = exportVars
|
summary.InOut.ExportVars = exportVars
|
||||||
summary.InOut.ConfigVars = config.Variables
|
summary.InOut.ConfigVars = config.Variables
|
||||||
|
|
||||||
|
// Save JSON case content to results directory
|
||||||
|
if config.Path != "" {
|
||||||
|
if err := saveJSONCase(config.Path); err != nil {
|
||||||
|
log.Warn().Err(err).Str("path", config.Path).Msg("save JSON case failed")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: move to mobile ui step
|
// TODO: move to mobile ui step
|
||||||
// Collect logs from cached drivers
|
// Collect logs from cached drivers
|
||||||
for _, cached := range uixt.ListCachedDrivers() {
|
for _, cached := range uixt.ListCachedDrivers() {
|
||||||
@@ -1022,3 +1030,25 @@ func (r *SessionRunner) GetSessionVariables() map[string]interface{} {
|
|||||||
func (r *SessionRunner) GetTransactions() map[string]map[TransactionType]time.Time {
|
func (r *SessionRunner) GetTransactions() map[string]map[TransactionType]time.Time {
|
||||||
return r.transactions
|
return r.transactions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// saveJSONCase saves the original JSON case content to the results directory
|
||||||
|
func saveJSONCase(casePath string) error {
|
||||||
|
// Read the original JSON case content
|
||||||
|
path := TestCasePath(casePath)
|
||||||
|
testCase, err := path.GetTestCase()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "load JSON case failed")
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove environs from testcase config
|
||||||
|
tConfig := testCase.Config.(*TConfig)
|
||||||
|
tConfig.Environs = nil
|
||||||
|
|
||||||
|
// save JSON case to results directory
|
||||||
|
jsonCasePath := config.GetConfig().CaseFilePath()
|
||||||
|
err = testCase.Dump2JSON(jsonCasePath)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "dump JSON case failed")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user