Skip to content

feat: add vue tests #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data/changes.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,14 @@ class SharedHelloWorld(object):
HTML = ChangeSet(file_path=os.path.join('src', 'app', 'item', 'items.component.html'),
old_value='"item.name"', new_value='"item.id"',
old_text=None, new_text=None)

class BlankVue(object):
VUE_SCRIPT = ChangeSet(file_path=os.path.join('app', 'components', 'Home.vue'),
old_value='Blank {N}-Vue app', new_value='TEST APP',
old_text='Blank {N}-Vue app', new_text='TEST APP')
VUE_TEMPLATE = ChangeSet(file_path=os.path.join('app', 'components', 'Home.vue'),
old_value='Home', new_value='TITLE',
old_text='Home', new_text='TITLE')
VUE_STYLE = ChangeSet(file_path=os.path.join('app', 'components', 'Home.vue'),
old_value='font-size: 20;', new_value='font-size: 20; color: red;',
old_color=Colors.DARK, new_color=Colors.RED)
123 changes: 123 additions & 0 deletions data/sync/blank_vue.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
"""
Sync changes on JS/TS project helper.
"""
import os

from core.enums.app_type import AppType
from core.log.log import Log
from core.settings import Settings
from core.utils.wait import Wait
from data.changes import Changes, Sync
from data.const import Colors
from products.nativescript.run_type import RunType
from products.nativescript.tns import Tns
from products.nativescript.tns_logs import TnsLogs


def __run_vue(app_name, platform, bundle, hmr):
# Execute `tns run` and wait until logs are OK
return Tns.run(app_name=app_name, platform=platform, emulator=True, wait=False, bundle=bundle, hmr=hmr)


def __preview_vue(app_name, bundle, hmr):
# Execute `tns run` and wait until logs are OK
return Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr)


def __workflow(preview, app_name, platform, device, bundle=False, hmr=False):
# Execute tns command
if preview:
result = __preview_vue(app_name=app_name, bundle=bundle, hmr=hmr)
else:
result = __run_vue(app_name=app_name, platform=platform, bundle=bundle, hmr=hmr)

if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.FULL, bundle=bundle,
hmr=hmr, app_type=AppType.VUE)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=240)

# Verify it looks properly
device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.old_text)
device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.old_text)
initial_state = os.path.join(Settings.TEST_OUT_IMAGES, device.name, 'initial_state.png')
device.get_screen(path=initial_state)

# Edit script in .vue file
Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_SCRIPT)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.new_text)

# Edit template in .vue file
Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_TEMPLATE)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.new_text)

# Edit styling in .vue file
Sync.replace(app_name=app_name, change_set=Changes.BlankVue.VUE_STYLE)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
style_applied = Wait.until(lambda: device.get_pixels_by_color(Colors.RED) > 100)
assert style_applied, 'Failed to sync changes in style.'

# Revert script in .vue file
Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_SCRIPT)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
device.wait_for_text(text=Changes.BlankVue.VUE_SCRIPT.old_text)

# Revert template in .vue file
Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_TEMPLATE)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle, hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
device.wait_for_text(text=Changes.BlankVue.VUE_TEMPLATE.old_text)

# Revert styling in .vue file
Sync.revert(app_name=app_name, change_set=Changes.BlankVue.VUE_STYLE)
if preview:
Log.info('Skip logs checks.')
else:
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL,
bundle=bundle,
hmr=hmr, app_type=AppType.VUE, file_name='Home.vue')
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

if hmr:
Log.info('Skip next steps because of https://github.com/nativescript-vue/nativescript-vue/issues/425')
else:
style_applied = Wait.until(lambda: device.get_pixels_by_color(Colors.RED) == 0)
assert style_applied, 'Failed to sync changes in style.'

# Assert final and initial states are same
device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)


def sync_blank_vue(app_name, platform, device, bundle=False, hmr=False):
__workflow(preview=False, app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr)


