How to run Apple UI Automaton script in terminal? - ios

instruments -w ‘AA6257B1-D3E0-49A6-85C2-F865B17ED6CD' \
-t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
'/Users/AZ-Admin/Downloads/test.app' \
-e UIASCRIPT '/Users/AZ-Admin/Desktop/UI\ Automation/ApTest.js' \
-e UIARESULTSPATH '/Users/AZ-Admin/Desktop/UI Automation'
Above is the instruction which I am giving to terminal for execution.
the problem I am facing here is my script is not executing only my Simulator is popping up and showing the app
I am also giving my ApTest.js code where my Automation Script is present
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
var testName = "Create a New Appointment";
UIALogger.logStart(testName);
target.frontMostApp().mainWindow().elements()["Finder View"].buttons()["CRM"].tap();
target.frontMostApp().mainWindow().buttons()["New Appointment"].tap();
target.frontMostApp().mainWindow().tableViews()["Edit Table"].tapWithOptions({tapOffset:{x:0.56, y:0.21}});
Thank you

Have you tried to execute the script via Instruments GUI?
Also I'd try not to use UIARESULTSPATH, but output directly into console instead.

It looks like you have an error in your -e UIASCRIPT '/Users/AZ-Admin/Desktop/UI\ Automation/ApTest.js' \ line.
Try using -e UIASCRIPT "/Users/AZ-Admin/Desktop/UI/Automation/ApTest.js" instead.
If it launches your app on the device you specify, you know the first two lines are correct. It sounds like Instruments doesn't know what test code to run once it launches the target app.

Related

Tool for edit lvm.conf file

is there any lvm.conf editor?
I'm trying to set global_filter, use_lvmtad and some other options, currently using sed:
sed -i /etc/lvm/lvm.conf \
-e "s/use_lvmetad = 1/use_lvmetad = 0/" \
-e "/^ *[^#] *global_filter/d" \
-e "/^devices {/a\ global_filter = [ \"r|/dev/drbd.*|\", \"r|/dev/dm-.*|\", \"r|/dev/zd.*|\" ]"
but I don't like this too much, is there any better way?
I found only lvmconfig tool, but it can only display certain configuration sections, and can't edit them.
If you using Ubuntu variant then you can use the LVM GUI to configure and manage the LVM. Refer this link
It seems that augtool is exactly what I was looking for.
These two packages should be enough to proper processing lvm.conf file:
apt install augeas-tools augeas-lenses
Example usage:
augtool print /files/etc/lvm/lvm.conf
And you should get the whole parse tree on stdout.
If the parser fails you won’t get any output, print the error message using:
augtool print /files/etc/lvm/lvm.conf/error
The augtool equivalent for the sed command from the original question:
augtool -s <<EOT
set /files/etc/lvm/lvm.conf/global/dict/use_lvmetad/int "0"
rm /files/etc/lvm/lvm.conf/devices/dict/global_filter
set /files/etc/lvm/lvm.conf/devices/dict/global_filter/list/0/str "r|^/dev/drbd.*|"
set /files/etc/lvm/lvm.conf/devices/dict/global_filter/list/1/str "r|/dev/dm-.*|"
set /files/etc/lvm/lvm.conf/devices/dict/global_filter/list/2/str "r|/dev/zd.*|"
EOT

Unable to run command line for iOS UI Automation

