How to verify buttons which are like images - ruby

when i give a query in terminal like
query "* id:'btn_addRemove'"
Then i am getting an output like
[0] {
"id" => "btn_addRemove",
"enabled" => true,
"contentDescription" => nil,
"class" => "android.widget.ImageView",
"rect" => {
"center_y" => 353,
"center_x" => 622,
"height" => 120,
"y" => 293,
"width" => 140,
"x" => 552
},
"tag" => nil,
"description" => "android.widget.ImageView{4307ec68 V.ED..C. ........ 552,35-692,155 #7f06006e app:id/btn_addRemove}"
},
[1] {
"id" => "btn_addRemove",
"enabled" => true,
"contentDescription" => nil,
"class" => "android.widget.ImageView",
"rect" => {
"center_y" => 559,
"center_x" => 622,
"height" => 120,
"y" => 499,
"width" => 140,
"x" => 552
},
"tag" => nil,
"description" => "android.widget.ImageView{430557b8 V.ED..C. ........ 552,35-692,155 #7f06006e app:id/btn_addRemove}"
},
Now problem is the "id" is same for both the buttons and when i click on the button , then it will change to green with some image in it and when i click again, the buttton changed to normal one which shows before.
How do i verify this ?

If you have multiple element with same IDs.
Then you can click or verify element using index.
query("ImageView css:'#'btn_addRemove'")[0]
Let me know, if you issue get resolved.

Related

Default value for select in custom Modifier

I have a select field from a form defined like bellow. As you can see that select has two values, Yes and No. I'm looking to set a default value for this select.
"children" => [
"bc_offer_is_duration_count_fixed" => [
"arguments" => [
"data" => [
"config" => [
"dataType" => "select",
"formElement" => "select",
"visible" => "1",
"required" => "1",
"validation" => [
'required-entry' => "1"
],
"default" => null,
"label" => __('Is duration count fixed'),
"scopeLabel" => __('[GLOBAL]'),
"code" => "bc_offer_offer_durations",
"source" => "content",
"globalScope" => true,
"sortOrder" => 10,
"componentType" => "field",
"component" => "Project_OfferProducts/js/form/element/offer-is-duration-count-fixed",
'options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]
]
]
]
]
]
It's part of the modifyData method from a class defined here
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier as CatalogAbstractModifier;
abstract class AbstractModifier extends CatalogAbstractModifier
Obviously I already tried to set "default" => "Yes" and "default" => "1" and "default" => 1
I also have an offer-js-duration-count-fixed.js file with that content
define([
'Magento_Ui/js/form/element/select',
'Project_OfferProducts/js/model/offer-configuration/context'
], function (Select, context) {
'use strict';
return Select.extend({
updatingDurationFromField: false,
initialize: function () {
this._super();
context.isDurationCountFixed.subscribe(function(newValue){
this.refreshInField(newValue);
}.bind(this));
this.value.subscribe(this.refreshInGrid.bind(this));
if(context.isDurationCountFixed())
{
this.value(1);
}
else
{
this.value(0);
}
return this;
},
refreshInGrid: function(){
this.updatingDurationFromField = true;
context.isDurationCountFixed(this.value());
this.updatingDurationFromField = false;
},
refreshInField: function(newValue){
if(!this.updatingDurationFromField)
{
this.value(context.isDurationCountFixed());
}
}
});});
I'm under Magento 2.
just what i think
change this
'options' => [['label' => __('Yes'), 'value' => '1'], ['label' => __('No'), 'value' => '0']]
to
'options' => [['label' => __('Yes'), 'value' => 1], ['label' => __('No'), 'value' => 0]]
and change
"default" => null,
to
"default" => "1",

Display contents of a hash if value exists

I have a hash:
req = {
"count" => 50100,
"results" => [
{"listing_id" => 615929315, "state" => "active", "user_id" => 140604756, "category_id" => 69150367},
{"listing_id" => 615929311, "state" => "active", "user_id" => 152528025, "category_id" => 69150367}
]
}
I want to find and display the entire internal hash if a particular user_id exists. I can find it:
req["results"][0].select{|key, value| value == 152528025}
# => {"user_id" => 152528025}
How do I then display this entire (nested) hash?
{"listing_id" => 615929311, "state" => "active", "user_id" => 152528025, "category_id" => 69150367}
req["results"].select{|x| x["user_id"] == 152528025}

How Get Index If Object In Array Contains Desired Value in Ruby

