feat: validate with ocr text

This commit is contained in:
debugtalk
2022-08-28 12:18:45 +08:00
parent 939c153d37
commit 2cd10989f0
2 changed files with 40 additions and 1 deletions

View File

@@ -318,6 +318,36 @@ func (s *StepIOSValidation) AssertLabelNotExists(expectedLabel string, msg ...st
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 {
return s.step.Name
}
@@ -630,6 +660,8 @@ func (w *wdaClient) doValidation(iValidators []interface{}) (validateResults []*
result = w.assertName(expected, exists)
case uiSelectorLabel:
result = w.assertLabel(expected, exists)
case uiSelectorOCR:
result = w.assertOCR(expected, exists)
}
if result {
@@ -667,3 +699,8 @@ func (w *wdaClient) assertLabel(label string, exists bool) bool {
_, err := w.DriverExt.FindElement(selector)
return exists == (err == nil)
}
func (w *wdaClient) assertOCR(text string, exists bool) bool {
_, _, _, _, err := w.DriverExt.FindTextByOCR(text)
return exists == (err == nil)
}

View File

@@ -10,9 +10,11 @@ func TestIOSSettingsAction(t *testing.T) {
Config: NewConfig("ios ui action on Settings"),
TestSteps: []IStep{
NewStep("launch Settings").
IOS().Home().Tap("//*[@label='设置']").
IOS().Home().Tap("设置").
Validate().
AssertNameExists("飞行模式").
AssertLabelExists("飞行模式").
AssertOCRExists("飞行模式").
AssertLabelNotExists("飞行模式2"),
NewStep("swipe up and down").
IOS().SwipeUp().SwipeUp().SwipeDown(),