Skip to content

Commit d25be56

Browse files
authored
fix: schematics tests on Windows (#57)
* fix: schematics tests on Windows * fix: ensure app folder cleanup * fix: add emu and sim in base TnsRunTest
1 parent 9450291 commit d25be56

File tree

6 files changed

+33
-49
lines changed

6 files changed

+33
-49
lines changed

core/base_test/tns_run_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88

99
class TnsRunTest(TnsTest):
10+
emu = None
11+
sim = None
1012

1113
@classmethod
1214
def setUpClass(cls):

core/utils/run.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
# pylint: disable=unused-variable
55
import logging
66
import os
7-
8-
import psutil
97
import time
108
from datetime import datetime
119

10+
import psutil
11+
1212
from core.base_test.test_context import TestContext
13+
from core.enums.os_type import OSType
1314
from core.log.log import Log
1415
from core.settings import Settings
1516
from core.utils.file_utils import File, Folder
@@ -50,7 +51,10 @@ def run(cmd, cwd=Settings.TEST_RUN_HOME, wait=True, timeout=600, fail_safe=False
5051
if wait:
5152
start = time.time()
5253
with open(log_file, mode='w') as log:
53-
process = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=log)
54+
if Settings.HOST_OS == OSType.WINDOWS:
55+
process = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=log, stderr=log)
56+
else:
57+
process = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=log)
5458

5559
# Wait until command complete
5660
try:

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ flake8>=3.6.0
1313
pylint>=1.9.4
1414
selenium>=3.141.0
1515
webdriver_manager>=1.7
16-
subprocess32>=3.5.3
16+
subprocess32>=3.5.3
17+
requests>=2.21.0

requirements_darwin.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ selenium>=3.141.0
1515
webdriver_manager>=1.7
1616
atomac>=1.1.0
1717
PyObjC>=5.1.1
18-
subprocess32>=3.5.3
18+
subprocess32>=3.5.3
19+
requests>=2.21.0

tests/code_sharing/migrate_web_tests.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,41 @@
44

55
from parameterized import parameterized
66

7-
from core.base_test.tns_test import TnsTest
7+
from core.base_test.tns_run_test import TnsRunTest
88
from core.enums.os_type import OSType
99
from core.enums.platform_type import Platform
1010
from core.log.log import Log
1111
from core.settings import Settings
1212
from core.utils.chrome import Chrome
13-
from core.utils.device.adb import Adb
14-
from core.utils.device.device_manager import DeviceManager
1513
from products.angular.ng import NG, DEFAULT_WEB_URL
1614
from products.nativescript.tns import Tns
1715

1816

1917
# noinspection PyMethodMayBeStatic
20-
class MigrateWebToMobileTests(TnsTest):
18+
class MigrateWebToMobileTests(TnsRunTest):
2119
app_name = Settings.AppName.DEFAULT
2220
app_folder = os.path.join(Settings.TEST_RUN_HOME, app_name)
23-
emu = None
24-
sim = None
2521
chrome = None
2622

2723
@classmethod
2824
def setUpClass(cls):
29-
TnsTest.setUpClass()
25+
TnsRunTest.setUpClass()
3026
NG.kill()
3127
NG.new(collection=None, project=cls.app_name)
3228
cls.chrome = Chrome()
33-
cls.emu = DeviceManager.Emulator.ensure_available(Settings.Emulators.DEFAULT)
34-
if Settings.HOST_OS is OSType.OSX:
35-
cls.sim = DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT)
3629

3730
def setUp(self):
38-
TnsTest.setUp(self)
31+
TnsRunTest.setUp(self)
3932
NG.kill()
40-
Adb.open_home(device_id=self.emu.id) # Open home screen just to be sure we do not find text of previous run.
4133

4234
def tearDown(self):
4335
NG.kill()
44-
TnsTest.tearDown(self)
36+
TnsRunTest.tearDown(self)
4537

4638
@classmethod
4739
def tearDownClass(cls):
4840
cls.chrome.kill()
49-
TnsTest.tearDownClass()
41+
TnsRunTest.tearDownClass()
5042

5143
def test_01_ng_serve_web(self):
5244
self.ng_serve(prod=False)

tests/code_sharing/ng_new_tests.py

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
# pylint: disable=too-many-branches
2-
# pylint: disable=too-many-statements
31
import os
42
import unittest
53

