Skip to content

Instantly share code, notes, and snippets.

@kumarSC
Last active November 5, 2015 02:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kumarSC/58852f20c08df41129cd to your computer and use it in GitHub Desktop.
Save kumarSC/58852f20c08df41129cd to your computer and use it in GitHub Desktop.
Shell utility to capture latest test results from XCode UI Testing tool and convert it as JSON consumable for CI (Jenkins, Bamboo) or other reporting.
#!/bin/bash
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
reset=`tput sgr0`
command -v jq >/dev/null 2>&1 || { echo "${red}Script could not find jq command installed on system.Installing...${reset}" >&2; `brew install jq`; }
# command -v jq >/dev/null 2>&1 || { echo >&2 ". Aborting."; exit 1; }
echo -e "${green}This simple utility will find the latest Xcode UI Test Result and transform the result in a JSON\nIn case you don't have a custom result directory passed as an argument, Script will look for test results in default DerivedData dir\n${yellow}Usage: $0 testResult-dir-path${reset}\n"
resultDir="$1"
deriveData="$HOME/Library/Developer/Xcode/DerivedData"
if [ $# -eq 0 ] && [ -d $deriveData ] ; then
latestTestResult=`find $deriveData -name "*TestSummaries*" -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" "`
echo $latestTestResult
else
if [ -d $resultDir ] ; then
latestTestResult=`find $resultDir -name "*TestSummaries*" -type f -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -1 | cut -f2- -d" "`
echo $latestTestResult
else
echo -e "${red}Invalid result directory.\n${yellow}Usage: $0 testResult-dir-path${reset}\n"; exit 1;
fi
fi
plutil -convert json $latestTestResult -r -o XcodeUITestResult.json
successfulExport=$?; if [[ $successfulExport != 0 ]]; then echo "${red}Json results export failed${reset}"; exit $successfulExport; else echo "${green}Json results exported as XcodeUITestResult.json${reset}"; fi
#TODO: Filtering UI Test specific data from JSON using jq
jq '.RunDestination.LocalComputer.Platform','.RunDestination.TargetSDK','.TestableSummaries[1]' XcodeUITestResult.json
@kumarSC
Copy link
Author

kumarSC commented Nov 5, 2015

Updated capability to filter specific UI Test result element from JSON with jq(https://stedolan.github.io/jq)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment