Find out in what line Espresso fails exactly - automated-tests

I am running Espresso tests on my Android app. If one fails I the view tree is printed. Unfortunately I don't know in what line this failure occurs exactly.
Is there a way to tell Espresso to print the stack trace when an Exception is thrown (e.g. NoMatchingViewException) so I can see in what line my tests fails?
Thanks
Thomas
EDIT:
Output I get looks like (removed part in the middle):
android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.wombatl.mobility.charge.test:id/stopChargingButton' matches multiple views in the hierarchy.
Problem views are marked with '****MATCHES****' below.
View Hierarchy:
+>DecorView{id=-1, visibility=VISIBLE, width=1080, height=2160, 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, layout-params=WM.LayoutParams{(0,0)(fillxfill) ty=1 fl=#81810100 pfl=0x20000 wanim=0x10302f6 needsMenuKey=2 colorMode=0}, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=3}
|
+->LinearLayout{id=-1, visibility=VISIBLE, width=1080, height=2034, 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, layout-params=android.widget.FrameLayout$LayoutParams#48dbdb, tag=null, root-is-layout-requested=false, has-input-connection=false, x=0.0, y=0.0, child-count=2}
|
(...)
|
+--------------->AppCompatTextView{id=2131361990, res-name=hoursTextView, visibility=VISIBLE, width=68, height=53, has-focus=false, has-focusable=false, has-window-focus=true, is-clickable=false, is-enabled=true, is-focused=false, is-focusable=false, is-layout-requested=false, is-selected=false, layout-params=android.widget.Rela

No, the line number will not be shown in the failure message. You will have to deduce it yourself.

It is clearly stated that you have multiple matches for the view with id stopChargingButton. That's it.
android.support.test.espresso.AmbiguousViewMatcherException: 'with id: com.wombatl.mobility.charge.test:id/stopChargingButton' matches multiple views in the hierarchy.
View matchers should match only one element otherwise Espresso doesn't know what view to operate on and throws the exception. Add additional matching criteria to identify specific view on the screen. You may use allOf() hamcrest matcher for this purpose.
If the view you wanna operate on is the part of the ListView - use onData(). If it is inside RecyclerView look in the documentation how to operate on the item which is the part of the RecyclerView.

Related

Q: [WEATHER] How can I view example Alert response data?

I need to design a program around the possibility of severe weather alerts. With that said, I need to know the structure of the alert object returned. The example in the reference displays an empty array, which doesn't help me much. I can't exactly wait around for an alert to occur; any ideas?
You can see the attributes in alerts here - https://developer.here.com/documentation/weather/topics/resource-type-alert-items.html.
Alerts is an array consisting objects of AlertItemsType which have the below values:
Type of alert
We have 36 support global types which can be viewed here - https://developer.here.com/documentation/weather/topics/supported-alert-types.html
Description of the alert
The TimeSegmentType type defines the attributes this element can have.
For example currently, we see weather alerts for the below query. Replace app_id and ap_code values with actuals.
https://weather.api.here.com/weather/1.0/report.json?product=alerts&app_id=xxxx&app_code=yyyyy&name=Bodenseekreis

Watson Conversation: condition matching input to context array

Taking the car dashboard example, I altered the initial #genre node to be #genre:classical. I also added a list to the contex
"choices":["Beethoven","Mahler 9","Brahms 3rd"]
and the Watson response is "I have 3 selections". The condition on the next node is $choices.contains(input.text). The "Found a match" response is just for testing. It looks like this:
When I test this in the api tool and type "Beethoven" both "Found a match" and "Great choice!..." appear. Same for the other two choices, but only if I type the exact choice, e.g., "Mahler 9". Typing "Mahler" or "mahler" doesn't get a match. I read through the SpEL documentation but couldn't see a way in a one-line condition to parse through the list looking for partial matches.
So my question is, is there an condition expression that would match partial user input, e.g., "Mahler"? I'll be using the Java SDK to code the app server, so alternatively I wondered if I could add a temporary #entity just for this sequence instead of using the context list then delete it when the conversation is done? Or is there a way to construct a more complex condition in the MessageRequest and will Watson recognize it? Or is this just not the right way to go about this? Any pointers, examples or docs much appreciated.
So my question is, is there an condition expression that would match partial user input
You can't add temporary entities or intents. As adding them forces Watson to start training itself (even if you could it through code).
You can however create quite complex regular expressions, pass them in as a context variable.
For example your advanced node can have:
{
"output": {
"text": "Please ask me a question."
},
"context": {
"rx": "fish|[0-9]+"
}
}
Then in you condition you would write.
input.text.matches(context.rx)
This will then trigger if the person mentions a number, or the word fish. So you can create your partial user input checking that way.

Inform 7 error using If player consents

I'm trying to write a piece of interactive fiction using inform 7, I want to put a choice in there for the player and I want a simple yes or no I used the following code:
if the player consents say "You get a better view of the stranger."
Otherwise:
say "You can't make out what's happening clearly, however, you notice the stranger walking out of the pub"
I then get this useless error message:
You wrote 'if the player consents say "You get a better view of the stranger."' : but I can't find a verb that I know how to deal with. This looks like an 'if' phrase which has slipped its moorings, so I am ignoring it. ('If' phrases, like all other such instructions, belong inside definitions of rules or phrases - not as sentences which have no context. Maybe a full stop or a skipped line was accidentally used instead of semicolon, so that you inadvertently ended the last rule early?)
Any help would be greatly appreciated.
The punctuation is off. Phrases should end with a semicolon, and if phrases should use either begin..end blocks, or the "colon-and-indentation" style. So either:
if the player consents begin;
say "You get a better view of the stranger.";
otherwise;
say "You can't make out what's happening clearly, however, you notice the stranger walking out of the pub";
end if;
or
if the player consents:
say "You get a better view of the stranger.";
otherwise:
say "You can't make out what's happening clearly, however, you notice the stranger walking out of the pub";
Note the colons and semicolons and tabs in the second example.
Also, as the error message says, you need to specify when that question should be asked. If phrases must be inside rules or phrases. For example, if the question should be asked as a result of an action:
After examining the stranger for the first time:
say "Move closer?";
if the player consents begin;
say "You get a better view of the stranger.";
otherwise;
say "You can't make out what's happening clearly, however, you notice the stranger walking out of the pub";
end if;

Prolog: Recursion and splitting lists

I'm trying to write a game in which the program reads through a database, grabs attributes and asks the player if the Movie that the player is thinking of will have that attribute. The user will answer either yes or no and if yes, the game will ask about the next attribute until either the user has said yes to every attribute, at that point the program will output the name of the movie. Or if the user says no, the game will then move along to the next movie in the database and start asking about those attributes.
The game ends when either it finds a movie with all the attributes or there are no more movies in the database in which the program could ask about.
Here is the database file.
object_properties(crocodile_dundee,[comedy,australian,paul_hogan_movie]).
object_properties(flipper,[action_movie,australian, paul_hogan_movie,
-comedy]).
object_properties(jackass,[comedy,-australian]).
object_properties(the_godfather,[drama,crime,-character_batman]).
object_properties(the_dark_knight,[drama,crime,character_batman]).
object_properties(the_living_planet, [documentary,director_attenborough]).
object_properties(the_code, [documentary,nerds_love_it]).
object_properties(the_russian_revolution, [documentary,about_history]).
Here is my game file.
go():-
guess_object(0,[]).
guess_object(Obj,[A|As]) :-
object_categories(Obj,A).
guess_object(1).
guess_object(2).
guess_object(3).
guess_object(4).
guess_object(5). %how do i do this specifically for the current Obj attributes?
guess(X) :- guess_object(_, X),
writeln('Does your object have the attribute '(X)'?'),
read(Input), Input=('yes') -> assert(object(X)) ; retractall(X), guess(X).
writeln('I guess that the film is: 'guess_object(Obj,_).
The main questions I have:
How do I split the object attributes in to a list like I'm trying to do on guess_object(1) through to guess_object(5) depending on whether the object has 2 attributes or 4 attributes, etc.
How do I make my guess(A) predicate recursive so once the user says no it will then go to the next object in the database file?
I'm not too great at prolog but any advice or pointers would be greatly appreciated, even if it's just pointing out a stupid mistake I may have made. I will also answer any questions anyone has to the best of my ability.

Applying more than one sort on a Tridion broker query

I have a broker query where I need to sort by 2 different fields (using JSP and 2011 SP1)
The API has the method "addSorting" which I am applying.
It appears, however, that the second addSorting call is overwriting the first addSorting call - rather than adding the second sort:
// Sort by Date
CustomMetaKeyColumn customMetaKeyColumnDate = new CustomMetaKeyColumn("date", MetadataType.DATE);
query.addSorting(new SortParameter(customMetaKeyColumnDate, SortParameter.DESCENDING));
// Sort by Owner
CustomMetaKeyColumn customMetaKeyColumnOwner = new CustomMetaKeyColumn("owner", MetadataType.STRING);
query.addSorting(new SortParameter(customMetaKeyColumnOwner, SortParameter.ASCENDING));
They sorts work fine individually.
Is this expected? Is addSorting really a setSorting - where only 1 sort can be specified or am I missing a way to combine 2 sorts?
The addSorting method works just fine. However, it simply does not work for CustomMeta columns!!! There is already a confirmed defect regarding this subject with the following summary: "SortParameter does not work with two metadata fields". This is still an open defect for 2011SP1 and is scheduled to be fixed only for the next release.
Cheers,
Daniel.

Resources