6-
from core.base_test.tns_test import TnsTest
4+
from core.base_test.tns_run_test import TnsRunTest
75
from core.enums.env import EnvironmentType
86
from core.enums.os_type import OSType
97
from core.enums.platform_type import Platform
108
from core.enums.styling_type import StylingType
119
from core.settings import Settings
12-
from core.utils.device.adb import Adb
13-
from core.utils.device.device_manager import DeviceManager
1410
from core.utils.file_utils import Folder
1511
from core.utils.json_utils import JsonUtils
1612
from data.apps import Apps
@@ -19,35 +15,22 @@
1915
from products.nativescript.app import App
2016
from products.nativescript.tns import Tns
2117
from products.nativescript.tns_assert import TnsAssert
18+
from products.nativescript.tns_paths import TnsPaths
2219

2320

2421
# noinspection PyMethodMayBeStatic
25-
class NGNewTests(TnsTest):
22+
class NGNewTests(TnsRunTest):
2623
app_name = Settings.AppName.DEFAULT
27-
app_folder = os.path.join(Settings.TEST_RUN_HOME, app_name)
28-
emu = None
29-
sim = None
30-
31-
@classmethod
32-
def setUpClass(cls):
33-
TnsTest.setUpClass()
34-
cls.emu = DeviceManager.Emulator.ensure_available(Settings.Emulators.DEFAULT)
35-
if Settings.HOST_OS is OSType.OSX:
36-
cls.sim = DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT)
24+
app_path = TnsPaths.get_app_path(app_name=app_name)
3725

3826
def setUp(self):
39-
TnsTest.setUp(self)
27+
TnsRunTest.setUp(self)
4028
NG.kill()
41-
Adb.open_home(device_id=self.emu.id) # Open home page to be sure we do not find old text
42-
Folder.clean(self.app_folder)
29+
Folder.clean(self.app_path)
4330

4431
def tearDown(self):
4532
NG.kill()
46-
TnsTest.tearDown(self)
47-
48-
@classmethod
49-
def tearDownClass(cls):
50-
TnsTest.tearDownClass()
33+
TnsRunTest.tearDown(self)
5134

5235
def test_001_simple(self):
5336
NGNewTests.create_and_run(shared=False)
@@ -110,7 +93,8 @@ def create_and_run(shared=True, sample=False, theme=True, style=None, prefix=Non
11093
App.update(app_name=NGNewTests.app_name, modules=True, angular=True, typescript=False, web_pack=False)
11194

11295
# Run the app
113-
NGNewTests.run_bundle(app_data=app_data, webpack=webpack, shared=shared, theme=theme)
96+
NGNewTests.run_bundle(app_data=app_data, webpack=webpack, shared=shared, theme=theme,
97+
emu=NGNewTests.emu, sim=NGNewTests.sim)
11498

11599
@staticmethod
116100
def create_app(app_data, shared, sample, theme, style, prefix, source_dir, webpack):
@@ -163,14 +147,14 @@ def create_app(app_data, shared, sample, theme, style, prefix, source_dir, webpa
163147
assert Folder.exists(os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, source_dir))
164148

165149
@staticmethod
166-
def run_bundle(app_data, webpack, shared, theme):
150+
def run_bundle(app_data, webpack, shared, theme, emu, sim):
167151
# Run android (if webpack is available -> use --bundle)
168152
Tns.run(app_name=NGNewTests.app_name, platform=Platform.ANDROID, emulator=True, bundle=webpack)
169153
for text in app_data.texts:
170-
NGNewTests.emu.wait_for_text(text=text, timeout=300)
154+
emu.wait_for_text(text=text, timeout=300)
171155
# Check if theme is really applied (only for non shared projects, shared is not good example to check)
172156
if not shared:
173-
blue_pixels = NGNewTests.emu.get_pixels_by_color(color=Colors.LIGHT_BLUE)
157+
blue_pixels = emu.get_pixels_by_color(color=Colors.LIGHT_BLUE)
174158
if theme:
175159
assert blue_pixels > 1000, 'Default {N} theme is NOT applied on Android.'
176160
else:
@@ -180,10 +164,10 @@ def run_bundle(app_data, webpack, shared, theme):
180164
if Settings.HOST_OS is OSType.OSX:
181165
Tns.run(app_name=NGNewTests.app_name, platform=Platform.IOS, emulator=True, bundle=webpack)
182166
for text in app_data.texts:
183-
NGNewTests.sim.wait_for_text(text=text, timeout=300)
167+
sim.wait_for_text(text=text, timeout=300)
184168
# Check if theme is really applied (only for non shared projects, shared is not good example to check)
185169
if not shared:
186-
blue_pixels = NGNewTests.emu.get_pixels_by_color(color=Colors.LIGHT_BLUE)
170+
blue_pixels = emu.get_pixels_by_color(color=Colors.LIGHT_BLUE)
187171
if theme:
188172
assert blue_pixels > 1000, 'Default {N} theme is NOT applied on iOS.'
189173
else:

0 commit comments

Comments
 (0)