How can I set the path to Instruments on Appium? - ios

I'm trying to run Appium for an iOS application, but it seems that the path to instruments is invalid. How can I set it? Is there an environment variable I should use? Or some argument? Even I could change that in the source code it would be useful for me :)
Here's the relevant part of the log I receive from Appium:
info: instruments is:
info: [INSTSERVER] Instruments socket server started at /tmp/instruments_sock
info: Spawning instruments with command: -t /usr/local/lib/node_modules/appium/app/uiauto/Automation.tracetemplate /var/folders/rd/z5t93lfj0cx0wm2_hqmthnkr0000gn/T/TestApp.app -e UIASCRIPT /usr/local/lib/node_modules/appium/app/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments/
Thanks!

You can use sudo xcode-select --switch /path/to/Xcode.app to select which version of Xcode you'd like to use with appium.

Ok, After some digging in the code it appears Appium takes its "Instruments" path by using the command xcrun -find instruments.
xcrun itself has cache, so if you changed/removed xcode you should probably run
xcrun -kill-cache -find instruments
This will clear the cache, but will not necessarily point xcrun to the right path. In order to do so you should add the environment variable DEVELOPER_DIR to point to the Xcode developer directory, e.g. /Applications/Xcode.app/Contents/Developer.

Related

How to launch iOS Simulator in specific language from command line?

I need to lauch iOS Simulator that uses specific language using command line. So I found that I can use
instruments -w <device>
and it is working great, I can set specific device. But how can I run simulator with specific language? I've tried adding
-AppleLanguages -AppleLocale
but there are some warnings:
Instruments Usage Error : Specified target process is invalid: -AppleLanguage
thanks!
The only way to launch iOS Simulator with specific language is to change contents of its .GlobalPreferences.plist file. Using xcrun tool will not work because it passess arguments to launched app and not changing language of simulator itself. Manipulation on .GlobalPreferences.plist is quite difficult because it is a binary plist file, so you cannot modify it as 'normal' xml. The easiest way to change its contents is to write simple Xcode Command Line Tool application, Foundation SDK has all tools needed to modify binary plists.
To run your app must be installed and located (if not, will open default language)
Use this command to run your app with some language
xcrun simctl launch <deviceid> <appid> -AppleLanguages "(pt-BR)"
Sample:
xcodebuild -sdk iphonesimulator8.4 -arch i386 install DSTROOT=SomeFolder
xcrun instruments -w "iPhone 6 (8.4 Simulator)"
xcrun simctl install booted SomeFolder/Applications/YourApp.app
xcrun simctl launch booted com.yourdomain.yourapp -AppleLanguages "(pt-BR)"
Have a look at:
https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/TestingYourInternationalApp/TestingYourInternationalApp.html
Search for "Testing Specific Languages and Regions"
Perhaps it could also be a solution creating different targets. Each target has configured another language

Having an issue Running instruments using terminal

I have used this below command to run automation template using instruments.
instruments -t /Applications/xcode5.0.2/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate ~/Library/Application\ Support/iPhone\ Simulator/7.1/Applications/93F12976-0667-4180-904A-95ECA172C78C/myapp.app -e UIASCRIPT /Users/myUserName/Desktop/TestScript.js
This command is able to open the simulator and my app in the simulator but, its not running the TestScript.js file, because when this file is loaded into instruments its adding up escape sequences in my code, which is ruining my code and not allowing to run the script.
did anybody face this issue before?
Or any body has any suggestion on running instruments using terminal.

Appium setup on Mac machine

I am trying to use Appium on mac Machine.
I am getting the below error, I tried unistalling the appium and installiing it.
When I tried to run the command directly, I am able to launch the app. Please help.
Error is
info: Spawning instruments with command: /Applications/Xcode.app/Contents/Developer/usr/bin/instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /Users/vchaudha/Desktop/InternationalMountains.app -e UIASCRIPT /Volumes/Appium/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-uiauto/uiauto/bootstrap.js -e UIARESULTSPATH /tmp/appium-instruments
info: And extra without-delay env: {"DYLD_INSERT_LIBRARIES":"/Volumes/Appium/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/thirdparty/iwd4/InstrumentsShim.dylib","LIB_PATH":"/Volumes/Appium/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-instruments/thirdparty/iwd4"}
info: And launch timeouts (in ms): {"global":90000}
info: [INST STDERR] Instruments Usage Error : (null)
I Got the resolution of this. So for others who gets stuck with this error.
Do not try to run the Appium from image but copy it into applications directory and then run from there.

Automation testing with instruments on device

