Skip to content

Commit 8fcbb74

Browse files
committed
refactor: collect artefacts on build fail
1 parent 8875227 commit 8fcbb74

File tree

6 files changed

+41
-2
lines changed

6 files changed

+41
-2
lines changed

core/base_class/BaseClass.py

+19
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,23 @@ class BaseClass(unittest.TestCase):
2424
errors = 0
2525
failures = 0
2626

27+
@classmethod
28+
def __copy_images(cls, artifacts_folder):
29+
"""
30+
Archive test app (without platforms and node_modules)
31+
:param artifacts_folder: Base folder where artifacts from failed tests are stored.
32+
"""
33+
src = os.path.join(TEST_RUN_HOME, 'out', 'images')
34+
dest = os.path.join(artifacts_folder, 'artifacts')
35+
if os.path.isdir(src):
36+
try:
37+
shutil.copytree(src, dest)
38+
Folder.cleanup(src)
39+
except:
40+
print "Failed to backup images and logs."
41+
else:
42+
print "No images and logs data."
43+
2744
@classmethod
2845
def __copy_project_folder(cls, artifacts_folder):
2946
"""
@@ -96,6 +113,7 @@ def setUp(self):
96113
print "Test Method: {0}".format(self._testMethodName)
97114
print "Start Time: {0}".format(time.strftime("%X"))
98115
print ""
116+
Folder.cleanup(os.path.join(TEST_RUN_HOME, 'out', 'images'))
99117

100118
def tearDown(self):
101119
# Logic executed only on test failure
@@ -112,6 +130,7 @@ def tearDown(self):
112130
Folder.create(artifacts_folder)
113131

114132
# Collect artifacts on test failure
133+
self.__copy_images(artifacts_folder=artifacts_folder)
115134
self.__copy_project_folder(artifacts_folder=artifacts_folder)
116135
self.__save_host_screen(artifacts_folder=artifacts_folder, test_method_name=test_name)
117136

core/device/device.py

+8
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ def screen_match(device_name, device_id, expected_image, tolerance=0.1, timeout=
121121
print "Diff image will be saved at " + diff_image_final_path
122122
File.copy(src=expected_image_original_path, dest=expected_image_path)
123123
comparison_result[2].save(diff_image_final_path)
124+
# Get logs (from android devices).
125+
if device_type == DeviceType.EMULATOR or device_type == DeviceType.ANDROID:
126+
log_path = diff_image_final_path.replace('_diff.png', '.log')
127+
print "Console logs will be saved at " + log_path
128+
log = Adb.get_logcat(device_id=device_id)
129+
if len(log) < 10000:
130+
print log
131+
File.write(file_path=log_path, text=log)
124132
assert are_equal, "Current image on {0} does not match expected image {1}. Diff is {2}%". \
125133
format(device_name, expected_image, diff)
126134
else:

tests/webpack/hello_world_js_tests.py

+5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def setUpClass(cls):
4444
def setUp(self):
4545
Tns.kill()
4646
Helpers.emulator_cleanup(app_name=self.app_name)
47+
BaseClass.tearDown(self)
48+
49+
def tearDown(self):
50+
BaseClass.tearDown(self)
51+
Tns.kill()
4752

4853
@classmethod
4954
def tearDownClass(cls):

tests/webpack/hello_world_ng_tests.py

+2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ def setUpClass(cls):
4545
def setUp(self):
4646
Tns.kill()
4747
Helpers.emulator_cleanup(app_name=self.app_name)
48+
BaseClass.tearDown(self)
4849

4950
def tearDown(self):
51+
BaseClass.tearDown(self)
5052
Tns.kill()
5153

5254
@classmethod

tests/webpack/hello_world_ts_tests.py

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def setUpClass(cls):
4545
def setUp(self):
4646
Tns.kill()
4747
Helpers.emulator_cleanup(app_name=self.app_name)
48+
BaseClass.tearDown(self)
49+
50+
def tearDown(self):
51+
BaseClass.tearDown(self)
52+
Tns.kill()
4853

4954
@classmethod
5055
def tearDownClass(cls):

tests/webpack/helpers/values.csv

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ ts-android-bundle-uglify-snapshot, 470179, 0, 11961178
1212
ts-ios-bundle, 1338565, 3589104, 13452450
1313
ts-ios-bundle-uglify, 470179, 1338568, 13452450
1414
ng-android-bundle, 1338565, 3485155, 11961178
15-
ng-android-bundle-uglify, 470179, 1335433, 11961178
15+
ng-android-bundle-uglify, 470179, 1335433, 11585838
1616
ng-android-bundle-snapshot, 1338565, 0, 16494569
17-
ng-android-bundle-uglify-snapshot, 470164, 0, 11961178
17+
ng-android-bundle-uglify-snapshot, 470164, 0, 14818929
1818
ng-ios-bundle, 1338565, 3589104, 13452450
1919
ng-ios-bundle-uglify, 439249, 1292628, 13062704

0 commit comments

Comments
 (0)