运行测试时出现“无法完成单击”错误,但它间歇性地发生。
在调用 clickOnView 之前,我确保视图不为空。
在调用 clickOnView 之前还有什么需要检查的吗?
Button btnLike = (Button) vwItem.findViewById(R.id.buttonLike);
assertTrue(solo.waitForCondition(new Common.WaitUntilViewNotNull(solo, vwItem, R.id.buttonLike), 5000));
solo.clickOnView(btnLike);
public static class WaitUntilViewNotNull implements Condition {
int viewId;
Solo solo;
View parentView;
public WaitUntilViewNotNull(Solo solo, View parentView, int viewId) {
this.solo = solo;
this.viewId = viewId;
this.parentView = parentView;
}
@Override
public boolean isSatisfied() {
View v = null;
if (parentView != null) {
v = (View)parentView.findViewById(viewId);
}
else {
v = (View) solo.getView(viewId);
}
return v != null;
}
}