Skip to content

Commit 114d626

Browse files
dbnicholsonrtibbles
authored andcommitted
Add periodic status refresh for webview test app
1 parent a719db1 commit 114d626

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

testapps/on_device_unit_tests/test_app/app_flask.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from flask import (
1313
Flask,
1414
current_app,
15+
jsonify,
1516
render_template,
1617
request,
1718
Markup
@@ -37,6 +38,11 @@ def __init__(self, *args, **kwargs):
3738
setup_lifecycle_callbacks()
3839
self.service_running = False
3940

41+
def get_status(self):
42+
return jsonify({
43+
'service_running': self.service_running,
44+
})
45+
4046
@property
4147
@skip_if_not_running_from_android_device
4248
def service(self):
@@ -88,6 +94,11 @@ def index():
8894
)
8995

9096

97+
@app.route('/status')
98+
def status():
99+
return current_app.get_status()
100+
101+
91102
@app.route('/unittests')
92103
def unittests():
93104
import unittest

testapps/on_device_unit_tests/test_app/templates/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,27 @@ <h3 class="text-underline">Android tests</h3>
134134
</script>
135135
</div>
136136

137+
<script>
138+
function update_status() {
139+
var request = new XMLHttpRequest();
140+
request.onload = function() {
141+
var service_status = document.getElementById('service-status');
142+
if (this.status >= 400) {
143+
service_status.textContent = `App status failed: ${this.statusText}`;
144+
} else {
145+
var status = JSON.parse(this.responseText);
146+
service_status.textContent = status.service_running
147+
? 'Service started'
148+
: 'Service stopped';
149+
}
150+
};
151+
request.open('GET', 'status', true);
152+
request.send();
153+
}
154+
155+
setInterval(update_status, 2000);
156+
</script>
157+
137158
<br>
138159
<br>
139160
</div>

0 commit comments

Comments
 (0)