I used the template from this website: http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation and created my own command line to run the automation test on terminal.
Here are some useful information about my script:
I'm using xCode 6.4.
I ran this automation script in Xcode instrument and it works fine.
Here is my command line:
instruments -w 927b666816e2d4377b208a872b42a1d3xxxxxxxx -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate ConsumeriOS -e UIASCRIPT/Users/wendywang/Documents/TIO/ConsumeriOS/ConsumeriOS/ConsumeriOSTests/automationScript/LogIn.js
But I received this error:
2015-10-05 14:16:34.122 instruments[23330:551118] WebKit Threading Violation - initial use of WebKit from a secondary thread. Instruments Usage Error : Failed to resolve target for Instrument 'Automation' instruments, version 6.4 (57082) usage: instruments [-t template] [-D document] [-l timeLimit] [-i #] [-w device] [[-p pid] | [application [-e variable value] [argument ...]]] tio-spare:~ wendywang$ ConsumeriOS -e UIASCRIPT /Users/wendywang/Documents/xxx/ConsumeriOS/ConsumeriOS/ConsumeriOSTests/automationScript/LogIn.js -bash: ConsumeriOS: command not found
I double checked that
The UDID is correct
The automation trace template is in the correct path
The LogIn.js file is in the correct path
One thing I am not sure:
The ConsumeriOS is the name of the code. But inside the code, it can actually produce a few apps. I am testing the app called Consumer. So I am not sure if I should write ConsumeriOS as the name of the app, or Consumer instead.
Does anyone know why it is generating this error? Thanks!
Huhu,
try this:
Give the
complete path to the app with the .app extension,
Put the DeviceID and the script into "",
try it with the device name, if it doesn't
work.
Here a sample that works for me.
instruments -w "DeviceID" -t PATHTOTEMPLATE/Automation.tracetemplate PATHTOAPP/ConsumeriOS.app -e UIASCRIPT "PATHTOSCRIPT/UITest.js"
Let me know!
The relevant message is this one:
tio-spare:~ wendywang$ ConsumeriOS -e UIASCRIPT /Users/wendywang/Documents/xxx/ConsumeriOS/ConsumeriOS/ConsumeriOSTests/automationScript/LogIn.js -bash: ConsumeriOS: command not found
It appears that you may have copy-pasted this command:
instruments -w 927b666816e2d4377b208a872b42a1d3xxxxxxxx -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate ConsumeriOS -e UIASCRIPT/Users/wendywang/Documents/TIO/ConsumeriOS/ConsumeriOS/ConsumeriOSTests/automationScript/LogIn.js
But incorrectly -- in two separate pieces, part 1:
instruments -w 927b666816e2d4377b208a872b42a1d3xxxxxxxx -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate
And part 2 (separated by a newline):
ConsumeriOS -e UIASCRIPT/Users/wendywang/Documents/TIO/ConsumeriOS/ConsumeriOS/ConsumeriOSTests/automationScript/LogIn.js
Separately, it looks like you wrote the name of your app (ConsumeriOS) instead of the full path to your app (/path/to/ConsumeriOS.app).

instruments automation command not working , when executed twice in terminal. i am using xcode 6.1.1

I am using the following command in terminal to trigger my simulator.
instruments -w 'iPhone 5s' -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate <app file path> -e UIASCRIPT <script path> -e UIARESULTSPATH <testreport path>
For the first time it is working , but when i try to run it the second time in the same terminal window it is throwing the following errors.
Instruments Trace Error : Target failed to run: The operation couldn’t be completed. (FBSOpenApplicationErrorDomain error 8.) : Failed to launch process with bundle identifier "com.xxx.yyy"
and also soemtimes the error
Instruments Trace Error : Target failed to run: The operation couldn’t be completed. (FBSOpenApplicationErrorDomain error 4.)
Here is my code for running instruments using command line, note that this code is for real devices (TestAutomator is the name of the app, no need to add .ipa):
instruments -w 'fa10dec83c62a571a9691b5d9ef24cc68de73bf0' \
-t '/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate' \
TestAutomation \
-e UIASCRIPT '/Users/roykronenfeld/Desktop/Automation.js' \
-e UIARESULTSPATH '/Users/roykronenfeld/Desktop‘
And here is a working version for simulator:
instruments -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate "/Users/JOHN/Library/Application Support/iPhone Simulator/7.1/Applications/B9812A59-EBE4-454E-B910-B2969B4D3702/TestApp.app" -e UIASCRIPT ./Tests.js
I encountered this same error via an Appium run, which wraps Instruments.
For me, the fix was:
XCode > Projects > (My Project) > General
In the Identity section, I found errors with my ID and Certificate. I used Xcode prompts to fix both.
(Appium specific) Confirm node is installed.
Check the sign info of your project.Generally speaking, the warning message means that the Instrument didn't have the authority to run the target application on your device.

How to print messages after make done with cmake?

I'm trying to print messages after building process done using CMake.
I just want to inform the user after make command is done without any error.
How can I do it? I tried add_custom_target() but I cannot choose when to run.
Also, I tried add_custom_command(), again it doesn't give me the right result.
Any idea?
Thank you for your idea in advance.
You could, indeed, do the following:
add_custom_target( FinalMessage ALL
${CMAKE_COMMAND} -E cmake_echo_color --cyan "Compilation is over!"
COMMENT "Final Message" )
add_dependencies( FinalMessage ${ALL_TARGETS} )
That custom target depending on the list of all the targets you previously defined, you make sure it will be run last.
To print a message after building a specific target, e. g. make yourtarget, you can use
add_custom_command(TARGET yourtarget POST_BUILD
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan
"Message after yourtarget has been built.")
Instead of POST_BUILD, you could also use PRE_BUILD or PRE_LINK for other purposes, see documentation.
(You specified in the comments, that you like to print a message after all targets, but the original question is less precise. So it might be of some value for people looking here.)
I just resolved the issue with the help of smarquis.
Thank you.
Here's the step by step procedure to do it. Since my source tree are connected complicatedly with add_subdirectory() method, this method can be applied everyone.
Initialize ALL_TARGETS variable cached. Add the line in CMakeLists.txt right below the version checking command.
Set(ALL_TARGETS "" CACHE INTERNAL "")
Override Add_library() and Add_executable() methods. If there's any other target, override it as well. Add the lines below at the end of CMakeLists.txt file.
function(Add_library NAME)
Set(ALL_TARGETS ${ALL_TARGETS} "${ARGN}" CACHE INTERNAL "ALL_TARGETS")
_add_library(${NAME} ${ARGN})
endfunction()
function(Add_executable NAME)
Set(ALL_TARGETS ${ALL_TARGETS} "${ARGN}" CACHE INTERNAL "ALL_TARGETS")
_add_executable(${NAME} ${ARGN})
endfunction()
Create custom target that will execute all the things you want to do after building. In this example I just print some information on screen. Add it followed by the above.
add_custom_target(BUILD_SUCCESSFUL ALL
DEPENDS ${ALL_TARGETS}
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "====================="
COMMAND ${CMAKE_COMMAND} -E echo " Compile complete!"
COMMAND ${CMAKE_COMMAND} -E echo "====================="
COMMAND ${CMAKE_COMMAND} -E echo ""
)
Tada!

Running iOS UIAutomation as a post-action build script is return as a posix spawn error

I'm entirely new to using bash and Xcode build scripts and so my code is probably a jungle full of errors.
The idea here is to trigger the script below which will scrape the directory that it is saved in for any .js automation scripts. It will then send these scripts to instruments to be run one at a time. I found some nifty code that created time stamped files and so I used that to create a more meaningful storage system.
#!/bin/bash
# This script should run all (currently only one) tests, independently from
# where it is called from (terminal, or Xcode Run Script).
# REQUIREMENTS: This script has to be located in the same folder as all the
# UIAutomation tests. Additionally, a *.tracetemplate file has to be present
# in the same folder. This can be created with Instruments (Save as template...)
# The following variables have to be configured:
#EXECUTABLE="Plans.app"
# Find the test folder (this script has to be located in the same folder).
ROOT="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Prepare all the required args for instruments.
TEMPLATE=`find $ROOT -name '*.tracetemplate'`
#EXECUTABLE=`find ~/Library/Application\ Support/iPhone\ Simulator | grep "${EXECUTABLE}$"`
echo "$BUILT_PRODUCTS_DIR"
echo "$PRODUCT_NAME"
EXECUTABLE="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/"
SCRIPTS=`find $ROOT -name '*.js'`
# Prepare traces folder
TRACES="${ROOT}/Traces/`date +%Y-%m-%d_%H-%M-%S`"
mkdir -p "$TRACES"
printf "\n" >> "$ROOT/results.log"
echo `date +%Y-%m-%d_%H-%M-%S` >> "$ROOT/results.log"
# Get the name of the user we should use to run Instruments.
# Currently this is done, by getting the owner of the folder containing this script.
USERNAME=`ls -l "${ROOT}/.." | grep \`basename "$ROOT"\` | awk '{print $3}'`
# Bring simulator window to front. Depending on the localization, the name is different.
osascript -e 'try
tell application "iPhone Simulator" to activate
on error
tell application "iOS Simulator" to activate
end try'
# Prepare an Apple Script that promts for the password.
PASS_SCRIPT="tell application \"System Events\"
activate
display dialog \"Password for user $USER:\" default answer \"\" with hidden answer
text returned of the result
end tell"
# Run all the tests.
for SCRIPT in $SCRIPTS; do
echo -e "\nRunning test script $SCRIPT"
TESTC="sudo -u ${USER} xcrun instruments -l -c -t ${TEMPLATE} ${EXECUTABLE} -e UIARESULTSPATH ${TRACES}/${TRACENAME} -e UIASCRIPT ${SCRIPT} >> ${ROOT}/results.log"
#echo "$COMMAND"
echo "Executing command $TESTC" >> "$ROOT/results.log"
echo "here $TESTC" >> "$ROOT/results.log"
OUTPUT=$(TESTC)
echo $OUTPUT >> "$ROOT/results.log"
echo "Finished logging" >> "$ROOT/results.log"
SCRIPTNAME=`basename "$SCRIPT"`
TRACENAME=`echo "$SCRIPTNAME" | sed 's_\.js$_.trace_g'`
for i in $(ls -A1t $PWD | grep -m 1 '.trace')
do
TRACEFILE="$PWD/$i"
done
if [ -e $TRACEFILE ]; then
mv "$TRACEFILE" "${TRACES}/${TRACENAME}"
fi
if [ `grep " Fail: " results.log | wc -l` -gt 0 ]; then
echo "Test ${SCRIPTNAME} failed. See trace for details."
open "${TRACES}/${TRACENAME}"
exit 1
break
fi
done
rm results.log
A good portion of this was taken from another Stack Overflow answer but because of the repository setup that I'm working with I needed to keep the paths abstract and separate from the root folder of the script. Everything seems to work (although probably not incredibly efficiently) except for the actual xcrun command to launch instruments.
TESTC="sudo -u ${USER} xcrun instruments -l -c -t ${TEMPLATE} ${EXECUTABLE} -e UIARESULTSPATH ${TRACES}/${TRACENAME} -e UIASCRIPT ${SCRIPT} >> ${ROOT}/results.log"
echo "Executing command $TESTC" >> "$ROOT/results.log"
OUTPUT=$(TESTC)
This is turned into the following by whatever black magic Bash runs on:
sudo -u Braains xcrun instruments -l -c -t
/Users/Braains/Documents/Automation/AppName/TestCases/UIAutomationTemplate.tracetemplate
/Users/Braains/Library/Developer/Xcode/DerivedData/AppName-
ekqevowxyipndychtscxwgqkaxdk/Build/Products/Debug-iphoneos/AppName.app/ -e UIARESULTSPATH
/Users/Braains/Documents/Automation/AppName/TestCases/Traces/2014-07-17_16-31-49/ -e
UIASCRIPT /Users/Braains/Documents/Automation/AppName/TestCases/Test-Case_1js
(^ Has inserted line breaks for clarity of the question ^)
The resulting error that I am seeing is:
posix spawn failure; aborting launch (binary ==
/Users/Braains/Library/Developer/Xcode/DerivedData/AppName-
ekqevowxyipndychtscxwgqkaxdk/Build/Products/Debug-iphoneos/AppName.app/AppName).
I have looked all over for a solution to this but I can't find anything because Appium has a similar issue. Unfortunately I don't understand the systems well enough to know how to translate the fixes to Appium to my own code but I imagine it's a similar issue.
I do know that the posix spawn failure is related to threading, but I don't know enough about xcrun to say what's causing the threading issue.
Related info:
- I'm building for the simulator but it'd be great to work on real devices too
- I'm using xCode 5.1.1 and iOS Simulator 7.1
- This script is meant to be run as a build post action script in xCode
- I did get it briefly working once before I broke it and couldn't get it back to the working state. So I think that means all of my permissions are set correctly.
UPDATE: So I've gotten to the root of this problem although I have not found a fix yet. First of all I have no idea what xcrun is for and so I dropped it. Then after playing around I found that my Xcode environment variables are returning the wrong path, probably because of some project setting somewhere. If you copy the Bash command from above but replace Debug-iphoneos with Debug-iphonesimulator the script can be run from the command line and will work as expected.
So for anyone who happens across this the only solution I could find was to hardcode the script for the simulator.
I changed EXECUTABLE="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/" to be EXECUTABLE="${SYMROOT}/Debug-iphonesimulator/${EXECUTABLE_PATH}". This is obviously not a great solution but it works for now.

Resources