mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-09 22:44:05 +08:00
feat: validate with label
This commit is contained in:
@@ -42,6 +42,7 @@ const (
|
|||||||
|
|
||||||
// UI validation
|
// UI validation
|
||||||
uiSelectorName string = "ui_name"
|
uiSelectorName string = "ui_name"
|
||||||
|
uiSelectorLabel string = "ui_label"
|
||||||
uiSelectorOCR string = "ui_ocr"
|
uiSelectorOCR string = "ui_ocr"
|
||||||
assertionExists string = "exists"
|
assertionExists string = "exists"
|
||||||
assertionNotExists string = "not_exists"
|
assertionNotExists string = "not_exists"
|
||||||
|
|||||||
@@ -288,6 +288,36 @@ func (s *StepIOSValidation) AssertNameNotExists(expectedName string, msg ...stri
|
|||||||
return s
|
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 {
|
func (s *StepIOSValidation) Name() string {
|
||||||
return s.step.Name
|
return s.step.Name
|
||||||
}
|
}
|
||||||
@@ -598,6 +628,8 @@ func (w *wdaClient) doValidation(iValidators []interface{}) (validateResults []*
|
|||||||
switch validator.Check {
|
switch validator.Check {
|
||||||
case uiSelectorName:
|
case uiSelectorName:
|
||||||
result = w.assertName(expected, exists)
|
result = w.assertName(expected, exists)
|
||||||
|
case uiSelectorLabel:
|
||||||
|
result = w.assertLabel(expected, exists)
|
||||||
}
|
}
|
||||||
|
|
||||||
if result {
|
if result {
|
||||||
@@ -627,3 +659,11 @@ func (w *wdaClient) assertName(name string, exists bool) bool {
|
|||||||
_, err := w.DriverExt.FindElement(selector)
|
_, err := w.DriverExt.FindElement(selector)
|
||||||
return exists == (err == nil)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ func TestIOSSettingsAction(t *testing.T) {
|
|||||||
NewStep("launch Settings").
|
NewStep("launch Settings").
|
||||||
IOS().Home().Tap("//*[@label='设置']").
|
IOS().Home().Tap("//*[@label='设置']").
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("飞行模式").
|
AssertLabelExists("飞行模式").
|
||||||
AssertNameNotExists("飞行模式2"),
|
AssertLabelNotExists("飞行模式2"),
|
||||||
NewStep("swipe up and down").
|
NewStep("swipe up and down").
|
||||||
IOS().SwipeUp().SwipeUp().SwipeDown(),
|
IOS().SwipeUp().SwipeUp().SwipeDown(),
|
||||||
},
|
},
|
||||||
@@ -33,7 +33,7 @@ func TestIOSSearchApp(t *testing.T) {
|
|||||||
NewStep("进入 App 资源库 搜索框").
|
NewStep("进入 App 资源库 搜索框").
|
||||||
IOS().Home().SwipeLeft().Times(2).Tap("dewey-search-field").
|
IOS().Home().SwipeLeft().Times(2).Tap("dewey-search-field").
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("取消"),
|
AssertLabelExists("取消"),
|
||||||
NewStep("搜索抖音").
|
NewStep("搜索抖音").
|
||||||
IOS().Input("抖音\n"),
|
IOS().Input("抖音\n"),
|
||||||
},
|
},
|
||||||
@@ -80,13 +80,13 @@ func TestIOSWeixinLive(t *testing.T) {
|
|||||||
AppTerminate("com.tencent.xin"). // 关闭已运行的微信,确保启动微信后在「微信」首页
|
AppTerminate("com.tencent.xin"). // 关闭已运行的微信,确保启动微信后在「微信」首页
|
||||||
Tap("微信").
|
Tap("微信").
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("通讯录", "微信启动失败,「通讯录」不存在"),
|
AssertLabelExists("通讯录", "微信启动失败,「通讯录」不存在"),
|
||||||
NewStep("进入直播页").
|
NewStep("进入直播页").
|
||||||
IOS().
|
IOS().
|
||||||
Tap("发现").Sleep(5). // 进入「发现页」;等待 5 秒确保加载完成
|
Tap("发现").Sleep(5). // 进入「发现页」;等待 5 秒确保加载完成
|
||||||
TapXY(0.5, 0.3). // 基于坐标位置点击「直播」;TODO:通过 OCR 识别「直播」
|
TapXY(0.5, 0.3). // 基于坐标位置点击「直播」;TODO:通过 OCR 识别「直播」
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("直播"),
|
AssertLabelExists("直播"),
|
||||||
NewStep("向上滑动 5 次").
|
NewStep("向上滑动 5 次").
|
||||||
IOS().
|
IOS().
|
||||||
SwipeUp().Times(3).ScreenShot(). // 上划 3 次,截图保存
|
SwipeUp().Times(3).ScreenShot(). // 上划 3 次,截图保存
|
||||||
@@ -110,7 +110,7 @@ func TestIOSCameraPhotoCapture(t *testing.T) {
|
|||||||
StopCamera().
|
StopCamera().
|
||||||
StartCamera().
|
StartCamera().
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("PhotoCapture", "拍照按钮不存在"),
|
AssertLabelExists("PhotoCapture", "拍照按钮不存在"),
|
||||||
NewStep("start recording").
|
NewStep("start recording").
|
||||||
IOS().Tap("PhotoCapture"),
|
IOS().Tap("PhotoCapture"),
|
||||||
},
|
},
|
||||||
@@ -132,12 +132,12 @@ func TestIOSCameraVideoCapture(t *testing.T) {
|
|||||||
StopCamera().
|
StopCamera().
|
||||||
StartCamera().
|
StartCamera().
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("PhotoCapture", "录像按钮不存在"),
|
AssertLabelExists("PhotoCapture", "录像按钮不存在"),
|
||||||
NewStep("switch to video capture").
|
NewStep("switch to video capture").
|
||||||
IOS().
|
IOS().
|
||||||
SwipeRight().
|
SwipeRight().
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("VideoCapture", "拍摄按钮不存在"),
|
AssertLabelExists("VideoCapture", "拍摄按钮不存在"),
|
||||||
NewStep("start recording").
|
NewStep("start recording").
|
||||||
IOS().
|
IOS().
|
||||||
Tap("VideoCapture"). // 开始录像
|
Tap("VideoCapture"). // 开始录像
|
||||||
@@ -160,8 +160,8 @@ func TestIOSDouyinAction(t *testing.T) {
|
|||||||
NewStep("launch douyin").
|
NewStep("launch douyin").
|
||||||
IOS().Home().Tap("//*[@label='抖音']").
|
IOS().Home().Tap("//*[@label='抖音']").
|
||||||
Validate().
|
Validate().
|
||||||
AssertNameExists("首页", "首页 tab 不存在").
|
AssertLabelExists("首页", "首页 tab 不存在").
|
||||||
AssertNameExists("消息", "消息 tab 不存在"),
|
AssertLabelExists("消息", "消息 tab 不存在"),
|
||||||
NewStep("swipe up and down").
|
NewStep("swipe up and down").
|
||||||
IOS().SwipeUp().Times(3).SwipeDown(),
|
IOS().SwipeUp().Times(3).SwipeDown(),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user