Protractor: how to click all delete buttons in a page object - protractor

I have a table with 3 rows of data and 3 delete buttons. I want to delete all rows of data and so am trying to write a method in my page object to do so... this should be a snap but I can't get it to work. I'm trying it like this:
this.rows = element.all(by.repeater('row in rows'));
this.deleteAllFriends = function() {
this.rows.each(function(row) {
row.$('i.icon-trash').click();
})
};
But this throws an error:
Error: Index out of bound. Trying to access index:2, but locator: by.repeater("row in rows") only has 1 elements
So obviously, the index protractor expects next is no longer there, because it's been deleted. How can I work around this?
This also does not work and throws the same error:
this.deleteButtons = $$('i.icon-trash');
this.deleteAllFriends = function() {
this.deleteButtons.each(function(button) {
button.click();
});
};
This also doesn't work...
this.deleteAllFriends = function() {
while(this.deleteButton.isDisplayed()) {
this.deleteButton.click();
}
};

With today's version >= 1.3.0 of Protractor you are now be able to do this at once
$$('i.icon-trash').click();
feat(protractor): allow advanced features for ElementArrayFinder

I finally figured it out...
this.deleteButtons = $$('i.icon-trash'); // locator
this.deleteAllFriends = function() {
var buttons = this.deleteButtons;
buttons.count().then(function(count) {
while(count > 0) {
buttons.first().click();
count--;
}
})
};

Related

Flutter update a map value inside a list

