Skip to content

Commit 19d756a

Browse files
authored
Merge pull request #474 from AutomationSolutionz/mac_appium_automation
Mac appium automation
2 parents 3637d1a + 05d8855 commit 19d756a

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

Framework/Built_In_Automation/Mobile/CrossPlatform/Appium/BuiltInFunctions.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# -*- coding: cp1252 -*-
33

44
""" Name: Built In Functions - Appium
5-
Description: Contains all Sequential Actions related to automating Android and IOS using Appium
5+
Description: Contains all Sequential Actions related to automating Android, IOS and MacOS using Appium
66
"""
77

88
#########################
@@ -14,6 +14,7 @@
1414
from appium import webdriver
1515
from appium.options.android import UiAutomator2Options
1616
from appium.options.ios import XCUITestOptions
17+
from appium.options.mac import Mac2Options
1718
import traceback
1819
import socket
1920
import os, sys, datetime, time, inspect, subprocess, re, signal, _thread, requests, copy
@@ -341,7 +342,7 @@ def find_correct_device_on_first_run(serial_or_name, device_info):
341342

342343
@logger
343344
def unlock_android_device(data_set):
344-
""" Unlocks an androi device with adb commands"""
345+
""" Unlocks an android device with adb commands"""
345346

346347
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
347348

@@ -460,10 +461,6 @@ def launch_application(data_set):
460461

461462
# Parse data set
462463
try:
463-
desiredcaps = {}
464-
desiredcaps['unicodeKeyboard'] = False
465-
desiredcaps['resetKeyboard'] = False
466-
467464
browserstack_run = False
468465
aws_run = False
469466

@@ -494,6 +491,7 @@ def launch_application(data_set):
494491
platform_version = ""
495492
device_name = ""
496493
ios = ""
494+
macos = ""
497495
no_reset = False
498496
work_profile = False
499497

@@ -506,6 +504,8 @@ def launch_application(data_set):
506504
activity_name = right
507505
elif left in ("ios", "ios simulator") and mid == "element parameter":
508506
ios = right
507+
elif "macos" in left.lower().strip():
508+
macos = right.strip()
509509
elif left == "work profile" and right.strip().lower() in ("yes", "true"):
510510
work_profile = True
511511
elif left in ("no reset", "no_reset", "noreset") and mid == "element parameter":
@@ -521,9 +521,12 @@ def launch_application(data_set):
521521
desiredcaps['unicodeKeyboard'] = False
522522
desiredcaps['resetKeyboard'] = False
523523
# Set the global variable for the preferred connected device
524-
if find_correct_device_on_first_run(serial, device_info) in failed_tag_list:
524+
if find_correct_device_on_first_run(serial, device_info) in failed_tag_list and macos == "":
525525
return "zeuz_failed"
526-
526+
elif macos != "":
527+
device_id = "device 1"
528+
appium_details[device_id] = {"driver":None, "server":None, "serial":"", "type":"macos", "iemi":"", "platform_version":"", "device_name":""}
529+
527530
device_type = appium_details[device_id]["type"].lower().strip()
528531

529532
for left, mid, right in data_set:
@@ -593,14 +596,15 @@ def launch_application(data_set):
593596
platform_version=platform_version,
594597
device_name=device_name,
595598
ios=ios,
599+
macos = macos,
596600
no_reset=no_reset,
597601
work_profile=work_profile,
598602
desiredcaps=desiredcaps,
599603
)
600604
if result == "zeuz_failed":
601605
return "zeuz_failed"
602606

603-
if launch_app: # if ios simulator then no need to launch app again
607+
if launch_app and macos == "": # if ios simulator then no need to launch app again
604608
appium_driver.activate_app(package_name) # Launch program configured in the Appium capabilities
605609
CommonUtil.ExecLog(sModuleInfo, "Launched the application successfully.", 1)
606610
return "passed"
@@ -761,6 +765,7 @@ def start_appium_driver(
761765
platform_version="",
762766
device_name="",
763767
ios="",
768+
macos="",
764769
no_reset=False,
765770
work_profile=False,
766771
desiredcaps=None,
@@ -916,6 +921,13 @@ def start_appium_driver(
916921
desired_caps["deviceName"] = "iPhone" # Read model (only needs to be unique if using more than one)
917922
desired_caps["bundleId"] = ios
918923
desired_caps["udid"] = appium_details[device_id]["serial"] # Device unique identifier - use auto if using only one phone
924+
elif str(appium_details[device_id]["type"]).lower() == "macos":
925+
CommonUtil.ExecLog(sModuleInfo, "Setting up with MacOS", 1)
926+
desired_caps["platformName"] = "mac"
927+
desired_caps["automationName"] = "mac2"
928+
desired_caps["wdaLocalPort"] = wdaLocalPort
929+
desired_caps["bundleId"] = macos
930+
desired_caps["newCommandTimeout"] = 6000
919931
else:
920932
CommonUtil.ExecLog(sModuleInfo, "Invalid device type: %s" % str(appium_details[device_id]["type"]), 3)
921933
return "zeuz_failed", launch_app
@@ -942,6 +954,8 @@ def start_appium_driver(
942954

943955
if appium_driver: # Make sure we get the instance
944956
appium_details[device_id]["driver"] = appium_driver
957+
if appium_details[device_id]["type"] == "macos":
958+
Shared_Resources.Set_Shared_Variables("screen_capture", "desktop")
945959
Shared_Resources.Set_Shared_Variables("appium_details", appium_details)
946960
CommonUtil.set_screenshot_vars(Shared_Resources.Shared_Variable_Export())
947961
CommonUtil.ExecLog(sModuleInfo, "Appium driver created successfully.", 1)

0 commit comments

Comments
 (0)