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"
// UI validation
assertionNameExists string = "name_exists"
assertionNameNotExists string = "name_not_exists"
assertionXpathExists string = "xpath_exists"
assertionXpathNotExists string = "xpath_not_exists"
uiSelectorName string = "ui_name"
uiSelectorXpath string = "ui_xpath"
uiSelectorOCR string = "ui_ocr"
assertionExists string = "exists"
assertionNotExists string = "not_exists"
)
type MobileAction struct {

View File

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

View File

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

View File

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