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

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

}

最佳答案

看来问题出在渲染视图之前分配btnLike变量。因此,它等于null

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

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

关于android - Robotium AssertionFailedError:无法完成单击,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16721708/

10-12 04:18