How to run mtouch command to launch Xamarin.iOS app on simulator for automated testing? - testing

I am new to Xamarin and I need to be able to launch a Xamarin iOS app on iOS simulator from command line. I have tried running mtouch but obviously am missing on something as I am not able to successfully launch the app on simulator. I don't know if I am missing on setting any environment variable or am running it from a wrong location as I am getting "Cannot find command" error.

mtouch -launchsim Hello.app
mtouch docs are here
On a Mac, the mtouch binary should be here
/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch

Related

“launchPackager.command” can’t be opened

Just updated my Mac to the official release of Ventura, and I cannot launch my application via react-native run-ios.
Expected behavior:
running react-native run-ios will launch an Xcode simulator and a terminal window with Metro running.
Current behavior:
Xcode simulator opens, main terminal says app was built successfully, but an error is thrown instead of the metro terminal opening:
“launchPackager.command” can’t be opened because (null) is not allowed to open documents in Terminal.
The simulator just shows a white screen and can't be interacted with.
What I've tried:
manually opening node_modules/react-native/scripts/launchPackager.command
opens Metro terminal but is not connected to the app
warn No apps connected. Sending "reload" to all React Native apps failed. Make sure your app is running in the simulator or on a phone connected via USB.
info Reloading app...
giving Terminal full disk access (no change)
This happened to me after upgrading to macOS Ventura. I happen to use iTerm as my main terminal, not the built-in Terminal.app so the following fix only applies to that scenario:
Set iTerm as the Default Handler for *.command Files
Open node_modules/react-native/scripts/ in Finder (open node_modules/react-native/scripts/)
Right-Click on launchPackager.command and click Open With then choose Other...
In your Applications directory, select iTerm and click Always Open With
After this, you might need to run npm run ios again from this terminal window. However, from now on, Metro will open in a new iTerm tab instead of trying to open the command in a new Terminal window.
For me, this was the desired behaviour and it removed this warning.
Note In future, any *.command files will now open with iTerm instead of Terminal.
I encountered the same problem as you, I installed another terminal (iTerm2), then randomly found a .command file, and in the display introduction, changed the default opening method to iTerm2enter image description here
I'm having this issue after upgrading my MacOS to Ventura 13.1.
If you don't want to use iTerm as the accepted answer suggest, the workaround I found was to look for the launchPackager.command file inside node-modules/react-native/scripts/ and open this file manually every time you run your app for the first time (specifically when the error pop-up appears). This will open the terminal with metro running already.
I know that manually processes are not the best, but I don't want to use iTerm :)
Using Intel version of apps (Webstorm, Android Studio, other IDE etc...) fixed my problems. I encountered the same issue and thanks to Intel version of Webstorm and Xcode on Rosetta I can able to pod install and other operations.
Note: I'm using Intel version of Android Studio, WebStorm. Also Xcode uses Rosetta 2. No problem detected and everything works perfect. I can able to develop React-Native & Native Android & iOS and Flutter apps without problem. Before that I was using Silicon version of WebStorm and almost no function worked.
Config: MacBook Air, macOS Ventura 13.2 on Apple M1 processor.
For Most of the case you just have to delete node_modules and install modules again (npm i). This happens when project was copied from old mac which had node_modules folder created by the old user, or if the system thinks so
This happened to me after i configured my terminal for the look and feel - but with iterm2, oh my zsh, and powerlevel10k

Expo: Change default IOS simulator

I am new in expo and react-native
Whenever i run the app from IOS simulator (inside expo) it always boots up the IphoneX. If i need to change the simulator,I have to open it through Xcode, is there any way we can change the default simulator ?
expo included an option in recent commits regarding this issue.
now you can tap shift+i on terminal which expo server is running.It will list all simulators and you need to select your choice.
https://github.com/expo/expo-cli/pull/2541
Currently there is no way of changing the simulator from Expo. Expo just uses the last opened simulator in Xcode.
If that doesn't work, try this (updated here from my comment) :
When the simulator is open click on Hardware>Device> Select the other iphone.
Now both will be open. Next exit the simulator from the dock.
Now try and open your project in the ios simulator from expo. It should open in the Simulator you selected from the hardware menu.
This worked for me on Feb 2021
on Mac OS with Big sur, expo v4.1.6
Clean your EXPO cache with expo start -c (on your project location)
In the expo terminal press shift + i (see screenshot below)
Then press shift + i and you should be able to select the Simulator by pressing enter on the one you need (see screnshot)
lastly Just wanted to share all the available options if you just press i in the metro terminal window.
It is possible, but you can't target it from the command line.
Expo will just target the last opened simulator.
Click on Hardware > Device and choose the device you desire
You now have two simulators open, make sure the one you want is active.
Now quit the simulator app with Command + Q
Now in your command line, when running the expo server, just click i
The simulator will open with your targeted device.
(As of December 3, 2020)
Open Simulator
Click on File ... (in the top-left menu bar)
Click on Open Device ... (in the drop down list)
Select your desired device and let it launch completely
Quit Simulator ... (command + Q)
Done
Running your app on iOS Simulator will automatically launch to this desired device now =)
Change the open iOS simulator device(s), and Expo will use it.
Expo directs its output to the open iOS simulator, so this must be done in the simulator itself rather than in Expo. It is simple to do.
You can direct expo output to different devices. Here's how. BTW, other approaches described here didn't work when I tried them.
Open a second simulator in iOS Simulator by:
1) select eg Simulator->Hardware->Device->iOS12.1->iPhone 8
2) Select the simulator that you don't want to use (eg the current default as of writing, iPhone XR). Press Command-W to close the simulator window, leaving the iPhone 8 simulator still running.
3) In Expo, deploy the code to simulator as usual, either using the i at the command line, or selecting 'run on iOS Simulator' from the browser version of Expo.
4) It is possible to get expo to display to more than one simulator that is running at once (eg to test rendering on multiple screen sizes). Once you get expo running on one device (steps 1-3), you can repeat on an additional device (or presumably more). Expo will then be running on multiple simulators. They will simultaneously display the output. When I change my code, it immediately updates to multiple simulators/screen sizes without requiring any additional steps. Haven't re-tested exactly the order of steps to do this most easily, but it's working.
Hope this works for you!
You just need to open the desirable simulator through Xcode, and then just run:
npm run ios
from your project directory or a similar command to start your app
I believe that yarn passes unrecognized arguments through to react-native run-ios, so you should be able to pass --simulator="foo" as described here: https://facebook.github.io/react-native/docs/running-on-simulator-ios.
I know the exact answer
Once you open the Simulator from the Expo, go to Help menu and Search for "iphone11", "iphoneX" ....
Then you should be fine
Go to /Users/username/.expo/ios-simulator-app-cache/ and remove all files in there.
Run the ios simulator you want and run your expo project.
Restarting the computer was the only thing that worked for me. Without it pressing "Shift+i" had no effect. Neither Expo client would be installed on new simulator instance.
This was on macOS and M1 MacBook Pro for me.
Just launch simulator on which you want to run app and then run command i.e. "yarn run ios" or "npm run ios" to run on simulator. App will run on both simulator.
If it doesn't work then quit all simulator and then run the command i.e. "yarn run ios" or "npm run ios", then app automatically run on simulator which was latter launched.
Hope this may help you!

