mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-08 00:47:36 +08:00
feat: add global AntiRisk configuration support
- Add AntiRisk field to TConfig struct for global anti-risk switch - Add SetAntiRisk method to configure global anti-risk setting - Implement automatic AntiRisk application in mobile UI steps - Global AntiRisk setting applies to all actions unless explicitly disabled - Maintains backward compatibility with existing action-level AntiRisk settings
This commit is contained in:
@@ -43,6 +43,7 @@ type TConfig struct {
|
|||||||
Path string `json:"path,omitempty" yaml:"path,omitempty"` // testcase file path
|
Path string `json:"path,omitempty" yaml:"path,omitempty"` // testcase file path
|
||||||
PluginSetting *PluginConfig `json:"plugin,omitempty" yaml:"plugin,omitempty"` // plugin config
|
PluginSetting *PluginConfig `json:"plugin,omitempty" yaml:"plugin,omitempty"` // plugin config
|
||||||
MCPConfigPath string `json:"mcp_config_path,omitempty" yaml:"mcp_config_path,omitempty"`
|
MCPConfigPath string `json:"mcp_config_path,omitempty" yaml:"mcp_config_path,omitempty"`
|
||||||
|
AntiRisk bool `json:"anti_risk,omitempty" yaml:"anti_risk,omitempty"` // global anti-risk switch
|
||||||
IgnorePopup bool `json:"ignore_popup,omitempty" yaml:"ignore_popup,omitempty"`
|
IgnorePopup bool `json:"ignore_popup,omitempty" yaml:"ignore_popup,omitempty"`
|
||||||
LLMService option.LLMServiceType `json:"llm_service,omitempty" yaml:"llm_service,omitempty"`
|
LLMService option.LLMServiceType `json:"llm_service,omitempty" yaml:"llm_service,omitempty"`
|
||||||
CVService option.CVServiceType `json:"cv_service,omitempty" yaml:"cv_service,omitempty"`
|
CVService option.CVServiceType `json:"cv_service,omitempty" yaml:"cv_service,omitempty"`
|
||||||
@@ -76,6 +77,12 @@ func (c *TConfig) SetVerifySSL(verify bool) *TConfig {
|
|||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetAntiRisk sets global anti-risk switch for current testcase.
|
||||||
|
func (c *TConfig) SetAntiRisk(antiRisk bool) *TConfig {
|
||||||
|
c.AntiRisk = antiRisk
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
// WithParameters sets parameters for current testcase.
|
// WithParameters sets parameters for current testcase.
|
||||||
func (c *TConfig) WithParameters(parameters map[string]interface{}) *TConfig {
|
func (c *TConfig) WithParameters(parameters map[string]interface{}) *TConfig {
|
||||||
c.Parameters = parameters
|
c.Parameters = parameters
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
v5.0.0-beta-2505282311
|
v5.0.0-beta-2505290011
|
||||||
|
|||||||
+24
-2
@@ -709,7 +709,7 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
}
|
}
|
||||||
uiDriver, err := uixt.GetOrCreateXTDriver(config)
|
uiDriver, err := uixt.GetOrCreateXTDriver(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
identifier := mobileStep.Identifier
|
identifier := mobileStep.Identifier
|
||||||
@@ -741,6 +741,7 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
attachments["error"] = err.Error()
|
attachments["error"] = err.Error()
|
||||||
|
|
||||||
// save foreground app
|
// save foreground app
|
||||||
|
if uiDriver != nil {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
actionResult := &ActionResult{
|
actionResult := &ActionResult{
|
||||||
MobileAction: uixt.MobileAction{
|
MobileAction: uixt.MobileAction{
|
||||||
@@ -757,9 +758,14 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
actionResult.Elapsed = time.Since(startTime).Milliseconds()
|
actionResult.Elapsed = time.Since(startTime).Milliseconds()
|
||||||
stepResult.Actions = append(stepResult.Actions, actionResult)
|
stepResult.Actions = append(stepResult.Actions, actionResult)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// automatic handling of pop-up windows on each step finished
|
// automatic handling of pop-up windows on each step finished
|
||||||
if !ignorePopup && !s.caseRunner.Config.Get().IgnorePopup {
|
var config *TConfig
|
||||||
|
if s.caseRunner != nil && s.caseRunner.Config != nil {
|
||||||
|
config = s.caseRunner.Config.Get()
|
||||||
|
}
|
||||||
|
if !ignorePopup && (config == nil || !config.IgnorePopup) && uiDriver != nil {
|
||||||
startTime := time.Now()
|
startTime := time.Now()
|
||||||
actionResult := &ActionResult{
|
actionResult := &ActionResult{
|
||||||
MobileAction: uixt.MobileAction{
|
MobileAction: uixt.MobileAction{
|
||||||
@@ -776,9 +782,11 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
// save attachments
|
// save attachments
|
||||||
|
if uiDriver != nil {
|
||||||
for key, value := range uiDriver.GetData(true) {
|
for key, value := range uiDriver.GetData(true) {
|
||||||
attachments[key] = value
|
attachments[key] = value
|
||||||
}
|
}
|
||||||
|
}
|
||||||
stepResult.Attachments = attachments
|
stepResult.Attachments = attachments
|
||||||
stepResult.Elapsed = time.Since(start).Milliseconds()
|
stepResult.Elapsed = time.Since(start).Milliseconds()
|
||||||
}()
|
}()
|
||||||
@@ -806,6 +814,20 @@ func runStepMobileUI(s *SessionRunner, step IStep) (stepResult *StepResult, err
|
|||||||
return stepResult, err
|
return stepResult, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Apply global AntiRisk configuration if enabled in testcase config
|
||||||
|
if s.caseRunner != nil && s.caseRunner.Config != nil {
|
||||||
|
config := s.caseRunner.Config.Get()
|
||||||
|
if config != nil && config.AntiRisk {
|
||||||
|
if action.Options == nil {
|
||||||
|
action.Options = &option.ActionOptions{}
|
||||||
|
}
|
||||||
|
// Only set AntiRisk to true if it's not already explicitly set to false
|
||||||
|
if !action.Options.AntiRisk {
|
||||||
|
action.Options.AntiRisk = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// stat uixt action
|
// stat uixt action
|
||||||
if action.Method == option.ACTION_LOG {
|
if action.Method == option.ACTION_LOG {
|
||||||
log.Info().Interface("action", action.Params).Msg("stat uixt action")
|
log.Info().Interface("action", action.Params).Msg("stat uixt action")
|
||||||
|
|||||||
Reference in New Issue
Block a user