This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
IntegrationTests.py
95 lines (77 loc) · 2.51 KB
/
IntegrationTests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import dash
import dash_core_components
import dash_core_components as dcc
import dash_html_components as html
import importlib
import multiprocessing
import percy
import time
import unittest
import os
import sys
class IntegrationTests(unittest.TestCase):
def percy_snapshot(cls, name=''):
snapshot_name = '{} - {}'.format(name, sys.version_info)
print(snapshot_name)
cls.percy_runner.snapshot(
name=snapshot_name
)
@classmethod
def setUpClass(cls):
super(IntegrationTests, cls).setUpClass()
cls.driver = webdriver.Chrome()
loader = percy.ResourceLoader(
webdriver=cls.driver
)
cls.percy_runner = percy.Runner(loader=loader)
cls.percy_runner.initialize_build()
@classmethod
def tearDownClass(cls):
super(IntegrationTests, cls).tearDownClass()
cls.driver.quit()
cls.percy_runner.finalize_build()
def setUp(s):
pass
def tearDown(s):
time.sleep(2)
s.server_process.terminate()
time.sleep(2)
def startServer(s, dash):
def run():
dash.scripts.config.serve_locally = True
dash.run_server(
port=8050,
debug=False,
processes=4,
threaded=False
)
# Run on a separate process so that it doesn't block
s.server_process = multiprocessing.Process(target=run)
s.server_process.start()
time.sleep(0.5)
# Visit the dash page
s.driver.get('http://localhost:8050')
time.sleep(0.5)
# Inject an error and warning logger
logger = '''
window.tests = {};
window.tests.console = {error: [], warn: [], log: []};
var _log = console.log;
var _warn = console.warn;
var _error = console.error;
console.log = function() {
window.tests.console.log.push({method: 'log', arguments: arguments});
return _log.apply(console, arguments);
};
console.warn = function() {
window.tests.console.warn.push({method: 'warn', arguments: arguments});
return _warn.apply(console, arguments);
};
console.error = function() {
window.tests.console.error.push({method: 'error', arguments: arguments});
return _error.apply(console, arguments);
};
'''
s.driver.execute_script(logger)