change: assert name/xpath exists

This commit is contained in:
debugtalk
2022-08-15 22:34:17 +08:00
parent 66eb8ee865
commit 5c816f3dd1
4 changed files with 39 additions and 35 deletions

View File

@@ -40,10 +40,11 @@ const (
uiInput MobileMethod = "input" uiInput MobileMethod = "input"
// UI validation // UI validation
assertionNameExists string = "name_exists" uiSelectorName string = "ui_name"
assertionNameNotExists string = "name_not_exists" uiSelectorXpath string = "ui_xpath"
assertionXpathExists string = "xpath_exists" uiSelectorOCR string = "ui_ocr"
assertionXpathNotExists string = "xpath_not_exists" assertionExists string = "exists"
assertionNotExists string = "not_exists"
) )
type MobileAction struct { type MobileAction struct {

View File

@@ -168,8 +168,8 @@ type StepAndroidValidation struct {
func (s *StepAndroidValidation) AssertXpathExists(expectedXpath string, msg ...string) *StepAndroidValidation { func (s *StepAndroidValidation) AssertXpathExists(expectedXpath string, msg ...string) *StepAndroidValidation {
v := Validator{ v := Validator{
Check: "UI", Check: uiSelectorXpath,
Assert: assertionXpathExists, Assert: assertionExists,
Expect: expectedXpath, Expect: expectedXpath,
} }
if len(msg) > 0 { if len(msg) > 0 {
@@ -183,8 +183,8 @@ func (s *StepAndroidValidation) AssertXpathExists(expectedXpath string, msg ...s
func (s *StepAndroidValidation) AssertXpathNotExists(expectedXpath string, msg ...string) *StepAndroidValidation { func (s *StepAndroidValidation) AssertXpathNotExists(expectedXpath string, msg ...string) *StepAndroidValidation {
v := Validator{ v := Validator{
Check: "UI", Check: uiSelectorXpath,
Assert: assertionXpathNotExists, Assert: assertionNotExists,
Expect: expectedXpath, Expect: expectedXpath,
} }
if len(msg) > 0 { if len(msg) > 0 {

View File

@@ -244,8 +244,8 @@ type StepIOSValidation struct {
func (s *StepIOSValidation) AssertNameExists(expectedName string, msg ...string) *StepIOSValidation { func (s *StepIOSValidation) AssertNameExists(expectedName string, msg ...string) *StepIOSValidation {
v := Validator{ v := Validator{
Check: "UI", Check: uiSelectorName,
Assert: assertionNameExists, Assert: assertionExists,
Expect: expectedName, Expect: expectedName,
} }
if len(msg) > 0 { if len(msg) > 0 {
@@ -259,8 +259,8 @@ func (s *StepIOSValidation) AssertNameExists(expectedName string, msg ...string)
func (s *StepIOSValidation) AssertNameNotExists(expectedName string, msg ...string) *StepIOSValidation { func (s *StepIOSValidation) AssertNameNotExists(expectedName string, msg ...string) *StepIOSValidation {
v := Validator{ v := Validator{
Check: "UI", Check: uiSelectorName,
Assert: assertionNameNotExists, Assert: assertionNotExists,
Expect: expectedName, Expect: expectedName,
} }
if len(msg) > 0 { if len(msg) > 0 {
@@ -274,8 +274,8 @@ func (s *StepIOSValidation) AssertNameNotExists(expectedName string, msg ...stri
func (s *StepIOSValidation) AssertXpathExists(expectedXpath string, msg ...string) *StepIOSValidation { func (s *StepIOSValidation) AssertXpathExists(expectedXpath string, msg ...string) *StepIOSValidation {
v := Validator{ v := Validator{
Check: "UI", Check: uiSelectorXpath,
Assert: assertionXpathExists, Assert: assertionExists,
Expect: expectedXpath, Expect: expectedXpath,
} }
if len(msg) > 0 { if len(msg) > 0 {
@@ -289,8 +289,8 @@ func (s *StepIOSValidation) AssertXpathExists(expectedXpath string, msg ...strin
func (s *StepIOSValidation) AssertXpathNotExists(expectedXpath string, msg ...string) *StepIOSValidation { func (s *StepIOSValidation) AssertXpathNotExists(expectedXpath string, msg ...string) *StepIOSValidation {
v := Validator{ v := Validator{
Check: "UI", Check: uiSelectorXpath,
Assert: assertionXpathNotExists, Assert: assertionNotExists,
Expect: expectedXpath, Expect: expectedXpath,
} }
if len(msg) > 0 { if len(msg) > 0 {
@@ -675,7 +675,7 @@ func (w *wdaClient) doValidation(iValidators []interface{}) (validateResults []*
} }
// parse check value // parse check value
if validator.Check != "UI" { if !strings.HasPrefix(validator.Check, "ui_") {
validataResult.CheckResult = "skip" validataResult.CheckResult = "skip"
log.Warn().Interface("validator", validator).Msg("skip validator") log.Warn().Interface("validator", validator).Msg("skip validator")
validateResults = append(validateResults, validataResult) validateResults = append(validateResults, validataResult)
@@ -687,17 +687,20 @@ func (w *wdaClient) doValidation(iValidators []interface{}) (validateResults []*
return nil, errors.New("validator expect should be string") return nil, errors.New("validator expect should be string")
} }
var result bool var exists bool
switch validator.Assert { if validator.Assert == assertionExists {
case assertionXpathExists: exists = true
result = w.assertXpath(expected, true) } else {
case assertionXpathNotExists: exists = false
result = w.assertXpath(expected, false)
case assertionNameExists:
result = w.assertName(expected, true)
case assertionNameNotExists:
result = w.assertName(expected, false)
} }
var result bool
switch validator.Check {
case uiSelectorName:
result = w.assertName(expected, exists)
case uiSelectorXpath:
result = w.assertXpath(expected, exists)
}
if result { if result {
log.Info(). log.Info().
Str("assert", validator.Assert). Str("assert", validator.Assert).

View File

@@ -20,10 +20,10 @@ func TestIOSSettingsAction(t *testing.T) {
} }
fmt.Println(testCase) fmt.Println(testCase)
// err := NewRunner(t).Run(testCase) err := NewRunner(t).Run(testCase)
// if err != nil { if err != nil {
// t.Fatal(err) t.Fatal(err)
// } }
} }
func TestIOSSearchApp(t *testing.T) { func TestIOSSearchApp(t *testing.T) {
@@ -93,10 +93,10 @@ func TestIOSWeixinLive(t *testing.T) {
} }
fmt.Println(testCase) fmt.Println(testCase)
// err := NewRunner(t).Run(testCase) err := NewRunner(t).Run(testCase)
// if err != nil { if err != nil {
// t.Fatal(err) t.Fatal(err)
// } }
} }
func TestIOSCameraPhotoCapture(t *testing.T) { func TestIOSCameraPhotoCapture(t *testing.T) {