2017-06-23 2 views
0

私はuiautomatorを使用して、アプリケーションの詳細でアプリケーションのアクセス許可を取り消そうとしています。Google's sample appを使用しています。しかし、私は私の尿スターターが間違ったトグル状態になっているように見えました。トグルがチェックされているとき、何らかの理由で、あなたはまだ私にfalseを返します。uiautomatorアプリケーションのアクセス許可リストをクリック/取り消します

私の最終目標は、異なるインデックスを持つ同じレイアウトからボタンを1つずつ切り替えることです。

enter image description here

@Test 
public void clickThruSettings() throws UiObjectNotFoundException { 

// go to the target page and open the permissions list. 
    Context context = InstrumentationRegistry.getContext(); 
    final Intent intent = new Intent(); 
    intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS); 
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); 
    Uri uri = Uri.fromParts("package", BASIC_SAMPLE_PACKAGE, null); 
    intent.setData(uri); 
    context.startActivity(intent); 
    UiObject permissions = mDevice.findObject(new UiSelector().text("Permissions")); 
    permissions.clickAndWaitForNewWindow(); 

// toggle on and off with index for linearLayout. 
    togglePermissionButton(true,0); 
    togglePermissionButton(false,1); 
    togglePermissionButton(true,2); 
    togglePermissionButton(false,3); 
    } 

private void togglePermissionButton(boolean enabled, int index) throws UiObjectNotFoundException { 
    UiObject permissionButton = mDevice.findObject(new UiSelector().className("android.widget.LinearLayout") 
      .scrollable(false).index(index)).getChild(new UiSelector().className(android.widget.Switch.class 
      .getName())); 
    if (permissionButton.waitForExists(2000)&& permissionButton.exists()&& permissionButton.isEnabled()) { 
     if (permissionButton.isChecked() != enabled) { 
      permissionButton.click(); 
     } 
    } 
} 

任意のアイデア?

答えて

0

インデックスはその親に基づいており、このように使用することはできません。 インスタンスプロパティを持つスイッチを直接見つけることができます。

​​
関連する問題