1

运行测试时出现“无法完成单击”错误,但它间歇性地发生。

在调用 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;
    }

}
4

1 回答 1

1

似乎问题在于在btnLike呈现视图之前分配变量。因此它等于null

顺便说一句,您可能更喜欢waitForViewcustom Condition

assertTrue(solo.waitForView(R.id.buttonLike, 1, 5000));
Button btnLike = (Button) vwItem.findViewById(R.id.buttonLike);
solo.clickOnView(btnLike);
于 2013-10-25T13:10:59.060 回答