In Detox I setup an expectation by label for 'SIGN IN', which returns 'Multiple Elements Found...'. However, when I try to filter it out by type I get the following error
DetoxRuntimeError: Test Failed: No elements found for “MATCHER(class ⊇
“RCTTextView”)”
Below is the elements I get when I use by.label('SIGN IN').getAttributes(). Even thought one of the elements contains RCTTextView it still can't be found.
{
"elements": [
{
"layer": "<CALayer: 0x600002d5c0c0>",
"hittable": true,
"elementSafeBounds": {
"y": 0,
"x": 0,
"width": 339,
"height": 39.5
},
"enabled": true,
"activationPoint": {
"x": 169.5,
"y": 19.75
},
"elementFrame": {
"y": 331.5,
"x": 18,
"width": 339,
"height": 39.5
},
"visible": true,
"label": "SIGN IN",
"className": "RCTView",
"safeAreaInsets": {
"right": 0,
"top": 0,
"left": 0,
"bottom": 0
},
"frame": {
"y": 351.5,
"x": 18,
"width": 339,
"height": 39.5
},
"normalizedActivationPoint": {
"x": 0.5,
"y": 0.5
},
"elementBounds": {
"y": 0,
"x": 0,
"width": 339,
"height": 39.5
}
},
{
"safeAreaInsets": {
"right": 0,
"top": 0,
"left": 0,
"bottom": 0
},
"enabled": true,
"visible": true,
"frame": {
"y": 351.5,
"x": 18,
"width": 339,
"height": 39.5
},
"elementBounds": {
"y": 0,
"x": 0,
"width": 339,
"height": 39.5
},
"elementFrame": {
"y": 0,
"x": 0,
"width": 339,
"height": 39.5
},
"layer": "<CALayer: 0x600002d5c5e0>",
"className": "RCTView",
"label": "SIGN IN",
"activationPoint": {
"x": 169.5,
"y": 19.75
},
"normalizedActivationPoint": {
"x": 0.5,
"y": 0.5
},
"hittable": true,
"elementSafeBounds": {
"y": 0,
"x": 0,
"width": 339,
"height": 39.5
}
},
{
"visible": true,
"frame": {
"y": 351.5,
"x": 18,
"width": 339,
"height": 39.5
},
"activationPoint": {
"x": 169.5,
"y": 19.75
},
"enabled": true,
"elementSafeBounds": {
"y": 0,
"x": 0,
"width": 339,
"height": 39.5
},
"hittable": true,
"label": "SIGN IN",
"normalizedActivationPoint": {
"x": 0.5,
"y": 0.5
},
"layer": "<CALayer: 0x600002d5cc80>",
"safeAreaInsets": {
"right": 0,
"top": 0,
"left": 0,
"bottom": 0
},
"elementBounds": {
"y": 0,
"x": 0,
"width": 339,
"height": 39.5
},
"className": "RCTView",
"elementFrame": {
"y": 0,
"x": 0,
"width": 339,
"height": 39.5
}
},
{
"enabled": true,
"visible": true,
"label": "SIGN IN",
"normalizedActivationPoint": {
"x": 0.5,
"y": 0.5
},
"frame": {
"y": 359.5,
"x": 155.5,
"width": 64,
"height": 24
},
"elementFrame": {
"y": 8,
"x": 137.5,
"width": 64,
"height": 24
},
"elementBounds": {
"y": 0,
"x": 0,
"width": 64,
"height": 24
},
"safeAreaInsets": {
"right": 0,
"top": 0,
"left": 0,
"bottom": 0
},
"className": "RCTTextView",
"activationPoint": {
"x": 32,
"y": 12
},
"elementSafeBounds": {
"y": 0,
"x": 0,
"width": 64,
"height": 24
},
"layer": "<CALayer: 0x600002c925c0>",
"hittable": true
}
]
}
What should I look into in order to fix the element type matcher?
I am currently working on a health application and i don't know how to decode this sample json using flutter. I want to extract "heartRateZones" list.
{
"activities-heart": [{
"dateTime": "2015-08-04",
"value": {
"customHeartRateZones": [],
"heartRateZones": [{
"caloriesOut": 740.15264,
"max": 94,
"min": 30,
"minutes": 593,
"name": "Out of Range"
}, {
"caloriesOut": 249.66204,
"max": 132,
"min": 94,
"minutes": 46,
"name": "Fat Burn"
}, {
"caloriesOut": 0,
"max": 160,
"min": 132,
"minutes": 0,
"name": "Cardio"
}, {
"caloriesOut": 0,
"max": 220,
"min": 160,
"minutes": 0,
"name": "Peak"
}],
"restingHeartRate": 68
}
}]
}
Please Help...
JSON is hosted at https://api.myjson.com/bins/g05ga .
According to the documentation, you should use json.decode and you will be able to extract what you want.
You can then use it somehow like this activities-heart.value.heartRateZones
I am hoping this is a one off, but today I came across a video that reports the following when calling the "Videos: list" endpoint by a videoId:
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/hqdefault.jpg",
"width": 480,
"height": 360
},
"standard": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/sddefault.jpg",
"width": 640,
"height": 480
},
"maxres": {
"url": "https://i.ytimg.com/vi/**uEGlS01**/maxresdefault.jpg",
"width": 1280,
"height": 720
}
}
... but neither the "maxres" or "standard" urls render an image (they 404 and render the nasty YouTube default grey image). Usually when those sizes were not available, those objects were not in the array.
Can anyone shed some light on this?
EDIT **
I should mention that the remainder of the thumb urls work as expected and embedding of the video fails to render a poster image with the exception of Chrome on desktop (which uses WEBP)
I suspect this is a fairly basic concept, but two days of trial and error, google searches, and random keyboard mashing have worn me down. I'm attempting to parse JSON returned from a URL, but I'm running into an issue that I suspect is related to the array inside the JSON.
What am I doing wrong?
JSON:
{
"HotelInformationResponse": {
"#hotelId": "106347",
"customerSessionId": "0ABAA83F-4430-B291-3432-E0A2DC790CA0",
"HotelImages": {
"#size": "16",
"HotelImage": [
{
"hotelImageId": 4694179,
"name": "",
"category": 1,
"type": 0,
"caption": "Exterior",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_44_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_44_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694182,
"name": "",
"category": 2,
"type": 0,
"caption": "Lobby",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_47_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_47_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694171,
"name": "",
"category": 2,
"type": 0,
"caption": "Lobby",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_36_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_36_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694174,
"name": "",
"category": 2,
"type": 0,
"caption": "Lobby",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_39_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_39_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694168,
"name": "",
"category": 3,
"type": 0,
"caption": "Guest Room",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_33_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_33_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694173,
"name": "",
"category": 3,
"type": 0,
"caption": "Guest Room",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_38_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_38_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694177,
"name": "",
"category": 3,
"type": 0,
"caption": "Guest Room",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_42_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_42_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694165,
"name": "",
"category": 10,
"type": 0,
"caption": "Restaurant",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_30_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_30_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694166,
"name": "",
"category": 10,
"type": 0,
"caption": "Restaurant",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_31_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_31_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 6601500,
"name": "",
"category": 11,
"type": 0,
"caption": "Interior",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_56_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_56_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694176,
"name": "",
"category": 12,
"type": 0,
"caption": "Pool",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_41_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_41_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694170,
"name": "",
"category": 12,
"type": 0,
"caption": "Pool",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_35_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_35_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694172,
"name": "",
"category": 12,
"type": 0,
"caption": "Pool",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_37_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_37_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694180,
"name": "",
"category": 21,
"type": 0,
"caption": "Lounge/Bar",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_45_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_45_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694181,
"name": "",
"category": 21,
"type": 0,
"caption": "Lounge/Bar",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_46_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_46_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
},
{
"hotelImageId": 4694175,
"name": "",
"category": 38,
"type": 0,
"caption": "Suite",
"url": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_40_b.jpg",
"thumbnailUrl": "http://images.travelnow.com/hotels/1000000/10000/5900/5900/5900_40_t.jpg",
"supplierId": 13,
"width": 350,
"height": 350,
"byteSize": 0
}
]
}
}
}
My simplified code:
api = Expedia::Api.new
response = api.get_information({:hotelId => '106347'})
data = response.body
parsed = JSON.parse(data.to_json)
thumbnail = parsed['HotelInformationResponse']['HotelImages']['HotelImage']['thumbNailUrl']
This returns an error "no implicit conversion of String into Integer" at the thumbnail line. I understand that the JSON lists more then one 'thumbNailUrl', and I need to specify with I'm requesting, but I'm not sure how. I would just like to retrieve the first 'thumbNailUrl'.
Incidentally, the EAN API gem I'm using is located here: https://github.com/zaidakram/expedia
This line parsed['HotelInformationResponse']['HotelImages'] gives you an Array of Hash. So you need to access each Hash inside the array by index(s). Thus you need to go as below :-
parsed['HotelInformationResponse']['HotelImages']['HotelImage'][0]['thumbnailUrl']
If you want to get all thumbnails then, iterate over it as
thumbnails = parsed['HotelInformationResponse']['HotelImages']['HotelImage'].map do |hash|
hash[thumbnailUrl]
end
To get the first hotel image you can do:
thumbnail = parsed['HotelInformationResponse']['HotelImages']['HotelImage'][0]['thumbNailUrl']
If you wanted to get all the thumbnails you can do something like:
thumbnails = []
parsed['HotelInformationResponse']['HotelImages']['HotelImage'].each { |thumbnail| thumbnails << thumbnail['thumNailUrl'] }