Skip to content

Commit caf03f9

Browse files
committed
Wait for OctoPrint Setup Wizard before taking screenshot
The previous screenshot captured OctoPrint's "starting up" loading screen instead of the actual UI. Now both the CI workflow and the E2E test wait for OctoPrint to fully finish its startup phase by checking for CONFIG_WIZARD in the page HTML, and puppeteer waits for the #wizard_dialog to become visible before capturing.
1 parent 896303c commit caf03f9

2 files changed

Lines changed: 54 additions & 15 deletions

File tree

.github/workflows/build.yml

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,23 @@ jobs:
111111
echo "Tests finished with exit code: $(cat artifacts/exit-code)"
112112
cat artifacts/test-results.txt 2>/dev/null || true
113113
114-
- name: Wait for OctoPrint web server
114+
- name: Wait for OctoPrint to fully start
115115
run: |
116-
for i in $(seq 1 60); do
117-
HTTP=$(curl -4 -s -o /dev/null -w '%{http_code}' \
118-
--connect-timeout 5 http://127.0.0.1:9980 2>/dev/null || true)
119-
[ "$HTTP" = "200" ] && echo "OctoPrint ready" && break
116+
echo "Waiting for OctoPrint to finish startup..."
117+
for i in $(seq 1 90); do
118+
BODY=$(curl -4 -s --connect-timeout 5 http://127.0.0.1:9980 2>/dev/null || true)
119+
if echo "$BODY" | grep -q "CONFIG_WIZARD"; then
120+
echo "OctoPrint fully started (Setup Wizard ready)"
121+
exit 0
122+
elif echo "$BODY" | grep -q "starting up"; then
123+
printf "S"
124+
else
125+
printf "."
126+
fi
120127
sleep 5
121128
done
129+
echo ""
130+
echo "WARNING: OctoPrint may not be fully started yet, proceeding anyway"
122131
123132
- name: Take OctoPrint screenshot
124133
run: |
@@ -131,10 +140,31 @@ jobs:
131140
});
132141
const page = await browser.newPage();
133142
await page.setViewport({width: 1280, height: 900});
134-
await page.goto('http://127.0.0.1:9980', {
135-
waitUntil: 'networkidle2', timeout: 60000
136-
});
143+
144+
// Retry loading until OctoPrint finishes its startup phase
145+
for (let attempt = 0; attempt < 30; attempt++) {
146+
await page.goto('http://127.0.0.1:9980', {
147+
waitUntil: 'networkidle2', timeout: 60000
148+
});
149+
const html = await page.content();
150+
if (html.includes('CONFIG_WIZARD') || html.includes('id=\"login\"')) break;
151+
console.log('OctoPrint still starting up, retrying in 10s... (attempt ' + (attempt+1) + ')');
152+
await new Promise(r => setTimeout(r, 10000));
153+
}
154+
155+
// Wait for the Setup Wizard dialog to appear
156+
try {
157+
await page.waitForSelector('#wizard_dialog', { visible: true, timeout: 120000 });
158+
} catch (e) {
159+
console.log('Wizard did not appear, taking screenshot of current state');
160+
}
161+
162+
// Dismiss notification popovers by clicking the wizard body
163+
try { await page.click('#wizard_dialog .modal-body'); } catch(e) {}
164+
await new Promise(r => setTimeout(r, 2000));
165+
137166
await page.screenshot({path: 'artifacts/octoprint-screenshot.png'});
167+
console.log('Screenshot captured');
138168
await browser.close();
139169
})();
140170
"

testing/tests/test_octoprint_web.sh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,35 @@ PASS="raspberry"
99

1010
SSH_CMD="sshpass -p $PASS ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o PreferredAuthentications=password -o PubkeyAuthentication=no -o LogLevel=ERROR -p $PORT ${USER}@${HOST}"
1111

12-
echo "Test: OctoPrint web server is accessible"
12+
echo "Test: OctoPrint web server is accessible and fully started"
1313

1414
OCTOPRINT_READY=0
15-
for i in $(seq 1 24); do
15+
for i in $(seq 1 60); do
16+
BODY=$($SSH_CMD "curl -s http://localhost" 2>/dev/null || echo "")
1617
HTTP_CODE=$($SSH_CMD "curl -s -o /dev/null -w '%{http_code}' http://localhost" 2>/dev/null || echo "000")
18+
1719
if [ "$HTTP_CODE" = "200" ]; then
18-
OCTOPRINT_READY=1
19-
break
20+
if echo "$BODY" | grep -q "starting up"; then
21+
printf "S"
22+
elif echo "$BODY" | grep -q "CONFIG_WIZARD\|OctoPrint"; then
23+
OCTOPRINT_READY=1
24+
break
25+
else
26+
printf "W"
27+
fi
28+
else
29+
printf "."
2030
fi
21-
printf "W"
2231
sleep 5
2332
done
2433
echo ""
2534

2635
if [ "$OCTOPRINT_READY" -eq 0 ]; then
27-
echo " FAIL: OctoPrint web server not reachable after 120s"
36+
echo " FAIL: OctoPrint did not fully start within 300s"
2837
exit 1
2938
fi
3039

31-
echo " OctoPrint web server is ready (HTTP 200)"
40+
echo " OctoPrint web server is fully started (HTTP 200, UI loaded)"
3241

3342
FULL_HTML=$($SSH_CMD "curl -s http://localhost" 2>/dev/null)
3443

0 commit comments

Comments
 (0)