Instrument-Multiple device execution - instruments

I am able to run instrument using command line for a single device / simulator, but I need to run it on two devices. Manually I can achieve this by opening two new window of Instruments and make two copy of the js and import it. But I need to achieve this using Command Line. Can anybody help me in achieving this or does anybody have the guidelines for the same?

I struggled with this as well here is a part of my solution.
What i did is:
Create trace files in instruments with you script .js file pre selected and save it to disk.
Reads the UDID of all connected devices.
Loop trough all connected devices and replace the UDID in your trace file with the currenct UDID.
In the same loop open instruments.
for line in $(system_profiler SPUSBDataType | sed -n -e '/iPad/,/Serial/p' -e '/iPhone/,/Serial/p' | grep "Serial Number:" | awk -F ": " '{print $2}'); do
UDID=${line}
file$x $(replace 345w67ww89ww0w98w762wewq33e2 with ${UDID})
open -a Instruments /PATH/TO/TRACE/file$x
done
This solution will open multiple windows of Instruments.
You can go trough them with appleScript to click the record button.

Another way to achieve it is to open two separate instance of Instrument and execute it

Related

Embedding a custom video in a XCUITest

I'm writing a test that is supposed to test uploading a video file, using XCUITest in XCode 12. The test is supposed to be self-contained so I'm not certain how to exactly do this.
Typically I want the flow to work like this:
App builds
File is copied from the code folder (I've moved the video to be in the code) into the simulator
Tests run
However step 2 is giving me a ton of problems. I'm trying using this in a build phase:
xcrun simctl addmedia booted ~/code/resources/Video.mov
Bur it's currently giving a completely unspecified error. I'm not sure if this is because I'm trying to do it before the simulator is "booted" or if something else is going on. Does anyone have a solution?
I figured it out. The correct way to do this was to just use a . instead of ~ and then realize that:
. puts you at the project level (.xcproj)

Finding xcode project name of a ported ionic app to ios to lauch multiple simulators

As a school project, I'am working on a iOS port of a ionic chat app. After a lot of troubleshooting, I finally managed to make it work on one device. Now I want to use multiple simulators to test the chat capabilities of my app.(following this tutorial on medium).
But the problem arises on the created launch script part where I need to find my project name:
path=$(find ~/Library/Developer/Xcode/DerivedData/<YOUR_PROJECT_NAME>-*/Build/Products/Debug-iphonesimulator -name "<YOUR_APP_NAME>.app" | head -n 1)
So I tried tried the command:
find ~/Library/Developer/Xcode/DerivedData/Spiel* -maxdepth 1 -type d
and instead of returning only 1 projects it returns several ones:
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-azmvgnpavliucyaxeiykxemnwbpv
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-azmvgnpavliucyaxeiykxemnwbpv/Logs
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-azmvgnpavliucyaxeiykxemnwbpv/Index
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-azmvgnpavliucyaxeiykxemnwbpv/Build
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-bmjzcrhlutzmbahdmqohtaidhhyj
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-bmjzcrhlutzmbahdmqohtaidhhyj/Logs
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-bmjzcrhlutzmbahdmqohtaidhhyj/TextIndex
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-bmjzcrhlutzmbahdmqohtaidhhyj/Index
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-bmjzcrhlutzmbahdmqohtaidhhyj/Build
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-gfcbagyqlgghbkbfgbyqgscyprjn
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-gfcbagyqlgghbkbfgbyqgscyprjn/Logs
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-gfcbagyqlgghbkbfgbyqgscyprjn/TextIndex
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-gfcbagyqlgghbkbfgbyqgscyprjn/Index
/Users/soyanchardon/Library/Developer/Xcode/DerivedData/Spiel-gfcbagyqlgghbkbfgbyqgscyprjn/Build
As you can see I have 3 Spiel folders, and I don't know which one should I choose.
Also as an additional question, why is there 3 folders? I assume it was because of my previous failed attempts to port the app, but I really have no clue!
Thanks you.
Just delete these folders from DerivedData and rebuild. Like this, you will have only one option to choose.
And yes, the problem comes from the previous attempts.

Automating Xcode' Debug > Simulate Location command

Is there any programmatic way to control the xcode > simulate location command? I have external location test scripts I'd like to run, and ideally the test suite could cause xcode to change the location of the connected phone at will.
Is this possible, and if so how?
Not sure if it's exactly what you're after, but you can have different unit test bundles use different locations (or GPX files) by setting it up in the scheme.
You could then have unit tests in each bundle which test what you need regarding that specific location.
xctool can also just run the unit tests in a specific target using the -only option:
path/to/xctool.sh \
-workspace YourWorkspace.xcworkspace \
-scheme YourScheme \
test -only SomeTestTarget
There is a GitHub project called Pokemon-Go-Controller that does exactly what you want.
Overview of the solution:
Create a gpx file
Create a blank project referencing (not copying) that gpx file and run it on your device
Run auto clicker which will constantly click update location in Xcode
Update gpx file using some script and the device location will be automatically updated
Instead of the auto clicker you can use this Apple Script:
#Will continue update the location to the location name below from Xcode:
property locationName : "pokemonLocation" #name of your gpx filex
###########################
tell application "System Events"
tell process "Xcode"
repeat while true
click menu item locationName of menu 1 of menu item "Simulate Location" of menu 1 of menu bar item "Debug" of menu bar 1
delay 0.2
end repeat
end tell
end tell
Yes, it is possible.
1. Set up the GPX files as described in #InsertWittyName 's answer, or as described in this blog post.
2. Use Instruments to run your app in the Simulator using the different GPX files.
I would write out the entire process, but someone more eloquent than myself already has.
As an avid S/O user, I would be bereft to leave what is basically a single-link answer. So here is some extra, bonus information.
You should definitely look into security testing your location aware features. I will be at Black Hat this year, so if you're there, let's talk about it!
If you don't like the previously linked/sort of explained answer, you could use XCTest with code to simulate different locations (like this).
It looks like there are also Apple Script solutions, like this one.
I hope I have at the very least provided enough information to qualify as more than just a lazy link-only answer. Enjoy, and good luck!
idevicelocation is a command line tool to mock geolocation in ios devices.
Usage:
$ idevicelocation [OPTIONS] LATITUDE LONGITUDE
Set the location passing two arguments, latitude and longitude:
$ idevicelocation 48.856614 2.3522219000000177
Passing negative values :
$ idevicelocation 77.432332 -- -7.008373564
Stopping Location Simulation:
$ idevicelocation --stop
Options:
-d enable connection debug messages.<br/>
-u specify device UDID.<br/>
-h help.<br/>
-s stop location simulation on device.
It uses libimobiledevice library to communicate with the process com.apple.dt.simulatelocation which is also used by Xcode internally for the same purpose.
Build instructions are there in the README file. Make sure to mount the correct developer image before going random places. Thanks to Angulo for writing this awesome utility.
This tool is not currently being shipped with libimobiledevice package although there's a Pull Request pending since long.

How to get fake contacts in iOS Simulator?

How can I get fake contacts in iOS Simulator? Is there a shell script I can use or an editor for my contacts?
Edit: I use React Native so I can't just throw some Swift project in there - is there a command line tool or way to connect the iOS Simulator to my Contacts application on my Mac?
You can download this generated VCF file, and then drag/drop it to your Simulator to import (1000) fake contacts. I created this test data using the mock data generation website Mockaroo.
This was created using a small Node.js script that takes a CSV and converts it into one single VCF file - which you can then drag and drop to the iOS Simulator. This is the simplest way to import contacts, no code required or installation of apps needed off GitHub (as the other answers imply). This CSV parser assumes you have three columns at the top of the file (First Name, Last Name, and Phone Number. If you want to add more columns/variables for importing, simply modify your CSV and the parser below based off the vCard spec.
Save the below script as "mock.js" and run it with node mock (here's a GitHub gist of it). This assumes the script below, along with your CSV file (e.g. "MOCK_DATA.csv") is in the same directory. The output of running this script will be a file named "vcards.vcf".
const fs = require('fs');
const csv = fs.readFileSync('./MOCK_DATA.csv', 'utf8');
const records = csv.split('\n').slice(1);
const VCARDS = [];
records.forEach(function(record, i) {
const data = record.split(',');
const VCARD = [
'BEGIN:VCARD',
'VERSION:4.0',
`N:${data[1]};${data[0]};;;`,
`FN:${data[0]} ${data[1]}`,
`TEL;type=HOME:${data[2]}`,
'END:VCARD'
].join('\n');
VCARDS.push(VCARD);
});
fs.writeFileSync(`./vcards.vcf`, VCARDS.join('\n'));
if you're looking for a programmatic way to do this sort of thing, simctl is a nice tool -
/usr/bin/xcrun simctl addmedia booted ~/path/to/contact.vcf
NSHipster has a great writeup: https://nshipster.com/simctl/
One key thing I overlooked is that a simulator must be "booted" before you can interact with it programmatically.
I'm mostly doing this to be able to take screenshots with fastlane, and I run this bash script at the start of that lane.
It 1. lists all of the ios 13.4 devices 2. greps the UUIDs and 3. loops through each simulator to boot it, add a vcf, and shut it down
It takes a few minutes to run, but for me beats opening all of the simulators and dragging a vcf. I also clear the simulator data, as there's no de-duping here.
#!/bin/bash
xcrun simctl list devices 'iOS 13.4' \
| grep -E -o -i "([0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12})" \
| while read line ; do
xcrun simctl boot $line
/usr/bin/xcrun simctl addmedia booted PathTo.vcf
xcrun simctl shutdown $line
done
Bit cleaner version of niftylettuce's answer, with Faker data, images, and extra data for evenly numbered contacts:
https://github.com/corysimmons/vcf-generator
I just found this while looking to do the same. Here is what I ended up doing:
for i in {0..100}
do
echo "BEGIN:VCARD\n
VERSION:4.0\n
PRODID:-//BBros.us llc//bvCard.com//EN\n
N:User"$i";TEst;;;\n
FN:TEst User"$i"\n
EMAIL:test.user"$i"#domain.com\n
ORG:Great Business\n
END:VCARD" > "File$(printf "%03d" "$i").vcf"
done
In Terminal I changed to a test folder, and ran this script in there. It created the VCard files, and I then dragged them to a running simulator window and dropped them on the simulator. This caused the simulator to open Contacts and import them.
I hope this helps.
* UPDATE *
So once I updated Xcode I can now only import a single contact at once, which is not ideal. This lead me to another solution:
https://github.com/cristianbica/CBSimulatorSeed-Swift
This is a quick app you can build & run in simulator to seed many contacts for you.

Blackberry older simulator

my client wants me to make an application which works on pre4.0 os... i understand that if i make 1 like that then it wont work on the latest os...
But my actual problem is that though i did the coding correctly coz the application was just a simple WebIcon... i cant load it onto the 7290 simulator...
i tried javaloader -u load MyApp.jad and javaloader -u load MyApp.cod... but i get the following error
Error: unable to open port...
earlier it couldnt find javac... so i placed javac in the System32 folder... now the below shown error is displayed and further the simulator doesnt connect with even the 4.0 IDE....
even tried compiling in the 4.0 IDE itself... but i get the following error...
Error!: Error: java compiler failed: javac -source 1.3 -target 1.1 -g -O -d MyDir
Don know wat to do... plz help...
screenshot of the simulator...
alt text http://www.freeimagehosting.net/uploads/d9e1840ce0.jpg
Well friends at last i tried uploading the applications .cod and .jad along with the optional .jar onto my company's server... and guess wat... it did download using the jar file but after trying all the techniques mentioned here... i guessed this was it...
But the application though gets listed in the applications but doesnt show up on the menu... and neither does it run in anyway...
Hence im closing with the research here... thanx a lot guys...
I load my programs doing the following:
(Note: This is on an Curve 8310--which has a memory card slot--not sure if you can plug in the phone and use it in HardDisk mode)
Plug the phone into the computer to enable HD mode
Copy the .jad, .jar and .cod to the memory card (or device memory in your case if HD mode works for this) of the phone
Click the Media Icon
Open the menu within media and hit explore (Here I have an option for memory card OR device memory) -- Select the device memory
Finally, find and select the .jad file -- the phone will ask if you want to download--just hit yes, and this will prompt for the install
Again, I realize this is a different (older) phone which you are using, so this method may not work.
Hope it helps!
Greg

Resources