From 5c816f3dd1454587e52b50b37be3b706dfd07ca8 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Mon, 15 Aug 2022 22:34:17 +0800 Subject: [PATCH] change: assert name/xpath exists --- hrp/step.go | 9 +++++---- hrp/step_android_ui.go | 8 ++++---- hrp/step_ios_ui.go | 41 ++++++++++++++++++++++------------------- hrp/step_ios_ui_test.go | 16 ++++++++-------- 4 files changed, 39 insertions(+), 35 deletions(-) diff --git a/hrp/step.go b/hrp/step.go index dcc2c7ff..4af50755 100644 --- a/hrp/step.go +++ b/hrp/step.go @@ -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 { diff --git a/hrp/step_android_ui.go b/hrp/step_android_ui.go index 60b9cc3a..d3fecb26 100644 --- a/hrp/step_android_ui.go +++ b/hrp/step_android_ui.go @@ -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 { diff --git a/hrp/step_ios_ui.go b/hrp/step_ios_ui.go index 68dc425e..a4987341 100644 --- a/hrp/step_ios_ui.go +++ b/hrp/step_ios_ui.go @@ -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). diff --git a/hrp/step_ios_ui_test.go b/hrp/step_ios_ui_test.go index 7a836cdd..0ed9120f 100644 --- a/hrp/step_ios_ui_test.go +++ b/hrp/step_ios_ui_test.go @@ -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) {