簡體   English   中英

如何使用Robotium單擊微調器中的第一項?

[英]How do I click the first item in a spinner using Robotium?

我在微調器中向上滾動以選擇Robotium測試用例中的第一項時遇到問題。 這是我的代碼:

int pos = solo.getCurrentSpinners().get(0).getSelectedItemPosition();
solo.pressSpinnerItem(0, 0 - pos);

調試時pos是1,但是Robotium仍然按索引1上的微調器,即使我命令它按-1時也是如此。 我究竟做錯了什么?

謝謝馬庫斯

看來他們現在把這些課都上了。 只是自己遇到了這個問題,但是找到了一種正確且通用的方法。

// 0 is the first spinner in the layout
View view1 = solo.getView(Spinner.class, 0);
solo.clickOnView(view1);
solo.scrollToTop(); // I put this in here so that it always keeps the list at start
// select the 10th item in the spinner
solo.clickOnView(solo.getView(TextView.class, 10)); 

您能否僅獲取視圖並調用執行單擊?

solo.getCurrentSpinners().get(0).performClick()

與Robotium一起使用的API非常不穩定,因此我決定采用直接API路線:

instrumentation.runOnMainSync(new Runnable() {
    @Override
    public void run() {
        Spinner spinner = (Spinner) solo.getView(resourceId);
        spinner.setSelection(position, true);
    }
});

這不會顯示微調框的彈出窗口,但會選擇所需的項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM