[Appium-XCUITest-Example] How to get started appium using Xcuitest for real device

How to get started appium using Xcuitest for real device.

I found there are a lot of duplicated question about xcuitest and appium 1.6 beta in here. but most of questions about this still no good answer. so I decide to write a tutorials for everyone who don’t know how to get started appium using Xcuitest.

Let’s go ahead to see.

0. Preparation

Firstly make sure your node >=4 and npm>=3 before you install appium beta version using npm.

1. Install appium v1.6

npm3 install -g appium@beta

2. Install dependencies

brew install ideviceinstaller
brew install carthage
npm install -g ios-deploy

3. Launch appium server

appium

4. Write script using appium python-binding.

Remember set automationName as “XCUITest”,
and you also need set realDeviceLogger as idevicesyslog.

from appium import webdriver
import os

app_path = "<your app path>"
udid = "<your udid>"
platformVersion = "<your platform version>"
deviceName = "<your device name>"

success = True
desired_caps = {}
desired_caps['platformName'] = 'iOS'
desired_caps['platformVersion'] = platformVersion
desired_caps['deviceName'] = deviceName
desired_caps['udid'] = udid
desired_caps['automationName'] = 'XCUITest'
desired_caps['realDeviceLogger'] = 'idevicesyslog'
desired_caps['app'] = os.path.abspath(app_path)

wd = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)
wd.implicitly_wait(60)

try:
	wd.find_element_by_xpath("//XCUIElementTypeButton[@name='OK']").click()
	wd.find_element_by_xpath("//XCUIElementTypeTextField[1]").send_keys("123")
finally:
	wd.quit()
	if not success:
		raise Exception("Test failed.")

5. Update your device info and run the script.

Note:

Remeber you have to change all UIA to XCUIElementType when you create xpath expression, for example:

UIAButton --> XCUIElementTypeButton
UIAXXX    --> XCUIElementTypeXXX

Some Problems:

How to solve slow appium tests on OSX 10.12 Sierra? ( Dezik provided )

6 Likes

Great tutorial , make some things to be more clear now …

From your snapshot , I see that you are still using Xcode 7.3.1 ?

So it’s possible to use XCUITest with previous ver of instruments as well ?

Thanks

Correct. It depends on the value of automaitonName.

Thanks for this, but its not working for me. Perhaps its an XCode 8 issue? When I run sudo npm3 install -g appium I get this error repeated a LOT of times:

npm ERR! uid must be an unsigned int
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/lib/node_modules/npm3/node_modules/npm/cli.js" "install" "-g" "appium"
npm ERR! node v4.6.0
npm ERR! npm  v3.10.8

Any ideas?

I got past this by installing the latest node (4.6.2) but I still cannot get appium to run with Xcode 8 and macOS Sierra.

I documented all my steps:

brew install carthage
sudo npm install -g webpack
n latest
npm install selenium
npm install ios-deploy
sudo npm install -g appium@beta
sudo npm install -g npm3
npm3 install appium-xcuitest-driver

But I get this error when I try to run a test:

[Xcode] 
Testing failed:
	./Scripts/generate_modules.sh: line 15: Modules/module.modulemap: Permission denied
** TEST FAILED **


The following build commands failed:
	PhaseScriptExecution Generate\ modules /Users/kaz/Library/Developer/Xcode/DerivedData/WebDriverAgent-brdadhpuduowllgivnnvuygpwhzy/Build/Intermediates/WebDriverAgent.build/Debug-iphonesimulator/WebDriverAgentLib.build/Script-AD35D0281CF1B37A00870A75.sh
(1 failure)

I have tried running appium as root, but that causes all sorts of other errors. What am I missing??

hi bro, I am sorry I use Xcode7 and EI Captian. I think maybe the problem is because XCode version. What is your whole appium server log?

I didn’t install the appium-xcuitest-driver explicitly, just appium@beta and things seem to be working. But just out of curiosity, what are the contents of that Script-*.sh shell script? I had a similar problem installing ios-deploy and it turned out to be related to my version libreadline. Maybe try running that script on its own with like sh -x ./Script-AD35D0281CF1B37A00870A75.sh and see what it spits out.

Alternatively, you could try git cloning the project and building according to the steps in the README.md and see if that works. Then you could at least have some data points to contrast where the npm install fails compared to building locally from source. I can confirm that with El Capitan + XCode 8, I was able to compile and run WebDriverAgentRunner from source and get it running. Didn’t try to install via npm3, though (git clone [email protected]:appium/appium-xcuitest-driver.git).

If it turns out you’re having trouble with readline when it tries to figure out the lldb dependencies, you might want to make sure you’re using the version of libreadline it’s expecting (I had to do brew switch readline 6.3.8 to get ios-deploy running, don’t know if this is also a problem with xcuitest-driver). I hope this helps.

Hi,

So I don’t need to build WebDriverAgent in Xcode? or something?

I am trying to execute mobile native app execution on real device . But appium log says “[debug] [XCUITest] Waiting up to 60000ms for WebDriverAgent to start”

I am not undressing why we have web driver agent running when i try to execute native mobile app but not web application .

Please confirm if any configurations needed to run native app.