mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-13 00:11:28 +08:00
feat: validate with ocr text
This commit is contained in:
@@ -318,6 +318,36 @@ func (s *StepIOSValidation) AssertLabelNotExists(expectedLabel string, msg ...st
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *StepIOSValidation) AssertOCRExists(expectedText string, msg ...string) *StepIOSValidation {
|
||||||
|
v := Validator{
|
||||||
|
Check: uiSelectorOCR,
|
||||||
|
Assert: assertionExists,
|
||||||
|
Expect: expectedText,
|
||||||
|
}
|
||||||
|
if len(msg) > 0 {
|
||||||
|
v.Message = msg[0]
|
||||||
|
} else {
|
||||||
|
v.Message = fmt.Sprintf("[%s] not found", expectedText)
|
||||||
|
}
|
||||||
|
s.step.Validators = append(s.step.Validators, v)
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *StepIOSValidation) AssertOCRNotExists(expectedText string, msg ...string) *StepIOSValidation {
|
||||||
|
v := Validator{
|
||||||
|
Check: uiSelectorOCR,
|
||||||
|
Assert: assertionNotExists,
|
||||||
|
Expect: expectedText,
|
||||||
|
}
|
||||||
|
if len(msg) > 0 {
|
||||||
|
v.Message = msg[0]
|
||||||
|
} else {
|
||||||
|
v.Message = fmt.Sprintf("[%s] should not exist", expectedText)
|
||||||
|
}
|
||||||
|
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
|
||||||
}
|
}
|
||||||
@@ -630,6 +660,8 @@ func (w *wdaClient) doValidation(iValidators []interface{}) (validateResults []*
|
|||||||
result = w.assertName(expected, exists)
|
result = w.assertName(expected, exists)
|
||||||
case uiSelectorLabel:
|
case uiSelectorLabel:
|
||||||
result = w.assertLabel(expected, exists)
|
result = w.assertLabel(expected, exists)
|
||||||
|
case uiSelectorOCR:
|
||||||
|
result = w.assertOCR(expected, exists)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result {
|
if result {
|
||||||
@@ -667,3 +699,8 @@ func (w *wdaClient) assertLabel(label 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) assertOCR(text string, exists bool) bool {
|
||||||
|
_, _, _, _, err := w.DriverExt.FindTextByOCR(text)
|
||||||
|
return exists == (err == nil)
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,9 +10,11 @@ func TestIOSSettingsAction(t *testing.T) {
|
|||||||
Config: NewConfig("ios ui action on Settings"),
|
Config: NewConfig("ios ui action on Settings"),
|
||||||
TestSteps: []IStep{
|
TestSteps: []IStep{
|
||||||
NewStep("launch Settings").
|
NewStep("launch Settings").
|
||||||
IOS().Home().Tap("//*[@label='设置']").
|
IOS().Home().Tap("设置").
|
||||||
Validate().
|
Validate().
|
||||||
|
AssertNameExists("飞行模式").
|
||||||
AssertLabelExists("飞行模式").
|
AssertLabelExists("飞行模式").
|
||||||
|
AssertOCRExists("飞行模式").
|
||||||
AssertLabelNotExists("飞行模式2"),
|
AssertLabelNotExists("飞行模式2"),
|
||||||
NewStep("swipe up and down").
|
NewStep("swipe up and down").
|
||||||
IOS().SwipeUp().SwipeUp().SwipeDown(),
|
IOS().SwipeUp().SwipeUp().SwipeDown(),
|
||||||
|
|||||||
Reference in New Issue
Block a user