Hello everyone i am trying to update a map value inside of a list if the value already exists then it should just update the quantity. The problem is that the code only works for the first entry and does not work for the rest of them.
here is my code.
for (var map in items) {
print(countItem.indexOf(_productIndex));
if (map['\'id\''] == '\'$_productIndex\'') {
var toRemove = countItem.indexOf(_productIndex);
items.removeAt(toRemove);
items.add({
'\'totalQuantity\'': count,
'\'type\'': '\'unit\'',
'\'id\'': '\'$_productIndex\'',
'\'price\'': count * int.parse(_productPrice),
'\'name\'': '\'$_productName\'',
});
} else {
items.add({
'\'totalQuantity\'': count,
'\'type\'': '\'unit\'',
'\'id\'': '\'$_productIndex\'',
'\'price\'': int.parse(_productPrice),
'\'name\'': '\'$_productName\'',
});
}
break;
}
Your using indexOf for the wrong variable. Change it from _productIndex to map.
for (var map in items) {
print(countItem.indexOf(map));
...

SAPUI5 oData POST 500 error

I'm trying to do a oData create on checkbox pressed and getting the following errors. Not sure if this is front end or a back end ABAP issue as have got this same function working in another project.
It is failing on the create part but strangely is still passing through the details for SiteId, ArticleNumber, VarianceDate & Confirmed.
// Set CheckBox status, X for true, blank for false
onVarianceChecked: function (oEvent) {
var oEntry = {};
var bindingContext = oEvent.getSource().getBindingContext(this.MODEL_VIEW);
var path = bindingContext.getPath();
var object = bindingContext.getModel("SI").getProperty(path);
// Pass in the Header fields
oEntry.SiteId = this.SiteId;
oEntry.ArticleNumber = object.ArticleNumber;
oEntry.VarianceDate = moment(new Date(object.VarianceDate)).format('YYYY-MM-DDTHH:mm:ss');
// Set X or blank
if (oEvent.getParameter("selected") === true) {
oEntry.Confirmed = "X";
} else {
oEntry.Confirmed = "";
}
// Do the create
var oModel = this.getView().getModel("SI");
oModel.create("/VarianceHeaderSet", oEntry, {
success: function () {
console.log("Variance confirmed");
MessageToast.show("Variance confirmed", {
duration: 1000
});
},
error: function (oError) {
console.log("Error, variance could not be confirmed");
MessageToast.show("Error, variance could not be confirmed", {
duration: 1000
});
}
});
}
'000000000' is the initial value for Edm.DateTime, hence it will fail when you have modelled a DateTime property to not be nullable.
Go to SEGW and change the property to "nullable" or make sure that you always provide a correct Date in the POST.

arc-jsapi How can I st_geometry using a lookup field?

I am using the st_geometry field and try to view the PNU code value.
I tried two ways.
oracle DB query.
select a.pnu from LP_PA_CBND_4600000000 a
where sde.st_contains(a.shape,
sde.st_point(177566.6728471977,160430.12935426735, 4))=1
When an event occurs, click the map object
i got the evt.mapPoint(x,y).
4 is my srid.
this way is took a long time. and query was down...
i used the arcgis api`s IdentifyParameters
my code is follows.
PoiClick : function(map, evt) {
G_evt =evt;
console.log("ClickPoint ==== "+evt.mapPoint);
var targetLayerId = 'LP_PA_CBND';
var url = map.Layers.getLayerInfo(targetLayerId).SVC_URL;
var map = map.getMap();
//파라미터 설정.
var idParams = new krcgis.core.tasks.IdentifyParameters();
G_idparams =idParams;
idParams.geometry = evt.mapPoint;
idParams.mapExtent = map.extent;
idParams.returnGeometry = true;
idParams.tolerance = 3;
idParams.layerOption = krcgis.core.tasks.IdentifyParameters.LAYER_OPTION_ALL;
idParams.width = map.width;
idParams.height = map.height;
krcgis.Function.GetPoiInfo(url, idParams);
return evt.mapPoint;
},
//POI 정보를 가져온다.
GetPoiInfo : function(url, idParams) {
idTask = new krcgis.core.tasks.IdentyfyTask(url);
idTask
.execute(idParams)
.addCallback(function (response) {
G_response = response;
if (response) {
return response;
}
})
.addErrback(function (error) {
console.log('GetPoiInfo result error=', error);
});
}
It could be obtained in this way code pnu.
However, this way is different from the value that gets pnu code depending on the zoom level.
I want to get a single pnu code in a single x, y values.
how to get pnu code?
Database table :
IdentifyTask can be a little tricky, because it takes into account zoom levels, therefor it doesn't always return the same results.
I suggest that you use QueryTask. Just one problem - it doesn't have tolerance parameter, but you can buffer your evt.mapPoint and get Polygon.

Trying to work with down() method from ExtJS 4.2.1

I am trying to find a specific element from my page using ExtJS 4 so I can do modifications on it.
I know its id so it should not be a problem BUT
-I tried Ext.getCmp('theId') and it just return me undefined
-I tried to use down('theId') method by passing through the view and I still get a nullresponse.
As I know the id of the element I tried again the two methods by setting manually the id and it didn't work neither.
Do these two methods not function?
How should I do?
Here is the concerned part of the code :
listeners: {
load: function(node, records, successful, eOpts) {
var ownertree = records.store.ownerTree;
var boundView = ownertree.dockedItems.items[1].view.id;
var generalId = boundView+'-record-';
// Add row stripping on leaf nodes when a node is expanded
//
// Adding the same feature to the whole tree instead of leaf nodes
// would not be much more complicated but it would require iterating
// the whole tree starting with the root node to build a list of
// all visible nodes. The same function would need to be called
// on expand, collapse, append, insert, remove and load events.
if (!node.tree.root.data.leaf) {
// Process each child node
node.tree.root.cascadeBy(function(currentChild) {
// Process only leaf
if (currentChild.data.leaf) {
var nodeId = ""+generalId+currentChild.internalId;
var index = currentChild.data.index;
if ((index % 2) == 0) {
// even node
currentChild.data.cls.replace('tree-odd-node', '')
currentChild.data.cls = 'tree-even-node';
} else {
// odd node
currentChild.data.cls.replace('tree-even-node', '')
currentChild.data.cls = 'tree-odd-node';
}
// Update CSS classes
currentChild.triggerUIUpdate();
console.log(nodeId);
console.log(ownertree.view.body);
console.log(Ext.getCmp(nodeId));
console.log(Ext.getCmp('treeview-1016-record-02001001'));
console.log(ownertree.view.body.down(nodeId));
console.log(ownertree.view.body.down('treeview-1016-record-02001001'));
}
});
}
}
You can see my console.log at the end.
Here is what they give me on the javascript console (in the right order):
treeview-1016-record-02001001
The precise id I am looking for. And I also try manually in case...
h {dom: table#treeview-1016-table.x-treeview-1016-table x-grid-table, el: h, id: "treeview-1016gridBody", $cache: Object, lastBox: Object…}
I checked every configs of this item and its dom and it is exactly the part of the dom I am looking for, which is the view containing my tree. The BIG parent
And then:
undefined
undefined
null
null
Here is the item I want to access:
<tr role="row" id="treeview-1016-record-02001001" ...>
And I checked there is no id duplication anywhere...
I asked someone else who told me these methods do not work. The problem is I need to access this item to modify its cls.
I would appreciate any idea.
You are looking for Ext.get(id). Ext.getCmp(id) is used for Ext.Components, and Ext.get(id) is used for Ext.dom.Elements. See the docs here: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext-method-get
Ok so finally I used the afteritemexpand listener. With the ids I get the elements I am looking for with your Ext.get(id) method kevhender :).
The reason is that the dom elements where not completely loaded when I used my load listener (it was just the store) so the Ext.get(id) method couldn't get the the element correctly. I first used afterlayout listener, that was correct but too often called and the access to the id was not so easy.
So, here is how I did finally :
listeners: {
load: function(node, records, successful, eOpts) {
var ownertree = records.store.ownerTree;
var boundView = ownertree.dockedItems.items[1].view.id;
var generalId = boundView+'-record-';
if (!node.tree.root.data.leaf) {
// Process each child node
node.tree.root.cascadeBy(function(currentChild) {
// Process only leaf
if (currentChild.data.leaf) {
var nodeId = ""+generalId+currentChild.internalId;
var index = currentChild.data.index;
if ( (index % 2) == 0 && ids.indexOf(nodeId) == -1 ) {
ids[indiceIds] = nodeId;
indiceIds++;
}
console.log(ids);
}
});
}
},
afteritemexpand: function( node, index, item, eOpts ){
/* This commented section below could replace the load but the load is done during store loading while afteritemexpand is done after expanding an item.
So, load listener makes saving time AND makes loading time constant. That is not the case if we just consider the commented section below because
the more you expand nodes, the more items it will have to get and so loading time is more and more important
*/
// var domLeaf = Ext.get(item.id).next();
// for ( var int = 0; int < node.childNodes.length; int++) {
// if (node.childNodes[int].data.leaf && (int % 2) == 0) {
// if (ids.indexOf(domLeaf.id) == -1) {
// ids[indiceIds] = domLeaf.id;
// indiceIds++;
// }
// }
// domLeaf = domLeaf.next();
// }
for ( var int = 0; int < ids.length; int++) {
domLeaf = Ext.get(ids[int]);
if (domLeaf != null) {
for ( var int2 = 0; int2 < domLeaf.dom.children.length; int2++) {
if (domLeaf.dom.children[int2].className.search('tree-even-node') == -1){
domLeaf.dom.children[int2].className += ' tree-even-node';
}
}
}
}
},
With ids an Array of the ids I need to set the class.
Thank you for the method.

tinymce.dom.replace throws an exception concerning parentNode

I'm writing a tinyMce plugin which contains a section of code, replacing one element for another. I'm using the editor's dom instance to create the node I want to insert, and I'm using the same instance to do the replacement.
My code is as follows:
var nodeData =
{
"data-widgetId": data.widget.widgetKey(),
"data-instanceKey": "instance1",
src: "/content/images/icon48/cog.png",
class: "widgetPlaceholder",
title: data.widget.getInfo().name
};
var nodeToInsert = ed.dom.create("img", nodeData);
// Insert this content into the editor window
if (data.mode == 'add') {
tinymce.DOM.add(ed.getBody(), nodeToInsert);
}
else if (data.mode == 'edit' && data.selected != null) {
var instanceKey = $(data.selected).attr("data-instancekey");
var elementToReplace = tinymce.DOM.select("[data-instancekey=" + instanceKey + "]");
if (elementToReplace.length === 1) {
ed.dom.replace(elementToReplace[0], nodeToInsert);
}
else {
throw new "No element to replace with that instance key";
}
}
TinyMCE breaks during the replace, here:
replace : function(n, o, k) {
var t = this;
if (is(o, 'array'))
n = n.cloneNode(true);
return t.run(o, function(o) {
if (k) {
each(tinymce.grep(o.childNodes), function(c) {
n.appendChild(c);
});
}
return o.parentNode.replaceChild(n, o);
});
},
..with the error Cannot call method 'replaceChild' of null.
I've verified that the two argument's being passed into replace() are not null and that their parentNode fields are instantiated. I've also taken care to make sure that the elements are being created and replace using the same document instance (I understand I.E has an issue with this).
I've done all this development in Google Chrome, but I receive the same errors in Firefox 4 and IE8 also. Has anyone else come across this?
Thanks in advance
As it turns out, I was simply passing in the arguments in the wrong order. I should have been passing the node I wanted to insert first, and the node I wanted to replace second.