我得到了
android.support.test.espresso.PerformException:在视图上执行'send keyCode:4,metaState:0 key event'时出错'目标设备上启用了动画或转换.
我读的文章有相同的错误,但没有找到答案.
我有简单的Android应用程序,我尝试测试简单的事情:
代码非常简单:
@Test
public void getOver500Products() {
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
onView(withId(R.id.layout2)).perform(click());
clickExactItem(2);
for (int i = 0; i< 501; i++) {
clickRandomItem();
addedToCart();
Espresso.pressBack();
}
}
public void clickRandomItem() {
try {
int x = getRandomRecyclerPosition(R.id.list);
clickExactItem(x);
} catch (NoMatchingViewException e) {
}
}
public void clickExactItem(int position) {
onView(withId(R.id.list))
.perform(RecyclerViewActions
.actionOnItemAtPosition(position, click()));
}
public boolean addedToCart() {
try {
onView(withId(R.id.product_add_in_cart)).perform(click());
} catch (NoMatchingViewException e) {
return false;
} …Run Code Online (Sandbox Code Playgroud) 我有一个支持多种语言的旧项目。我想升级支持库和目标平台,在迁移到Androidx之前,一切正常,但现在更改语言无效!
我使用此代码更改App的默认语言环境
private static Context updateResources(Context context, String language)
{
Locale locale = new Locale(language);
Locale.setDefault(locale);
Configuration configuration = context.getResources().getConfiguration();
configuration.setLocale(locale);
return context.createConfigurationContext(configuration);
}
Run Code Online (Sandbox Code Playgroud)
并在每个活动上通过attachBaseContext这样的覆盖调用此方法:
@Override
protected void attachBaseContext(Context newBase)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
String language = preferences.getString(SELECTED_LANGUAGE, "fa");
super.attachBaseContext(updateResources(newBase, language));
}
Run Code Online (Sandbox Code Playgroud)
我尝试其他方法来获取字符串,但我注意到了吗?getActivity().getBaseContext().getString工作,而getActivity().getString不是工作。即使以下代码也不起作用,并且始终app_name在默认资源string.xml中显示vlaue。
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"/>
Run Code Online (Sandbox Code Playgroud)
我在https://github.com/Freydoonk/LanguageTest中共享示例代码
也getActivity()..getResources().getIdentifier行不通,总是返回0!
使用Espresso更新EditText很容易,但是在测试过程中我找不到改变文本的方法(比如使用TextView.setText("someText");方法).
ViewAction.replaceText(stringToBeSet);
Run Code Online (Sandbox Code Playgroud)
不工作,因为它应该是一个EditText;