So this is an array I get from somewhere and I wanted to get the index of the object that contains "text" => "Assets". How can i do that in Ruby?
Example
[{
"class" => "android.support.v7.widget.AppCompatTextView",
"tag" => nil,
"description" => "android.support.v7.widget.AppCompatTextView{b777d8c V.ED..... ........ 0,39-355,168 #7f0e007f app:id/textview_sectiontitle}",
"id" => "textview_sectiontitle",
"text" => "Assets",
"visible" => true,
"rect" => {
"height" => 129,
"width" => 355,
"y" => 2088,
"x" => 80,
"center_x" => 257,
"center_y" => 2152
},
"enabled" => true,
"contentDescription" => nil
},
{
"class" => "android.support.v7.widget.AppCompatImageButton",
"tag" => nil,
"description" => "android.support.v7.widget.AppCompatImageButton{ae57704 VFED..C.. ........ 1056,0-1280,208 #7f0e0109 app:id/imagebutton_amount}",
"id" => "imagebutton_amount",
"visible" => true,
"rect" => {
"height" => 208,
"width" => 224,
"y" => 2049,
"x" => 1136,
"center_x" => 1248,
"center_y" => 2153
},
"enabled" => true,
"contentDescription" => nil
}]
Try this one
arr.index { |item| item["text"] == "Assets" }

Does the Datadog API support a "partial" update?

I'm looking for a way to do a "partial" update on an existing screenboard/timeboard. By "partial", I mean adding some widget to the existing screenboard/timeboard without wiping out the existing widget that already exist.
Consider the following example:
Create screenboard:
require 'dogapi'
api_key = "..."
application_key = "..."
board = {
"width" => 1024,
"height" => 768,
"board_title" => "bjusufbe dogapi test",
"widgets" => [
{
"type" => "image",
"height" => 20,
"width" => 32,
"y" => 7,
"x" => 32,
"url" => "https://path/to/create_image.jpg"
}
]
}
dog = Dogapi::Client.new(api_key, application_key)
result = dog.create_screenboard(board)
Update screenboard:
require 'dogapi'
api_key = "..."
application_key = "..."
board_id = "..."
board = {
"width" => 1024,
"height" => 768,
"board_title" => "bjusufbe dogapi test",
"widgets" => [
{
"type" => "image",
"height" => 20,
"width" => 32,
"y" => 7,
"x" => 32,
"url" => "https://path/to/update_image.jpg"
}
]
}
dog = Dogapi::Client.new(api_key, application_key)
result = dog.update_screenboard(board_id, board)
When I run the create and then the update example, the update_image widget will overwrite the create_image widget and that is the problem I'm trying to avoid.

ruby one-liner from two hashes

a = {"rows" => [{"id" => "231-z", "name" => 'jon', "age"=> 27, "state" => 'AL'},
{"id" => "4121-x", "name" => 'ton', "age"=> 37, "state" => 'VA'}
]
}
b = {"rows" => [{"key" => ["xyz","4121-x"], "value" =>{"sum" => 12312, "realage" => 29}},
{"key" => ["xyz","231-z"], "value" =>{"sum" => 1212, "realage" => 33}}
]
}
In hash a, age is incorrect
In hash b, realage is correct. Also in hash b id is the second value in the first array that maps to id of hash a . Those are 4121-x, 231-z correspond to hash a
I want to correct the age in hash a and swap it with the realage of hash b
I can do it in multiple steps, but is it possible to do it in one liner or very short? So finally correct hash a should look like
a = {"rows" => [{"id" => "231-z", "name" => 'jon', "age"=> 33, "state" => 'AL'},
{"id" => "4121-x", "name" => 'ton', "age"=> 29, "state" => 'VA'}
]
}
does this look reasonable?
a['rows'].each_with_index do |ah, i|
(bh = b['rows'].select {|h| h['key'].last == ah['id'] }.first) &&
a['rows'][i] = ah.update('age' => bh['value']['realage'])
end
p a
{
"rows" => [
[0] {
"id" => "231-z",
"name" => "jon",
"age" => 33,
"state" => "AL"
},
[1] {
"id" => "4121-x",
"name" => "ton",
"age" => 29,
"state" => "VA"
}
]
}
Please note it will update a only if corresponding id found in b.
Also, the rows order does not matter, nor matter the rows number, it is only important b to have a row with same id as processed row in a
Here is a Working Demo

Resources