on xenial help sign in
A more resilient way to find the item
1729f76Albert Astals
tests/qmltests/Dash/tst_DashContent.qml+28−11
@@ -273,6 +273,33 @@ Item {
273 tryCompare(scopesModel.get(2), "isActive", data.active2);
273 tryCompare(scopesModel.get(2), "isActive", data.active2);
274 }
274 }
275
275
276+ function doFindMusicButton(parent) {
277+ console.log("P", parent);
278+ for (var i = 0; i < parent.children.length; i++) {
279+ var c = parent.children[i];
280+ if (UT.Util.isInstanceOf(c, "AbstractButton") && parent.x >= 0) {
281+ for (var ii = 0; ii < c.children.length; ii++) {
282+ var cc = c.children[ii];
283+ if (UT.Util.isInstanceOf(cc, "Label") && cc.text == "Music") {
284+ return c;
285+ }
286+ }
287+ }
288+ var r = doFindMusicButton(c);
289+ if (r !== undefined) {
290+ return r;
291+ }
292+ }
293+ return undefined;
294+ }
295+
296+ function findMusicButton() {
297+ // We need to find a AbstractButton that has a Label child
298+ // with text Music and it's parent x is >= 0
299+ var tabbar = findChild(dashContent, "tabbar");
300+ return doFindMusicButton(tabbar);
301+ }
302+
276 function test_tabBar_index_change() {
303 function test_tabBar_index_change() {
277 console.log("A");
304 console.log("A");
278 tryCompare(scopesModel, "loaded", true);
305 tryCompare(scopesModel, "loaded", true);
@@ -292,20 +319,10 @@ Item {
292 tryCompare(dashContent, "currentIndex", 0);
319 tryCompare(dashContent, "currentIndex", 0);
293
320
294 var button;
321 var button;
295− tryCompareFunction(function() {
322+ tryCompareFunction(function() { button = findMusicButton(); return button != undefined; }, true);
296− if (tabbar.children[0].children[0].children[0].children[1].x >= 0) {
297− button = tabbar.children[0].children[0].children[0].children[1].children[1];
298− } else {
299− button = tabbar.children[0].children[0].children[0].children[2].children[1];
300− }
301− return button != undefined;
302− }, true);
303 console.log("E", button);
323 console.log("E", button);
304 waitForRendering(button);
324 waitForRendering(button);
305
325
306− UT.Util.isInstanceOf(button, "AbstractButton");
307− UT.Util.isInstanceOf(button.children[3], "Label");
308− tryCompare(button.children[3], "text", "Music");
309 console.log("F");
326 console.log("F");
310
327
311 mouseClick(button, button.width / 2, button.height / 2)
328 mouseClick(button, button.width / 2, button.height / 2)