@@ -55,17 +55,40 @@ Item {
55 when: windowShown
55 when: windowShown
57 function initTestCase() {
57 function initTestCase() {
58− // Ensure DashHome is loaded before continuing
58+ var ok = false;
60+ var maxAttempts = 1000;
62+ // Qt loads a qml scene asynchronously. So early on, some findChild() calls made in
63+ // tests may fail because the desired child item wasn't loaded yet.
64+ // Thus here we try to ensure the scene has been fully loaded before proceeding with the tests.
65+ // As I couldn't find an API in QQuickView & friends to tell me that the scene is 100% loaded
66+ // (all items instantiated, etc), I resort to checking the existence of some key items until
67+ // repeatedly until they're all there.
59− var dashContentList = findChild(shell, "dashContentList");
69+ var dashContentList = findChild(shell, "dashContentList");
60− waitForRendering(dashContentList);
70+ waitForRendering(dashContentList);
61− var homeLoader = findChild(dashContentList, "home.scope loader");
71+ var homeLoader = findChild(dashContentList, "home.scope loader");
72+ ok = homeLoader !== undefined
73+ && homeLoader.item !== undefined;
75+ var greeter = findChild(shell, "greeter");
76+ ok &= greeter !== undefined;
78+ var launcherPanel = findChild(shell, "launcherPanel");
79+ ok &= launcherPanel !== undefined;
83+ console.log("Attempt " + attempts + " failed. Waiting a bit before trying again.");
84+ // wait a bit before retrying
87+ console.log("All seem fine after " + attempts + " attempts.");
89+ } while (!ok && attempts <= maxAttempts);
62− verify(homeLoader);
91+ verify(ok);
63− tryCompareFunction(function() {return homeLoader.item !== undefined;}, true);
65− // FIXME: Desperate measure to ensure Jenkins has the scene graph fully loaded
66− // before it calls the test functions (otherwise findChild calls will fail).
67− // The code above just didn't solve it.
70 swipeAwayGreeter();
93 swipeAwayGreeter();