我尝试过以下操作:
onView(allOf(withId(R.id.single_row_text), withText("Item1"))).perform(click());
Run Code Online (Sandbox Code Playgroud)
但我得到的只是:
android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (with id: net.test.android:id/single_row_text and with text: is "Item1")
If the target view is not part of the view hierarchy, you may need to use Espresso.onData to load it from one of the following AdapterViews:android.widget.ListView@410d6ab0
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=480, height=800, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=1}
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=480, height=800, has-focus=true, has-focusable=true, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, …Run Code Online (Sandbox Code Playgroud) 该场景是当用户点击"下载"按钮时,开始从互联网下载数据(音乐/图像等).下载完成后,按钮会将标签文本更改为"打开".然后用户单击"打开"按钮.我所做的就是:
onView(allOf(withId(R.id.button),withText("Download"))).check(matches(isClickable())).perform(click());
try {
Thread.sleep(delayedTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
onView(allOf(withId(R.id.button),withText("Open"))).check(matches(isClickable())).perform(click());
Run Code Online (Sandbox Code Playgroud)
有时测试通过,有时它不会.有时它失败的原因是"No views in hierarchy found matching: (with id: something:id/button and with text: is "Open").
我知道在Espresso中使用Thread.sleep也是不好的做法.我读过Espresso的闲置资源,但它对我没有意义,我不知道如何在这个特殊情况下应用它.
我使用Angular 1.5.5和Jasmine作为测试框架.目前我必须做这样的事情,以便测试通过:
function createController(bindings) {
return $componentController('myController', null, bindings);
}
beforeEach(inject(function (_$componentController_) {
$componentController = _$componentController_;
}));
describe('on pages updated', function () {
beforeEach(function () {
controller = createController({prop1: 0, prop2: 0});
controller.$onInit(); // you see I have to explitcitly call this $onInit function
});
it('should update isSelected and currentPage', function () {
expect(controller.prop1).toBe(0);
expect(controller.prop2).toBe(0);
controller.prop1= 1;
controller.prop2= 2;
controller.$onChanges(controller); // and $onChanges here as well
expect(controller.prop1).toBe(1);
expect(controller.prop2).toBe(2);
});
});
Run Code Online (Sandbox Code Playgroud) 假设我有2个片段,一个包含列表视图,另一个包含加载文本.我想当我点击一个列表项时,加载文本片段出现在列表视图的顶部.我已将加载文本背景的不透明度调整为:android:background ="#33FFFFFF".但它仍然只是在坚实的灰色背景上显示加载文本.
<?xml version="1.0" encoding="utf-8"?>
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list"
android:background="#e8e9ee"
android:divider="#ccc"
android:dividerHeight="1dp"/>
Run Code Online (Sandbox Code Playgroud)
包含textview的片段:
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/loadingText"
android:id="@+id/loadingText"
android:textColor="#e8e9ee"
android:background="#33FFFFFF"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
Run Code Online (Sandbox Code Playgroud)
我的java代码基本上是这样的:onItemClick:
FragmentTransaction transaction=manager.beginTransaction();
transaction.show(loadingFragment);
transaction.commit();
Run Code Online (Sandbox Code Playgroud) 更新:我通过添加previousMarker对象解决了性能问题.因此,只有先前单击的标记将被删除并替换为默认图标.但是,当我单击标记时,信息窗口仍未显示.
我有一个地图视图并在其上设置了一些标记.我想要的是当我点击一个标记时,它将其图标更改为一个不同的图标,当我点击另一个标记时,前一个标记的图标应该更改为其原始图标.
我所做的就是这样,但只要我点击标记就会改变标记图标.
@Override
public boolean onMarkerClick(Marker marker) { //Called when a marker has been clicked or tapped.
LatLng markerPos=marker.getPosition();
String markerLocationName=marker.getTitle();
String markerSubCategoryName=marker.getSnippet();
marker.remove();
MarkerOptions markerOptions =
new MarkerOptions().position(markerPos)
.title(markerLocationName)
.snippet(markerSubCategoryName)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.new_icon));// Changing marker icon
mMap.addMarker(markerOptions);
Log.d("marker","change marker icon"); // can open a dialog window here
return false;
}
Run Code Online (Sandbox Code Playgroud)
因此,如果我单击2个标记,我将显示2个新图标,同时我想要的只是当前单击的标记更改其图标.
所以我也做了类似的事情,增加了2行代码.它成功地做了我想要的但它有一些缺点(见下文).
@Override
public boolean onMarkerClick(Marker marker) { //Called when a marker has been clicked or tapped.
mMap.clear();
populateAllMarkersOnMap();//repopulate markers on map
LatLng markerPos=marker.getPosition();
String markerLocationName=marker.getTitle();
String markerSubCategoryName=marker.getSnippet();
marker.remove(); //remove …Run Code Online (Sandbox Code Playgroud) 以下是用于测试指令的非常常见的通用方案:
var element,scope;
beforeEach(inject(function ($rootScope,$compile) {
scope = $rootScope.$new()
element = angular.element('<div my-directive></div>')
$compile(element)(scope)
scope.$digest(); //why?
}))
Run Code Online (Sandbox Code Playgroud)
我理解$compile(element)返回一个函数,该函数接受一个scope参数并将其提供给元素的指令.我也明白scope.$digest()执行摘要循环并开始脏检查.尽管如此,我的问题是为什么你必须打电话给scope.$digest后呼叫$compile才能使这一切都能正常工作?
我从第三方Web服务获取以下JSON响应格式:
{
"meta": {
"code": 200,
"requestId": "1"
},
"response": {
"locations": [
{
"id": "1",
"name": "XXX",
"contact": {
phone: '123',
email: 'abc'
},
"location": {
"address": [
"Finland"
]
}
},
{
// another location
}
]
}
}
Run Code Online (Sandbox Code Playgroud)
这是我应该从自己的Web服务返回的响应:
[
{
"id": "1",
"name": "XXX",
"phone": '123',
"address": "Finland"
},
{
// another location
}
]
Run Code Online (Sandbox Code Playgroud)
我该怎么办?我读了一些有关Jackson的好东西,但是只有几个简单的示例,您可以将一些简单的JSON obj映射到POJO。在我的情况下,我需要删除一些节点,并遍历层次结构以获取嵌套的值。到目前为止,这是我在春季启动应用程序中迈出的第一步:
@GET
@Path("{query}")
@Produces("application/json")
public String getVenues(@PathParam("query") String query){
return client.target(url).queryParam("query",query).request(...).get(String.class)
}
Run Code Online (Sandbox Code Playgroud)
任何帮助,指点,建议都欢迎!
我实际上有时(不总是)得到这个错误(下图),这意味着我的硬件很好(?).

每次我收到此错误时,我都尝试在HyperV Manager中启动VM(升级到Windows 8.1后,无法运行Windows Phone模拟器而没有内存错误).
但是现在,即使我开始它,它仍然无法工作(图片如下).

当我开始使用Application Deployment在WVGA(而不是WVGA 512 MB)模拟器中测试xap文件时,发生了错误,模拟器没有启动,之后无论我尝试了什么版本的模拟器,都出现了同样的错误.
我尝试删除VM Manager中的所有VM,然后启动VS并再次运行模拟器,但它仍然无法正常工作.我也重新启动了Windows,但问题仍然没有解决.我正在使用VS2012和Windows 8.1.
我的目标只是从Firebase检索数据,然后在Android中将其作为ListView输出(无需将任何内容推送回数据库).我试图从AndroidChat示例中学习并创建了我自己的类和我自己的Custom List Adapter类,而不是Chat.java和ChatListAdapter.java(如在orignal示例中).我还更改了对Firebase的引用,并将我的数据结构更改为https://android-chat.firebaseio-demo.com/.下面是我的数据结构:(以下所有内容与AndroidChat示例相同,只是不同的变量名称)

我自己的班级:
package com.firebase.androidchat;
public class MenuItem {
private String food;
private String weekDay;
// Required default constructor for Firebase object mapping
@SuppressWarnings("unused")
private MenuItem() { }
MenuItem(String food, String weekDay) {
this.food = food;
this.weekDay = weekDay;
}
public String getFood() {
return food;
}
public String getWeekDay() {
return weekDay;
}
}
Run Code Online (Sandbox Code Playgroud)
我自己的自定义列表适配器类:
package com.firebase.androidchat;
import android.app.Activity;
import android.view.View;
import android.widget.TextView;
import com.firebase.client.Query;
public class MenuListAdapter extends FirebaseListAdapter<MenuItem> {
public MenuListAdapter(Query ref, …Run Code Online (Sandbox Code Playgroud) 我有一个视图层次结构如下:
GridView{id=2131362110, res-name=item_list_grid,
|
+----->RelativeLayout{id=2131362124, res-name=item_image_thumb_layout
|
+------------->ImageView{id=2131362125, res-name=item_image
|
+----->RelativeLayout{id=2131362124, res-name=item_image_thumb_layout
|
+------------->ImageView{id=2131362125, res-name=item_image
|
+------>RelativeLayout{id=2131362124, res-name=item_image_thumb_layout
|
+------------->ImageView{id=2131362125, res-name=item_image
|
GridView{id=2131362110, res-name=item_list_grid, ...etc
Run Code Online (Sandbox Code Playgroud)
我想点击其中一个带有id = item_image的ImageView.
我不能像atPosition(x)一样使用onView,所以我使用了onData.我尝试了所有这些:
onData(allOf(anything(),withId(R.id.item_image))).atPosition(0).perform(click());
onData(anything()).atPosition(0).perform(click());
onData(allOf(atPosition(0),withId(R.id.item_image))).perform(click());
Run Code Online (Sandbox Code Playgroud)
但所有结果都是
android.support.test.espresso.AmbiguousViewMatcherException: 'is assignable from class: class android.widget.AdapterView' matches multiple views in the hierarchy.
Run Code Online (Sandbox Code Playgroud)
有什么建议吗?谢谢!
正如标题所说,我想在锁定图标和文本之间留出一点空间.

这是我目前的XML:
<EditText
android:id="@+id/guide_payment_settings_email_et"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="5dp"
android:background="@drawable/border_paylpal_blue"
android:drawableLeft="@drawable/blue_rounded_lock"
android:hint="name@example.com"
android:inputType="textEmailAddress"
android:singleLine="true"
android:textColor="#4d4e5b"
android:textSize="12sp" />
Run Code Online (Sandbox Code Playgroud) 我试图选择tabindex大于-1的所有元素(可聚焦元素).到目前为止,这是我提出的:
$element.find('[tabindex]:not([tabindex < \'0\'])');
Run Code Online (Sandbox Code Playgroud)
它不起作用,而是抛出一个错误:
Error: Syntax error, unrecognized expression: [tabindex < '0']
at Function.Sizzle.error (vendor.js:1463)
...
Run Code Online (Sandbox Code Playgroud)
然而,这可行,但它不包括tabindex <-1的情况.
$element.find('[tabindex]:not([tabindex=\'-1\'])');
Run Code Online (Sandbox Code Playgroud) android ×7
angularjs ×3
java ×2
firebase ×1
google-maps ×1
jackson ×1
jasmine ×1
jquery ×1
json ×1
listview ×1
spring ×1
spring-boot ×1
testing ×1
unit-testing ×1