feat: validate with label

This commit is contained in:
debugtalk
2022-08-28 12:04:21 +08:00
parent ad730b3542
commit 939c153d37
3 changed files with 51 additions and 10 deletions
+40
View File
@@ -288,6 +288,36 @@ func (s *StepIOSValidation) AssertNameNotExists(expectedName string, msg ...stri
return s
}
func (s *StepIOSValidation) AssertLabelExists(expectedLabel string, msg ...string) *StepIOSValidation {
v := Validator{
Check: uiSelectorLabel,
Assert: assertionExists,
Expect: expectedLabel,
}
if len(msg) > 0 {
v.Message = msg[0]
} else {
v.Message = fmt.Sprintf("[%s] not found", expectedLabel)
}
s.step.Validators = append(s.step.Validators, v)
return s
}
func (s *StepIOSValidation) AssertLabelNotExists(expectedLabel string, msg ...string) *StepIOSValidation {
v := Validator{
Check: uiSelectorLabel,
Assert: assertionNotExists,
Expect: expectedLabel,
}
if len(msg) > 0 {
v.Message = msg[0]
} else {
v.Message = fmt.Sprintf("[%s] should not exist", expectedLabel)
}
s.step.Validators = append(s.step.Validators, v)
return s
}
func (s *StepIOSValidation) Name() string {
return s.step.Name
}
@@ -598,6 +628,8 @@ func (w *wdaClient) doValidation(iValidators []interface{}) (validateResults []*
switch validator.Check {
case uiSelectorName:
result = w.assertName(expected, exists)
case uiSelectorLabel:
result = w.assertLabel(expected, exists)
}
if result {
@@ -627,3 +659,11 @@ func (w *wdaClient) assertName(name string, exists bool) bool {
_, err := w.DriverExt.FindElement(selector)
return exists == (err == nil)
}
func (w *wdaClient) assertLabel(label string, exists bool) bool {
selector := gwda.BySelector{
LinkText: gwda.NewElementAttribute().WithLabel(label),
}
_, err := w.DriverExt.FindElement(selector)
return exists == (err == nil)
}