Robotium AssertionFailedError:单击无法完成

时间:2013-05-23 18:52:08

标签: android robotium

我在运行测试时遇到“点击无法完成”错误但是间歇性地发生。

在调用clickOnView之前,我确保视图不为null。

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

}

1 个答案:

答案 0 :(得分:1)

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

顺便说一下,您可能更喜欢waitForView而不是自定义Condition

assertTrue(solo.waitForView(R.id.buttonLike, 1, 5000));
Button btnLike = (Button) vwItem.findViewById(R.id.buttonLike);
solo.clickOnView(btnLike);