Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
25 changes: 23 additions & 2 deletions core/device/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import pytesseract
from PIL import Image
import atomac

from core.device.device_type import DeviceType
from core.device.helpers.adb import Adb
Expand Down Expand Up @@ -85,8 +86,8 @@ def screen_match(device_name, device_id, expected_image, tolerance=0.1, timeout=
type = type.replace('ProductType:', '').strip(' ')
device_name = type

print "Verify {0} looks correct...".format(expected_image)
expected_image_original_path = os.path.join("data", "images", device_name, "{0}.png".format(expected_image))
print "Verify {0} looks correct...".format(expected_image_original_path)
actual_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name, "{0}_actual.png".format(expected_image))
diff_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name, "{0}_diff.png".format(expected_image))
expected_image_path = os.path.join(OUTPUT_FOLDER, "images", device_name,
Expand Down Expand Up @@ -241,8 +242,28 @@ def click(device_id, text, timeout):
device_type = Device.__get_device_type(device_id)
if (device_type == DeviceType.EMULATOR) or (device_type == DeviceType.ANDROID):
UIAuto.click(device_id=device_id, text=text, timeout=timeout)
elif device_type == DeviceType.SIMULATOR:
simulator = atomac.getAppRefByBundleId("com.apple.iphonesimulator")
windows = simulator.findAll(AXRole='AXWindow')
names = list()

# Get all simulator's windows names
for window in windows:
names.append(window.AXTitle)

sim_title = Simulator.get_name(device_id)

# Get the full name of the window where the click will be performed
for name in names:
if sim_title in name:
window = simulator.findFirstR(AXTitle=name)
element = window.findFirstR(AXTitle=text)
if element is not None:
element.Press()
else:
raise TypeError("Cannot find element with text {0}".format(text))
else:
raise NotImplementedError("Click on text not implemented for iOS devices and simulators.")
raise NotImplementedError("Click on text not implemented for iOS devices.")

@staticmethod
def ensure_available(platform):
Expand Down
38 changes: 33 additions & 5 deletions core/device/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from core.osutils.command_log_level import CommandLogLevel
from core.osutils.file import File
from core.osutils.process import Process
from core.settings.settings import SIMULATOR_NAME, TEST_RUN_HOME, SIMULATOR_TYPE, SIMULATOR_SDK
from core.settings.settings import SIMULATOR_NAME, TEST_RUN_HOME, SIMULATOR_TYPE, SIMULATOR_SDK, SIMULATOR_NAME_2, \
SIMULATOR_TYPE_2, SIMULATOR_SDK_2


class Simulator(object):
Expand Down Expand Up @@ -70,6 +71,21 @@ def __get_state(simulator_id):
else:
return lines[0].split('(')[-1].split(')')[0]

@staticmethod
def get_name(simulator_id):
"""
Find simulator name by Simulator GUID
:param simulator_id: Simulator GUID
:return: Simulator name
"""
output = run(command='xcrun simctl list | grep {0}'.format(simulator_id), log_level=CommandLogLevel.SILENT)

if output:
sim_name = output.split()[0]
return sim_name
else:
raise AssertionError("Can not find device with id {0}".format(simulator_id))

@staticmethod
def create(name, device_type, ios_version):
"""
Expand Down Expand Up @@ -108,8 +124,16 @@ def start(name, timeout=180):

# Fire start command
print "Open Simulator.app with {0}".format(sim_id)
start_command = "open {0} --args -CurrentDeviceUDID {1}".format(Simulator.__get_sim_location(), sim_id)
run(command=start_command, log_level=CommandLogLevel.SILENT)

check_sim_app_running = run(command='ps aux|grep \"Simulator.app\"', timeout=60,
log_level=CommandLogLevel.SILENT)
if Simulator.__get_sim_location() in check_sim_app_running:
run(command='xcrun simctl boot {0}'.format(sim_id), timeout=60, log_level=CommandLogLevel.SILENT)
else:
start_command = "open {0} --args -CurrentDeviceUDID {1}".format(Simulator.__get_sim_location(),
sim_id)
run(command=start_command, log_level=CommandLogLevel.SILENT)

print 'Simulator {0} is booting now...'.format(name)

# Wait until simulator boot
Expand All @@ -120,7 +144,11 @@ def start(name, timeout=180):
else:
# Retry once...
Simulator.reset()
Simulator.create(SIMULATOR_NAME, SIMULATOR_TYPE, SIMULATOR_SDK)
if name == SIMULATOR_NAME:
Simulator.create(SIMULATOR_NAME, SIMULATOR_TYPE, SIMULATOR_SDK)
elif name == SIMULATOR_NAME_2:
Simulator.create(SIMULATOR_NAME_2, SIMULATOR_TYPE_2, SIMULATOR_SDK_2)

print 'Retry booting simulator...'.format(name)
run(command=start_command, log_level=CommandLogLevel.SILENT)
found, simulator_id = Simulator.wait_for_simulator(simulator_name=name, timeout=timeout)
Expand Down Expand Up @@ -243,7 +271,7 @@ def delete(name):
"""
delete_output = ""
output = run(command='xcrun simctl list | grep \'{0}\''.format(name), log_level=CommandLogLevel.SILENT)
while (SIMULATOR_NAME in output) and ('Invalid' not in output):
while (name in output) and ('Invalid' not in output):
if 'Booted' in output:
run('xcrun simctl shutdown \'{0}\''.format(name), log_level=CommandLogLevel.SILENT)
Simulator.stop()
Expand Down
5 changes: 5 additions & 0 deletions core/settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,15 @@ def resolve_path(package_env, default_value):
EMULATOR_NAME = "Emulator-Api23-Default"
EMULATOR_PORT = "5554"
EMULATOR_ID = "emulator-{0}".format(EMULATOR_PORT)

SIMULATOR_NAME = "iPhone7N"
SIMULATOR_TYPE = 'iPhone 7'
SIMULATOR_SDK = '11.0'

SIMULATOR_NAME_2 = "iPhone8N"
SIMULATOR_TYPE_2 = 'iPhone 8'
SIMULATOR_SDK_2 = '11.4'

# Android Build Settings
ANDROID_KEYSTORE_PATH = os.environ.get("ANDROID_KEYSTORE_PATH")
ANDROID_KEYSTORE_PASS = os.environ.get("ANDROID_KEYSTORE_PASS")
Expand Down
Binary file modified data/apps/livesync-hello-world.tgz
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion runNose.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from core.osutils.folder import Folder
from core.settings.settings import OUTPUT_FOLDER, CURRENT_OS, OSType, \
ANDROID_PATH, IOS_PATH, SUT_FOLDER, CLI_PATH, IOS_INSPECTOR_PATH, SIMULATOR_NAME, SIMULATOR_TYPE, SIMULATOR_SDK, \
TEST_RUN_HOME
TEST_RUN_HOME, SIMULATOR_NAME_2, SIMULATOR_TYPE_2, SIMULATOR_SDK_2
from core.tns.tns import Tns
from core.tns.tns_platform_type import Platform
from core.xcode.xcode import Xcode
Expand Down Expand Up @@ -85,6 +85,7 @@ def get_repos():
SIMULATOR_SDK = '10.0'

Simulator.create(SIMULATOR_NAME, SIMULATOR_TYPE, SIMULATOR_SDK)
Simulator.create(SIMULATOR_NAME_2, SIMULATOR_TYPE_2, SIMULATOR_SDK_2)
Xcode.cleanup_cache() # Clean Xcode cache folders
Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.ANDROID)
Device.uninstall_app(app_prefix="org.nativescript.", platform=Platform.IOS)
Expand Down
38 changes: 37 additions & 1 deletion tests/simulator/run_ios_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from core.device.simulator import Simulator
from core.osutils.file import File
from core.osutils.folder import Folder
from core.settings.settings import IOS_PACKAGE, SIMULATOR_NAME, TEST_RUN_HOME
from core.settings.settings import IOS_PACKAGE, SIMULATOR_NAME, TEST_RUN_HOME, SIMULATOR_NAME_2
from core.tns.replace_helper import ReplaceHelper
from core.tns.tns import Tns
from core.tns.tns_platform_type import Platform
Expand Down Expand Up @@ -70,6 +70,10 @@ def tearDown(self):
Tns.kill()
BaseClass.tearDown(self)

