mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 15:37:35 +08:00
change: remove xpath validation
This commit is contained in:
@@ -42,7 +42,6 @@ const (
|
|||||||
|
|
||||||
// UI validation
|
// UI validation
|
||||||
uiSelectorName string = "ui_name"
|
uiSelectorName string = "ui_name"
|
||||||
uiSelectorXpath string = "ui_xpath"
|
|
||||||
uiSelectorOCR string = "ui_ocr"
|
uiSelectorOCR string = "ui_ocr"
|
||||||
assertionExists string = "exists"
|
assertionExists string = "exists"
|
||||||
assertionNotExists string = "not_exists"
|
assertionNotExists string = "not_exists"
|
||||||
|
|||||||
@@ -158,31 +158,31 @@ type StepAndroidValidation struct {
|
|||||||
step *TStep
|
step *TStep
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepAndroidValidation) AssertXpathExists(expectedXpath string, msg ...string) *StepAndroidValidation {
|
func (s *StepAndroidValidation) AssertNameExists(expectedName string, msg ...string) *StepAndroidValidation {
|
||||||
v := Validator{
|
v := Validator{
|
||||||
Check: uiSelectorXpath,
|
Check: uiSelectorName,
|
||||||
Assert: assertionExists,
|
Assert: assertionExists,
|
||||||
Expect: expectedXpath,
|
Expect: expectedName,
|
||||||
}
|
}
|
||||||
if len(msg) > 0 {
|
if len(msg) > 0 {
|
||||||
v.Message = msg[0]
|
v.Message = msg[0]
|
||||||
} else {
|
} else {
|
||||||
v.Message = fmt.Sprintf("xpath [%s] not found", expectedXpath)
|
v.Message = fmt.Sprintf("[%s] not found", expectedName)
|
||||||
}
|
}
|
||||||
s.step.Validators = append(s.step.Validators, v)
|
s.step.Validators = append(s.step.Validators, v)
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepAndroidValidation) AssertXpathNotExists(expectedXpath string, msg ...string) *StepAndroidValidation {
|
func (s *StepAndroidValidation) AssertNameNotExists(expectedName string, msg ...string) *StepAndroidValidation {
|
||||||
v := Validator{
|
v := Validator{
|
||||||
Check: uiSelectorXpath,
|
Check: uiSelectorName,
|
||||||
Assert: assertionNotExists,
|
Assert: assertionNotExists,
|
||||||
Expect: expectedXpath,
|
Expect: expectedName,
|
||||||
}
|
}
|
||||||
if len(msg) > 0 {
|
if len(msg) > 0 {
|
||||||
v.Message = msg[0]
|
v.Message = msg[0]
|
||||||
} else {
|
} else {
|
||||||
v.Message = fmt.Sprintf("xpath [%s] should not exist", expectedXpath)
|
v.Message = fmt.Sprintf("[%s] should not exist", expectedName)
|
||||||
}
|
}
|
||||||
s.step.Validators = append(s.step.Validators, v)
|
s.step.Validators = append(s.step.Validators, v)
|
||||||
return s
|
return s
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ func TestAndroidAction(t *testing.T) {
|
|||||||
Config: NewConfig("android ui action"),
|
Config: NewConfig("android ui action"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("launch douyin").
|
NewStep("launch douyin").
|
||||||
Android().Serial("xxx").Click("抖音").
|
Android().Serial("xxx").Tap("抖音").
|
||||||
Validate().
|
Validate().
|
||||||
AssertXpathExists("首页", "首页 tab 不存在").
|
AssertNameExists("首页", "首页 tab 不存在").
|
||||||
AssertXpathExists("消息", "消息 tab 不存在"),
|
AssertNameExists("消息", "消息 tab 不存在"),
|
||||||
NewStep("swipe up and down").
|
NewStep("swipe up and down").
|
||||||
Android().Serial("xxx").SwipeUp().SwipeUp().SwipeDown(),
|
Android().Serial("xxx").SwipeUp().SwipeUp().SwipeDown(),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -288,36 +288,6 @@ func (s *StepIOSValidation) AssertNameNotExists(expectedName string, msg ...stri
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StepIOSValidation) AssertXpathExists(expectedXpath string, msg ...string) *StepIOSValidation {
|
|
||||||
v := Validator{
|
|
||||||
Check: uiSelectorXpath,
|
|
||||||
Assert: assertionExists,
|
|
||||||
Expect: expectedXpath,
|
|
||||||
}
|
|
||||||
if len(msg) > 0 {
|
|
||||||
v.Message = msg[0]
|
|
||||||
} else {
|
|
||||||
v.Message = fmt.Sprintf("xpath [%s] not found", expectedXpath)
|
|
||||||
}
|
|
||||||
s.step.Validators = append(s.step.Validators, v)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StepIOSValidation) AssertXpathNotExists(expectedXpath string, msg ...string) *StepIOSValidation {
|
|
||||||
v := Validator{
|
|
||||||
Check: uiSelectorXpath,
|
|
||||||
Assert: assertionNotExists,
|
|
||||||
Expect: expectedXpath,
|
|
||||||
}
|
|
||||||
if len(msg) > 0 {
|
|
||||||
v.Message = msg[0]
|
|
||||||
} else {
|
|
||||||
v.Message = fmt.Sprintf("xpath [%s] should not exist", expectedXpath)
|
|
||||||
}
|
|
||||||
s.step.Validators = append(s.step.Validators, v)
|
|
||||||
return s
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StepIOSValidation) Name() string {
|
func (s *StepIOSValidation) Name() string {
|
||||||
return s.step.Name
|
return s.step.Name
|
||||||
}
|
}
|
||||||
@@ -628,8 +598,6 @@ func (w *wdaClient) doValidation(iValidators []interface{}) (validateResults []*
|
|||||||
switch validator.Check {
|
switch validator.Check {
|
||||||
case uiSelectorName:
|
case uiSelectorName:
|
||||||
result = w.assertName(expected, exists)
|
result = w.assertName(expected, exists)
|
||||||
case uiSelectorXpath:
|
|
||||||
result = w.assertXpath(expected, exists)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if result {
|
if result {
|
||||||
@@ -659,11 +627,3 @@ func (w *wdaClient) assertName(name string, exists bool) bool {
|
|||||||
_, err := w.DriverExt.FindElement(selector)
|
_, err := w.DriverExt.FindElement(selector)
|
||||||
return exists == (err == nil)
|
return exists == (err == nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wdaClient) assertXpath(xpath string, exists bool) bool {
|
|
||||||
selector := gwda.BySelector{
|
|
||||||
XPath: xpath,
|
|
||||||
}
|
|
||||||
_, err := w.DriverExt.FindElement(selector)
|
|
||||||
return exists == (err == nil)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user