我正在尝试编写自定义ViewAction <div data-reactid=".0.0.1.0.0.1.$termsConditions-component.0.1.3.1.0.0.0.0.0.2.0:$5.5.0"><span class="cursor" data-reactid=".0.0.1.0.0.1.$termsConditions-component.0.1.3.1.0.0.0.0.0.2.0:$5.5.0.0"><svg viewBox="0 0 16 20" class="excel-document" style="background-image:none;background-position:0% 0%;display:inline;fill:#333;height:20px;width:16px;" data-reactid=".0.0.1.0.0.1.$termsConditions-component.0.1.3.1.0.0.0.0.0.2.0:$5.5.0.0.0"><path d="M2 0C.9 0 .01.9.01 2L0 18c0 1.1.89 2 1.99 2H14c1.1 0 2-.9 2-2V6l-6-6H2zm7 7V1.5L14.5 7H9zm-2.34 7.39l-3.45-5.1h2.73l2.1 3.42 2.175-3.42h2.58L9.36 14.405 13.095 20H10.29l-2.34-3.705L5.565 20h-2.64l3.735-5.61z" fill="#11764B" data-reactid=".0.0.1.0.0.1.$termsConditions-component.0.1.3.1.0.0.0.0.0.2.0:$5.5.0.0.0.0"></path></svg></span>
。但是似乎ClickWithMessageAction()
没有点击给定的元素。
perform.onClick()
中调用 ClickWithMessageAction()
PageObject
我希望fun clickButton(){
Button{
ClickWithMessageAction(error_message)
}
class ClickWithMessageAction(private val error_message: String) : ViewAction{
override fun getDescription(): String {
return "Click button"
}
override fun getConstraints(): Matcher<View> {
return isEnabled()
}
override fun perform(uiController: UiController?, view: View?) {
if (view != null){
try{
view.performClick()
}catch(e: PerformException){
throw Error(error_message)
}
}
}
}
单击元素,并在失败的情况下发布error_message。
答案 0 :(得分:0)
我在PageObject中称它错误。应该是
fun clickButton(){
Button{
act{ClickWithMessageAction(error_message)}
}
}