App crashing on launch with instrumentation w/ calabash-ios

UPDATE: This was fixed by resetting the phone's settings. General -> Reset -> "Reset all settings".
We are having on issue on iPhones 6 and 6+ when launching our IBM MobileFirst-based app.
When calabash instrumentation is linked and I manually launch the app, the splash screen will come up and the app will quit almost instantly.
Double tapping home shows me the app running in the background, but Xcode does not recognize it as a running process. After force-closing the app and re-launching, it will usually do the same thing, but sometimes it comes up.
I've noticed our automation is sometimes stuck in an infinite loop of launching and crashing. This only happens on the instrumented app.
The crash log throws EXC_BAD_ACCESS. I found a thread on the google group from a few years back that talks about linker flags, but I don't have any of the weaker flags mentioned there.
Steps to reproduce:
*App must be instrumented with the calabash automation framework (calabash-ios setup must have been executed in same directory as xcodeproj file.)
Build application and deploy native iOS project to XCode via eclipse.
Build the -cal target with the "Run" configuration.
Kill the debugger/application.
Manually launch the app on the device. The app will successfully launch maybe 15%-20% of the time, otherwise it will just quit.
Using calabash-cucumber version 0.14.3.
Linker flags:
$(inherited)
-force_load
"$(SRCROOT)/calabash.framework/calabash"
-lstdc++
It appears $(inherited) contains -ObjC for Debug.
Xcode installed at: /Applications/Xcode.app/Contents/Developer
Xcode version: 6.1.1
Xcode build: 6A2008a
The user is unresponsive, the fix was:
Actually I just found the fix to this. What I had to do is reset the
phone's settings in Settings -> General -> Reset -> "Reset All
Settings" (the first option). Have not seen the behavior since.
I had exact same problem, tried so many different ways and finally found how to fix it - I changed project directory, pulled from Git, then bundle install, pod install and build the app with calabash target as usual
Xcode 7.3.1, calabash-cucumber (0.19.1)

How to run iOS .app package within Simulator?

Dev guys from other company, sent me iOS app package that is build with Xcode, but I don't have its Xcode project, just built app package file. How to run that on simulator or on iphone?
UDPATE: I'v tried Simulator launcher but the solution is not working when using Xcode 4.2.1.
UPDATE2: Also tried to use this solution but with no luck (getting black simulator screen and errors shown in terminal after launch). IMHO these problems might be related to iOS 5
UPDATE3: Also, unsuccessfully, tried to use this solution
normally you should be able to install it with itunes, a detailed step-by step guide can be found here: http://www.wikihow.com/Install-Ad-hoc-iPhone-OS-Apps
If it is built for device, you can install it to your device using iTunes or Xcode Organizer. However, you cannot run it on any device. They should also give you a provisioning profile for letting you install that app on your device.
Found the solution. I'v asked the guys to send me "ipa" package instead of raw .app package. Then added it to my iPhone device.

Debugging iOS app built from commandline

I am building an app for iOS via commandline but I am having problems debugging it. Had I built using XCode, it would have let me "build and debug" on device without problems. But now, I don't know how to launch it on device using gdb and step through it. If I try to "add a custom target/executable" to a blank XCode project and then launch it, XCode complains about not finding the executable. Same thing happens if I install the app on device manually and try to attach to it using gdb within XCode. Any pointers on how to go about debugging this app? Changing the build process to use XCode is not an option.
This site gives a nice tutorial on how to manually set up a remote debugging session on an iOS device. The process boils down to creating a remote debugging server on the device and attaching to it with a local GDB instance.