|
| 1 | +""" |
| 2 | +Verify pages templates looks ok |
| 3 | +""" |
| 4 | + |
| 5 | +import fileinput |
| 6 | +import sys |
| 7 | +import unittest |
| 8 | + |
| 9 | +from nose_parameterized import parameterized |
| 10 | + |
| 11 | +from core.base_class.BaseClass import BaseClass |
| 12 | +from core.device.device import Device |
| 13 | +from core.device.emulator import Emulator |
| 14 | +from core.npm.npm import Npm |
| 15 | +from core.osutils.command import * |
| 16 | +from core.osutils.folder import Folder |
| 17 | +from core.settings.settings import EMULATOR_ID, EMULATOR_NAME, TEST_RUN_HOME |
| 18 | +from core.tns.tns import Tns |
| 19 | + |
| 20 | + |
| 21 | +class PageTemplatesTestsAndroid(BaseClass): |
| 22 | + folder = os.path.join(TEST_RUN_HOME, 'tests', 'pageTemplates') |
| 23 | + log = "" |
| 24 | + |
| 25 | + @classmethod |
| 26 | + def setUpClass(cls): |
| 27 | + logfile = os.path.join('out', cls.__name__ + '.txt') |
| 28 | + BaseClass.setUpClass(logfile) |
| 29 | + Emulator.stop() |
| 30 | + Emulator.ensure_available() |
| 31 | + Folder.cleanup(cls.app_name) |
| 32 | + Folder.cleanup("extensions") |
| 33 | + File.remove("user-settings.json") |
| 34 | + output = Tns.run_tns_command( |
| 35 | + command='extension install nativescript-starter-kits --profileDir ' + TEST_RUN_HOME) |
| 36 | + assert "Successfully installed extension nativescript-starter-kits" in output |
| 37 | + assert "Successfully loaded extension nativescript-starter-kits" in output |
| 38 | + Tns.run_tns_command(command='usage-reporting disable --profileDir ' + TEST_RUN_HOME) |
| 39 | + Tns.run_tns_command(command='error-reporting disable --profileDir ' + TEST_RUN_HOME) |
| 40 | + Npm.install(package='global-modules-path', option='--save', folder=cls.folder) |
| 41 | + |
| 42 | + base_url = "https://github.com/nativescript/" |
| 43 | + Tns.create_app(app_name="blank-js", attributes={"--template": base_url + "template-blank"}) |
| 44 | + Tns.create_app(app_name="blank-ts", attributes={"--template": base_url + "template-blank-ts"}) |
| 45 | + Tns.create_app(app_name="blank-ng", attributes={"--template": base_url + "template-blank-ng"}) |
| 46 | + |
| 47 | + def setUp(self): |
| 48 | + BaseClass.setUp(self) |
| 49 | + |
| 50 | + def tearDown(self): |
| 51 | + Tns.kill() |
| 52 | + BaseClass.tearDown(self) |
| 53 | + |
| 54 | + @classmethod |
| 55 | + def tearDownClass(cls): |
| 56 | + BaseClass.tearDownClass() |
| 57 | + |
| 58 | + @parameterized.expand([ |
| 59 | + ('login', 'loginPageScreen'), |
| 60 | + ('blank', 'blankPageScreen'), |
| 61 | + ('signup', 'signupPageScreen') |
| 62 | + ]) |
| 63 | + def test_javascript(self, page_type, expected_image): |
| 64 | + self.log = Tns.run_android(attributes={'--path': 'blank-js', '--emulator': ''}, wait=False, |
| 65 | + assert_success=False) |
| 66 | + strings = ['Successfully synced', EMULATOR_ID] |
| 67 | + Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10) |
| 68 | + |
| 69 | + # Add page to application |
| 70 | + print(os.path) |
| 71 | + cmd = 'node {addPageScript} {pageName} {page_type} js blank-js'.format( |
| 72 | + addPageScript=os.path.join(self.folder, 'addPageNext.js'), pageName=page_type, page_type=page_type) |
| 73 | + run(cmd) |
| 74 | + strings = ['Successfully synced application', 'Successfully transferred', page_type, EMULATOR_ID] |
| 75 | + Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10) |
| 76 | + |
| 77 | + # Set new page for home app page |
| 78 | + text_to_search = 'application.start({ moduleName:' |
| 79 | + text_to_replace = "application.start({ moduleName: " + "\"{name}/{name}-page\"".format(name=page_type) + \ |
| 80 | + " });\n" |
| 81 | + for line in fileinput.input("blank-js/app/app.js", inplace=True): |
| 82 | + if line.strip().startswith(text_to_search): |
| 83 | + line = text_to_replace |
| 84 | + sys.stdout.write(line) |
| 85 | + |
| 86 | + strings = ['Successfully synced application', 'Successfully transferred', 'app.js', EMULATOR_ID] |
| 87 | + Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10) |
| 88 | + |
| 89 | + # Verify android looks ok |
| 90 | + Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=expected_image, |
| 91 | + tolerance=3.0) |
| 92 | + |
| 93 | + @parameterized.expand([ |
| 94 | + ('login', 'loginPageScreen'), |
| 95 | + ('blank', 'blankPageScreen'), |
| 96 | + ('signup', 'signupPageScreen') |
| 97 | + ]) |
| 98 | + def test_typescript(self, page_type, expected_image): |
| 99 | + self.log = Tns.run_android(attributes={'--path': 'blank-ts', '--emulator': ''}, wait=False, |
| 100 | + assert_success=False) |
| 101 | + strings = ['Successfully synced', EMULATOR_ID] |
| 102 | + Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10) |
| 103 | + |
| 104 | + # Add page to application |
| 105 | + print(os.path) |
| 106 | + cmd = 'node {addPageScript} {pageName} {page_type} ts blank-ts'.format( |
| 107 | + addPageScript=os.path.join(self.folder, 'addPageNext.js'), pageName=page_type, page_type=page_type) |
| 108 | + run(cmd) |
| 109 | + strings = ['Successfully synced application', 'Successfully transferred', page_type, EMULATOR_ID] |
| 110 | + Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10) |
| 111 | + |
| 112 | + # Set new page for home app page |
| 113 | + text_to_search = 'app.start({ moduleName:' |
| 114 | + text_to_replace = "app.start({ moduleName: " + "\"{name}/{name}-page\"".format(name=page_type) + "});\n" |
| 115 | + |
| 116 | + for line in fileinput.input("blank-ts/app/app.ts", inplace=True): |
| 117 | + if line.strip().startswith(text_to_search): |
| 118 | + line = text_to_replace |
| 119 | + sys.stdout.write(line) |
| 120 | + |
| 121 | + # Verify android looks ok |
| 122 | + Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=expected_image, |
| 123 | + tolerance=3.0) |
| 124 | + |
| 125 | + @parameterized.expand([ |
| 126 | + ('login', 'loginPageScreen'), |
| 127 | + ('blank', 'blankPageScreen'), |
| 128 | + ('signup', 'signupPageScreen'), |
| 129 | + ]) |
| 130 | + def test_angular(self, page_type, expected_image): |
| 131 | + self.log = Tns.run_android(attributes={'--path': 'blank-ng', '--emulator': ''}, wait=False, |
| 132 | + assert_success=False) |
| 133 | + strings = ['Successfully synced', EMULATOR_ID] |
| 134 | + Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10) |
| 135 | + |
| 136 | + # Add page to application |
| 137 | + print(os.path) |
| 138 | + cmd = 'node {addPageScript} {pageName} {page_type} ng blank-ng'.format( |
| 139 | + addPageScript=os.path.join(self.folder, 'addPageNext.js'), pageName=page_type, page_type=page_type) |
| 140 | + run(cmd) |
| 141 | + strings = ['Successfully synced application', 'Successfully transferred', page_type, EMULATOR_ID] |
| 142 | + Tns.wait_for_log(log_file=self.log, string_list=strings, timeout=150, check_interval=10) |
| 143 | + |
| 144 | + # Set new page for home app page |
| 145 | + text_to_search = '{ path: "", redirectTo: ' |
| 146 | + text_to_replace = "{ path: \"\", redirectTo: \"" + "/{name}\"".format(name=page_type) + \ |
| 147 | + ", pathMatch: \"full\" },\n" |
| 148 | + for line in fileinput.input("blank-ng/app/app-routing.module.ts", inplace=True): |
| 149 | + if line.strip().startswith(text_to_search): |
| 150 | + line = text_to_replace |
| 151 | + sys.stdout.write(line) |
| 152 | + |
| 153 | + text_to_search = "loadChildren:" |
| 154 | + text_to_replace = "{" + "path: \"{name}\",".format( |
| 155 | + name=page_type) + " loadChildren: \"./{name}/{name}.module#{name}Module\"".format(name=page_type) + "}\n" |
| 156 | + for line in fileinput.input("blank-ng/app/app-routing.module.ts", inplace=True): |
| 157 | + if line.strip().startswith(text_to_search): |
| 158 | + line = text_to_replace |
| 159 | + sys.stdout.write(line) |
| 160 | + |
| 161 | + # Verify android looks ok |
| 162 | + Device.screen_match(device_name=EMULATOR_NAME, device_id=EMULATOR_ID, expected_image=expected_image, |
| 163 | + tolerance=3.0) |
0 commit comments