I am trying to follow this post to run UIAutomation scripts on iOS devices from command line, but i can't make it work.
This is the command i am currently using :
instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate /Users/X/Library/Developer/Xcode/DerivedData/TestiPhoneAutomation2-dyufpxsavtdqkybpagcoawdudzid/Build/Products/Debug-iphoneos/TestiPhoneAutomation2.app -e UIASCRIPT "/Users/X/Workspaces/TestiPhoneAutomation/test2.js" -e UIARESULTSPATH "/Users/X/Workspaces/TestiPhoneAutomation2/" -w 80bf5b...UDID...dfb52543 -v
It works well on simulator (replacing the Debug-iphoneos by Debug-iphonesimulator, it also ignore the -w in this case), but if i launch it using an application compiled for device it crash (i tried with release and debug, i get the same result).
The error i'm getting is :
posix spawn failure; aborting launch (binary ==
/Users/X/Library/Developer/Xcode/DerivedData/TestiPhoneAutomation2-dyufpxsavtdqkybpagcoawdudzid/Build/Products/Debug-iphoneos/TestiPhoneAutomation2.app/TestiPhoneAutomation2).
2012-10-03 12:10:36.609 instruments[76151:1603] Recording cancelled :
At least one target failed to launch; aborting run Instruments Trace
Error : Failed to start trace.
I got this same error, but I didn't have multiple copies of Instruments running. I got this working by putting the -w UDID arguments before the application, and only using the name of the application (with the application already deployed to the device).
The command line I used is the following (with Xcode 4.6):
instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate -w <device_id> <app_name> -e UIASCRIPT <path_to_script> -e UIARESULTSPATH <path_to_results>
Pls check the sequence of UDID in command line in fact for all parameters also run on debug version of build only. Hope this works, because its working for me.
For anyone else having this problem, I'll explain what worked for me and how I solved this.
I did the ps command to see which processes are running. I found that instruments was still running. I then did killall instruments and that killed the instruments process. I then did my instruments command and it worked perfect after that.

Can't run UIAutomationTest from command line

I have an iOS application, and I want to put it in continuous integration. The strategy I'm using to do that is trying to run the tests from the command line.
I'm trying to do it using the following script:
TRACETEMPLATE="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
instruments -t $TRACETEMPLATE build/Release-iphonesimulator/MyApp.app -e UIACSCRIPT "UnitTests/SomeTest.js"
SomeTest.js is a simple javascript file that I can run in Instrumentation inside Xcode and it works. I build my application using:
xcodebuild -alltargets -sdk iphonesimulator5.1
and this generates the MyApp.app. I can run the application from Xcode in the simulator just fine, however, when I try to run by the instruments, I get a box saying that there is an unknown error and in the command line it prints:
2012-05-15 15:32:59.928 instruments[17548:1d03] Recording cancelled : At least one target failed to launch; aborting run
Instruments Trace Error : Failed to start trace.
Can anyone give me any help/suggestions about what might be happening and how can I fix this?
Also, it always open the iPad simulator? Can I make it that it opens any simulator I want?
I was getting this same error and nearly pulled my hair out trying to solve it. The error messages are completely unhelpful.
What ended up being the problem for me was the .app file that I was pointing to. Once I found the "right" .app file that was deeply buried in the 5.1 Simulator folder, I was able to finally run UIAutomation tests from the command line with Xcode 4.3.
The path to the .app that worked for me:
~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications/{string-of-numbers-and-letters}/MyApp.app/
Here is the full command I'm using to run UIAutomation tests from the command line with Xcode 4.3:
instruments -t /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Instruments/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate ~/Library/Application\ Support/iPhone\ Simulator/5.1/Applications/{string-of-numbers-and-letters}/MyApp.app/ -e UIASCRIPT /Path/To/TestFile.js
Hope this helps someone else, as the documentation out there for this is extremely lacking.
Update
Note that as of Xcode 4.5.2, the automation template location has changed from that on my original answer:
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
The correct location of the Automation.tracetemplate, as of Xcode 4.5.2, is /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate
The paths for the command line invocation of UIAutomation has changed slightly over the past couple of years. I have written a few bash shell scripts that work together which can launch your UIAutomation test file in a way that works with Xcode 4.4.1.
See this gist: https://gist.github.com/3605692#comments
In a nutshell, the key command ends up being:
instruments -t $INSTRUMENTS_TEMPLATE $APP_PATH -e UIASCRIPT $SCRIPT_PATH -e UIARESULTSPATH $RESULTS_PATH
My scripts show the variable substitutions needed. The other benefit is that iOS simulator apps have often changing GUID as part of their path. My script will find them, so you don't have to hard code the temporary GUID in your builds / scripts / command line invocations.
sorry, my english is very bad.
As the easiest way to run this script from Teamtsity? Each assembly - the numbers and letters are different.
Not the easiest way:
clean the simulator prior to assembly
find the folder with the program, and it contains these numbers and letters, written in the variable.
This variable, such as writing the script.
Maybe there's a way easier to take from these numbers?
The Build Configuration should be debug than Release. That was the reason for the error in my case.
You can change Build Configuration in 'Edit Schemes' and by choosing the Profile tab. Verify that build tab also is in debug mode.
I did the ps command to see which processes are running. I found that instruments was still running. I then did killall instruments and that killed the instruments process. I then did my instruments command and it worked perfect after that.

Resources