on xenial help sign in
Trying to make tst_Shell.initTestCase() less hacky and more robust
commitf22c71d8198755c9e496cda8a0b57a0341945dd1 authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateTue 5 Nov 2013, 08:55 (13 years ago) parent2a111a1
1 file changed+34−11
tests/qmltests/tst_Shell.qml+34−11
tests/qmltests/tst_Shell.qml+34−11
@@ -55,17 +55,40 @@ Item {
5555 when: windowShown
5656
5757 function initTestCase() {
58− // Ensure DashHome is loaded before continuing
59− var dashContentList = findChild(shell, "dashContentList");
60− waitForRendering(dashContentList);
61− var homeLoader = findChild(dashContentList, "home.scope loader");
62− verify(homeLoader);
63− tryCompareFunction(function() {return homeLoader.item !== undefined;}, true);
64−
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.
68− wait(2000);
58+ var ok = false;
59+ var attempts = 0;
60+ var maxAttempts = 1000;
61+
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.
68+ do {
69+ var dashContentList = findChild(shell, "dashContentList");
70+ waitForRendering(dashContentList);
71+ var homeLoader = findChild(dashContentList, "home.scope loader");
72+ ok = homeLoader !== undefined
73+ && homeLoader.item !== undefined;
74+
75+ var greeter = findChild(shell, "greeter");
76+ ok &= greeter !== undefined;
77+
78+ var launcherPanel = findChild(shell, "launcherPanel");
79+ ok &= launcherPanel !== undefined;
80+
81+ attempts++;
82+ if (!ok) {
83+ console.log("Attempt " + attempts + " failed. Waiting a bit before trying again.");
84+ // wait a bit before retrying
85+ wait(100);
86+ } else {
87+ console.log("All seem fine after " + attempts + " attempts.");
88+ }
89+ } while (!ok && attempts <= maxAttempts);
90+
91+ verify(ok);
6992
7093 swipeAwayGreeter();
7194 }