if Simulator.is_running(SIMULATOR_NAME_2)[0]:
sim_id = Simulator.is_running(SIMULATOR_NAME_2)[1]
Simulator.stop(sim_id)

@classmethod
def tearDownClass(cls):
BaseClass.tearDownClass()
Expand Down Expand Up @@ -555,6 +559,38 @@ def test_385_tns_run_ios_source_code_in_ios_part_plugin(self):
Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID,
expected_image='livesync-hello-world_home')

def test_387_tns_run_ios_console_log_on_multiple_simulators(self):
"""
https://github.com/NativeScript/nativescript-cli/issues/3529
"""

# Start one more simulator
Simulator.start(SIMULATOR_NAME_2)
SIMULATOR_ID_2 = Simulator.ensure_available(simulator_name=SIMULATOR_NAME_2)

# `tns run ios` and wait until app is deployed on both simulators
log = Tns.run_ios(attributes={'--path': self.app_name, '--emulator': ''}, wait=False, assert_success=False)
strings = ['Project successfully built',
'Successfully installed on device with identifier \'{0}\''.format(self.SIMULATOR_ID),
'Successfully installed on device with identifier \'{0}\''.format(SIMULATOR_ID_2)]
Tns.wait_for_log(log_file=log, string_list=strings, timeout=180, check_interval=10)

Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID,
expected_image='livesync-hello-world_home', timeout=60)
Device.click(self.SIMULATOR_ID, 'TAP', timeout=60)
Tns.wait_for_log(log_file=log, string_list=['The button was clicked!'], timeout=120)
Device.screen_match(device_name=SIMULATOR_NAME, device_id=self.SIMULATOR_ID,
expected_image='hello-world_home_after_tap', timeout=60)

Device.screen_match(device_name=SIMULATOR_NAME_2, device_id=self.SIMULATOR_ID,
expected_image='livesync-hello-world_home', timeout=60)
Device.click(SIMULATOR_ID_2, 'TAP', timeout=60)
Tns.wait_for_log(log_file=log, string_list=['The button was clicked!'], timeout=120)
Device.screen_match(device_name=SIMULATOR_NAME_2, device_id=SIMULATOR_ID_2,
expected_image='hello-world_home_after_tap', timeout=60)

Simulator.stop(SIMULATOR_ID_2)

def test_390_tns_run_ios_should_warn_if_package_ids_do_not_match(self):
"""
If bundle identifiers in package.json and Info.plist do not match CLI should warn the user.
Expand Down