def preview_blank_vue(app_name, platform, device, bundle=False, hmr=False):
__workflow(preview=True, app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr)
12 changes: 5 additions & 7 deletions data/sync/hello_world_js.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from core.utils.wait import Wait
from data.changes import Changes, Sync
from data.const import Colors
from products.nativescript.preview_helpers import Preview
from products.nativescript.run_type import RunType
from products.nativescript.tns import Tns
from products.nativescript.tns_logs import TnsLogs
from products.nativescript.preview_helpers import Preview


def sync_hello_world_js(app_name, platform, device, bundle=False, hmr=False, uglify=False, aot=False,
Expand Down Expand Up @@ -129,9 +129,8 @@ def __sync_hello_world_js_ts(app_type, app_name, platform, device,
device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)


def preview_hello_world_js_ts(app_name, platform, device, bundle=False, hmr=False, uglify=False, aot=False,
instrumented=False):
result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, aot=aot, uglify=uglify, platform=platform,
def preview_hello_world_js_ts(app_name, platform, device, bundle=False, hmr=False, instrumented=False):
result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, platform=platform,
device=device, instrumented=instrumented)

# Verify app looks properly
Expand All @@ -143,10 +142,9 @@ def preview_hello_world_js_ts(app_name, platform, device, bundle=False, hmr=Fals
return result


def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=False, hmr=False, uglify=False,
aot=False, instrumented=False):
def preview_sync_hello_world_js_ts(app_type, app_name, platform, device, bundle=False, hmr=False, instrumented=False):
result = preview_hello_world_js_ts(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr,
uglify=uglify, aot=aot, instrumented=instrumented)
instrumented=instrumented)

