diff --git a/core/base_test/tns_run_test.py b/core/base_test/tns_run_test.py index 558623df..eaee1cdc 100644 --- a/core/base_test/tns_run_test.py +++ b/core/base_test/tns_run_test.py @@ -7,6 +7,8 @@ class TnsRunTest(TnsTest): + emu = None + sim = None @classmethod def setUpClass(cls): diff --git a/core/utils/run.py b/core/utils/run.py index baffb761..90269888 100644 --- a/core/utils/run.py +++ b/core/utils/run.py @@ -4,12 +4,13 @@ # pylint: disable=unused-variable import logging import os - -import psutil import time from datetime import datetime +import psutil + from core.base_test.test_context import TestContext +from core.enums.os_type import OSType from core.log.log import Log from core.settings import Settings 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 if wait: start = time.time() with open(log_file, mode='w') as log: - process = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=log) + if Settings.HOST_OS == OSType.WINDOWS: + process = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=log, stderr=log) + else: + process = subprocess.Popen(cmd, cwd=cwd, shell=True, stdout=subprocess.PIPE, stderr=log) # Wait until command complete try: diff --git a/requirements.txt b/requirements.txt index 11e447c3..a66e75ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,5 @@ flake8>=3.6.0 pylint>=1.9.4 selenium>=3.141.0 webdriver_manager>=1.7 -subprocess32>=3.5.3 \ No newline at end of file +subprocess32>=3.5.3 +requests>=2.21.0 \ No newline at end of file diff --git a/requirements_darwin.txt b/requirements_darwin.txt index 29b7bd0b..75357968 100644 --- a/requirements_darwin.txt +++ b/requirements_darwin.txt @@ -15,4 +15,5 @@ selenium>=3.141.0 webdriver_manager>=1.7 atomac>=1.1.0 PyObjC>=5.1.1 -subprocess32>=3.5.3 \ No newline at end of file +subprocess32>=3.5.3 +requests>=2.21.0 \ No newline at end of file diff --git a/tests/code_sharing/migrate_web_tests.py b/tests/code_sharing/migrate_web_tests.py index 64b78532..44500bdf 100644 --- a/tests/code_sharing/migrate_web_tests.py +++ b/tests/code_sharing/migrate_web_tests.py @@ -4,49 +4,41 @@ from parameterized import parameterized -from core.base_test.tns_test import TnsTest +from core.base_test.tns_run_test import TnsRunTest from core.enums.os_type import OSType from core.enums.platform_type import Platform from core.log.log import Log from core.settings import Settings from core.utils.chrome import Chrome -from core.utils.device.adb import Adb -from core.utils.device.device_manager import DeviceManager from products.angular.ng import NG, DEFAULT_WEB_URL from products.nativescript.tns import Tns # noinspection PyMethodMayBeStatic -class MigrateWebToMobileTests(TnsTest): +class MigrateWebToMobileTests(TnsRunTest): app_name = Settings.AppName.DEFAULT app_folder = os.path.join(Settings.TEST_RUN_HOME, app_name) - emu = None - sim = None chrome = None @classmethod def setUpClass(cls): - TnsTest.setUpClass() + TnsRunTest.setUpClass() NG.kill() NG.new(collection=None, project=cls.app_name) cls.chrome = Chrome() - cls.emu = DeviceManager.Emulator.ensure_available(Settings.Emulators.DEFAULT) - if Settings.HOST_OS is OSType.OSX: - cls.sim = DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT) def setUp(self): - TnsTest.setUp(self) + TnsRunTest.setUp(self) NG.kill() - Adb.open_home(device_id=self.emu.id) # Open home screen just to be sure we do not find text of previous run. def tearDown(self): NG.kill() - TnsTest.tearDown(self) + TnsRunTest.tearDown(self) @classmethod def tearDownClass(cls): cls.chrome.kill() - TnsTest.tearDownClass() + TnsRunTest.tearDownClass() def test_01_ng_serve_web(self): self.ng_serve(prod=False) diff --git a/tests/code_sharing/ng_new_tests.py b/tests/code_sharing/ng_new_tests.py index 6c6d8338..71ba815e 100644 --- a/tests/code_sharing/ng_new_tests.py +++ b/tests/code_sharing/ng_new_tests.py @@ -1,16 +1,12 @@ -# pylint: disable=too-many-branches -# pylint: disable=too-many-statements import os import unittest -from core.base_test.tns_test import TnsTest +from core.base_test.tns_run_test import TnsRunTest from core.enums.env import EnvironmentType from core.enums.os_type import OSType from core.enums.platform_type import Platform from core.enums.styling_type import StylingType from core.settings import Settings -from core.utils.device.adb import Adb -from core.utils.device.device_manager import DeviceManager from core.utils.file_utils import Folder from core.utils.json_utils import JsonUtils from data.apps import Apps @@ -19,35 +15,22 @@ from products.nativescript.app import App from products.nativescript.tns import Tns from products.nativescript.tns_assert import TnsAssert +from products.nativescript.tns_paths import TnsPaths # noinspection PyMethodMayBeStatic -class NGNewTests(TnsTest): +class NGNewTests(TnsRunTest): app_name = Settings.AppName.DEFAULT - app_folder = os.path.join(Settings.TEST_RUN_HOME, app_name) - emu = None - sim = None - - @classmethod - def setUpClass(cls): - TnsTest.setUpClass() - cls.emu = DeviceManager.Emulator.ensure_available(Settings.Emulators.DEFAULT) - if Settings.HOST_OS is OSType.OSX: - cls.sim = DeviceManager.Simulator.ensure_available(Settings.Simulators.DEFAULT) + app_path = TnsPaths.get_app_path(app_name=app_name) def setUp(self): - TnsTest.setUp(self) + TnsRunTest.setUp(self) NG.kill() - Adb.open_home(device_id=self.emu.id) # Open home page to be sure we do not find old text - Folder.clean(self.app_folder) + Folder.clean(self.app_path) def tearDown(self): NG.kill() - TnsTest.tearDown(self) - - @classmethod - def tearDownClass(cls): - TnsTest.tearDownClass() + TnsRunTest.tearDown(self) def test_001_simple(self): NGNewTests.create_and_run(shared=False) @@ -110,7 +93,8 @@ def create_and_run(shared=True, sample=False, theme=True, style=None, prefix=Non App.update(app_name=NGNewTests.app_name, modules=True, angular=True, typescript=False, web_pack=False) # Run the app - NGNewTests.run_bundle(app_data=app_data, webpack=webpack, shared=shared, theme=theme) + NGNewTests.run_bundle(app_data=app_data, webpack=webpack, shared=shared, theme=theme, + emu=NGNewTests.emu, sim=NGNewTests.sim) @staticmethod 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 assert Folder.exists(os.path.join(Settings.TEST_RUN_HOME, NGNewTests.app_name, source_dir)) @staticmethod - def run_bundle(app_data, webpack, shared, theme): + def run_bundle(app_data, webpack, shared, theme, emu, sim): # Run android (if webpack is available -> use --bundle) Tns.run(app_name=NGNewTests.app_name, platform=Platform.ANDROID, emulator=True, bundle=webpack) for text in app_data.texts: - NGNewTests.emu.wait_for_text(text=text, timeout=300) + emu.wait_for_text(text=text, timeout=300) # Check if theme is really applied (only for non shared projects, shared is not good example to check) if not shared: - blue_pixels = NGNewTests.emu.get_pixels_by_color(color=Colors.LIGHT_BLUE) + blue_pixels = emu.get_pixels_by_color(color=Colors.LIGHT_BLUE) if theme: assert blue_pixels > 1000, 'Default {N} theme is NOT applied on Android.' else: @@ -180,10 +164,10 @@ def run_bundle(app_data, webpack, shared, theme): if Settings.HOST_OS is OSType.OSX: Tns.run(app_name=NGNewTests.app_name, platform=Platform.IOS, emulator=True, bundle=webpack) for text in app_data.texts: - NGNewTests.sim.wait_for_text(text=text, timeout=300) + sim.wait_for_text(text=text, timeout=300) # Check if theme is really applied (only for non shared projects, shared is not good example to check) if not shared: - blue_pixels = NGNewTests.emu.get_pixels_by_color(color=Colors.LIGHT_BLUE) + blue_pixels = emu.get_pixels_by_color(color=Colors.LIGHT_BLUE) if theme: assert blue_pixels > 1000, 'Default {N} theme is NOT applied on iOS.' else: