11import base64
22import os
3+ import sys
34import time
45
56from .IntegrationTests import IntegrationTests
67import dash
78import dash_html_components as html
89import dash_core_components as dcc
10+ import percy
911from selenium .webdriver .common .by import By
1012from selenium .webdriver .support .ui import WebDriverWait
1113from selenium .webdriver .support import expected_conditions as EC
@@ -21,13 +23,23 @@ class Tests(IntegrationTests):
2123 Instead, we use Selenium webdrivers to automatically screenshot each of
2224 the apps being tested in test_usage.py, display them in a simple
2325 Dash app, and use Percy to take a snapshot for CVI.
26+
27+ Here, we extend the setUpClass method from IntegrationTests by adding
28+ percy runner initialization. This is because other classes that inherits
29+ from IntegrationTests do not necessarily need to initialize Percy (since
30+ all they do is save snapshots), and doing so causes Percy to render an
31+ empty build that ends up failing. Therefore, we decide to initialize and
32+ finalize the Percy runner in this class rather than inside
33+ IntegrationTests.
2434 """
2535
26- def test_usage (self ):
36+ @staticmethod
37+ def create_app (dir_name ):
2738 def encode (name ):
2839 path = os .path .join (
2940 os .path .dirname (__file__ ),
3041 'screenshots' ,
42+ dir_name ,
3143 name
3244 )
3345
@@ -60,8 +72,37 @@ def display_image(pathname): # pylint: disable=W0612
6072 name = pathname .replace ('/' , '' )
6173 return html .Img (id = name , src = encode (name ))
6274
63- # Start the app
64- self .startServer (app )
75+ return app
76+
77+ def percy_snapshot (self , name = '' ):
78+ if os .environ .get ('PERCY_ENABLED' , False ):
79+ snapshot_name = '{} (Python {}.{}.{})' .format (
80+ name ,
81+ sys .version_info .major ,
82+ sys .version_info .minor ,
83+ sys .version_info .micro ,
84+ )
85+
86+ self .percy_runner .snapshot (
87+ name = snapshot_name
88+ )
89+
90+ @classmethod
91+ def setUpClass (cls ):
92+ super (Tests , cls ).setUpClass ()
93+
94+ if os .environ .get ('PERCY_ENABLED' , False ):
95+ loader = percy .ResourceLoader (webdriver = cls .driver )
96+ percy_config = percy .Config (default_widths = [1280 ])
97+ cls .percy_runner = percy .Runner (loader = loader , config = percy_config )
98+ cls .percy_runner .initialize_build ()
99+
100+ @classmethod
101+ def tearDownClass (cls ):
102+ super (Tests , cls ).tearDownClass ()
103+
104+ if os .environ .get ('PERCY_ENABLED' , False ):
105+ cls .percy_runner .finalize_build ()
65106
66107 # Find the names of all the screenshots
67108 asset_list = os .listdir (os .path .join (
0 commit comments