I've ran into an issue that I can't seem to get the syntax right. I want to loop through the records in a grid and click a delete icon to validate the correct actions occur. I understand that the loop is synchronous and t.click is async, but I don't know how to apply the steps parm in the following code snippet. For example, there are 9 items in my grid and the click event is only firing once.
How exactly would I go about this?
var steps = [];
for (i = 0; i < lStoreCount; i++) {
steps.push(function (next) { t.moveMouseTo([(lControlX - 5), lControlY], next); })
steps.push(function (next) { t.click(); })
}
t.chain.apply(t, steps);
Thanks, I'll give it a shot. So when I set up the "steps" array, it needs to be name:value pair like you have listed? We are using a template icon in the cell for delete/add, so I need to move the mouse slightly to the left prior to the click event.
A step can be either an object {}, or a function(next, args...) { }. If you have to rely on specific coordinates then each step should be a click action with a target function returning the XY coordinates you want to click. Does this help?
Excellent! I appreciate the help. Here are my code snippets for anyone interested in combining a loop with a t.click, followed by assertions.
//1. Find the center of the grid cell with the action column.
//2. Move the mouse to the left 5 pixels
var lControlX = (t.findCenter(t.getCell(Grid, 0, 0))[0] - 5);
var lControlY = t.findCenter(t.getCell(Grid, 0, 0))[1];
var steps = [];
for (i = 0; i < lStoreCount; i++) {
steps.push({ action: 'click', target: function () { return [lControlX, lControlY]; } });
}
The following combines the steps object with an additional function to validate results.
t.chain(
steps,
function () {
var lStoreCount = Ext.StoreManager.lookup('MyGridStore').count();
t.is(lStoreCount, 0, "MyGridStore: Store/grid items deleted successfully.");
t.ok(loExport.disabled == true, "Export button is correctly disabled");
});