blue_count = device.get_pixels_by_color(color=Colors.LIGHT_BLUE)
# Set changes
Expand Down
29 changes: 14 additions & 15 deletions data/sync/hello_world_ng.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
"""

import os

from core.enums.app_type import AppType
from core.enums.platform_type import Platform
from core.settings import Settings
from data.changes import Changes, Sync
from data.const import Colors
from products.nativescript.preview_helpers import Preview
from products.nativescript.run_type import RunType
from products.nativescript.tns import Tns
from products.nativescript.tns_logs import TnsLogs
from products.nativescript.preview_helpers import Preview


def sync_hello_world_ng(app_name, platform, device, bundle=False, uglify=False, aot=False, hmr=False,
instrumented=True, app_type=AppType.NG):
instrumented=True):
result = Tns.run(app_name=app_name, platform=platform, emulator=True, wait=False,
bundle=bundle, aot=aot, uglify=uglify, hmr=hmr)
# Check logs
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, bundle=bundle,
hmr=hmr, instrumented=instrumented, app_type=app_type)
hmr=hmr, instrumented=instrumented, app_type=AppType.NG)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=300)

# Verify it looks properly
Expand All @@ -33,7 +34,7 @@ def sync_hello_world_ng(app_name, platform, device, bundle=False, uglify=False,
Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=app_type)
file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
Expand All @@ -46,7 +47,7 @@ def sync_hello_world_ng(app_name, platform, device, bundle=False, uglify=False,
assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='items.component.html', hmr=hmr, instrumented=instrumented,
app_type=app_type, aot=aot)
app_type=AppType.NG, aot=aot)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.CSS)
Expand All @@ -59,38 +60,37 @@ def sync_hello_world_ng(app_name, platform, device, bundle=False, uglify=False,
device.wait_for_text(text=number)
assert not device.is_text_visible(text=Changes.NGHelloWorld.TS.new_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=app_type)
file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

# Revert changes
Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.HTML)
device.wait_for_text(text=Changes.NGHelloWorld.TS.new_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='items.component.html', hmr=hmr, instrumented=instrumented,
app_type=app_type, aot=aot)
app_type=AppType.NG, aot=aot)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
device.wait_for_main_color(color=Colors.DARK)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=app_type)
file_name='item.service.ts', hmr=hmr, instrumented=instrumented, app_type=AppType.NG)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

Sync.revert(app_name=app_name, change_set=Changes.NGHelloWorld.CSS)
device.wait_for_main_color(color=Colors.WHITE)
device.wait_for_text(text=Changes.NGHelloWorld.TS.old_text)
strings = TnsLogs.run_messages(app_name=app_name, platform=platform, run_type=RunType.INCREMENTAL, bundle=bundle,
file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=app_type)
file_name='app.css', hmr=hmr, instrumented=instrumented, app_type=AppType.NG)
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings, timeout=180)

# Assert final and initial states are same
device.screen_match(expected_image=initial_state, tolerance=1.0, timeout=30)


def preview_hello_world_ng(app_name, platform, device, bundle=False, hmr=False, uglify=False, aot=False,
instrumented=False):
result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, aot=aot, uglify=uglify, platform=platform,
def preview_hello_world_ng(app_name, platform, device, bundle=False, hmr=False, instrumented=False):
result = Preview.run_app(app_name=app_name, bundle=bundle, hmr=hmr, platform=platform,
device=device, instrumented=instrumented)

# Verify app looks properly
Expand All @@ -101,10 +101,9 @@ def preview_hello_world_ng(app_name, platform, device, bundle=False, hmr=False,
return result


def preview_sync_hello_world_ng(app_name, platform, device, bundle=False, hmr=False, uglify=False,
aot=False, instrumented=False):
def preview_sync_hello_world_ng(app_name, platform, device, bundle=False, hmr=False, instrumented=False):
result = preview_hello_world_ng(app_name=app_name, platform=platform, device=device, bundle=bundle, hmr=hmr,
uglify=uglify, aot=aot, instrumented=instrumented)
instrumented=instrumented)

# Edit TS file and verify changes are applied
Sync.replace(app_name=app_name, change_set=Changes.NGHelloWorld.TS)
Expand Down
9 changes: 4 additions & 5 deletions products/nativescript/preview_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ def dismiss_simulator_alert():
run(command)

@staticmethod
def run_app(app_name, platform, device, bundle=False, hmr=False, uglify=False, aot=False,
instrumented=False):
result = Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr, aot=aot, uglify=uglify)
def run_app(app_name, platform, device, bundle=False, hmr=False, instrumented=False):
result = Tns.preview(app_name=app_name, bundle=bundle, hmr=hmr)

# Read the log and extract the url to load the app on emulator
log = File.read(result.log_file)
url = Preview.get_url(log)
Preview.run_url(url=url, device=device)
# When you run preview on ios simulator on first run confirmation dialog is showh. This script will dismiss it
if platform == Platform.IOS:
# When you run preview on ios simulator on first run confirmation dialog is shown.
if device.type == DeviceType.SIM:
time.sleep(2)
Preview.dismiss_simulator_alert()

Expand Down
32 changes: 20 additions & 12 deletions products/nativescript/tns.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,26 @@ def debug(app_name, platform, emulator=False, device=None, release=False, provis
pass
return result

@staticmethod
def preview(app_name, bundle=False, hmr=False, log_trace=True, verify=True, timeout=120):
"""
Execute `tns preview` command.
:param app_name: Pass --path <app_name>.
:param bundle: If true pass --bundle.
:param hmr: If true pass --hmr.
:param log_trace: If true pass --log trace.
:param verify: If true verify some logs.
:param timeout: Timeout in seconds.
:return: Result of `tns preview` command.
"""
result = Tns.exec_command(command='preview', path=app_name, bundle=bundle, hmr=hmr, wait=False,
log_trace=log_trace, timeout=timeout)
if verify:
strings = [
'Use NativeScript Playground app and scan the QR code above to preview the application on your device']
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)
return result

@staticmethod
def test_init(app_name, framework, verify=True):
"""
Expand Down Expand Up @@ -381,15 +401,3 @@ def kill():
else:
Process.kill(proc_name='node', proc_cmdline=Settings.Executables.TNS)
Process.kill_by_commandline(cmdline='webpack.js')

@staticmethod
def preview(app_name, bundle=False, hmr=False, aot=False, uglify=False, wait=False,
log_trace=True, verify=True, timeout=60):
result = Tns.exec_command(command='preview', path=app_name, bundle=bundle, hmr=hmr, aot=aot, uglify=uglify,
wait=wait, log_trace=log_trace, timeout=timeout)
if verify:
strings = [
'Use NativeScript Playground app and scan the QR code above to preview the application on your device']
TnsLogs.wait_for_log(log_file=result.log_file, string_list=strings)

return result
Loading