Can I tell if my app is running under Apple Test Flight Beta - testflight

In the prior test flight system we pushed AdHoc builds which we used a compiler constant to identify to turn on/off features for our beta testers. Now with Apple's Beta Test Flight System we have to build for the App Store, i.e. not AdHoc, which is fine as if it tests good we can use the same build for a production review.
Is there any way from within iOS to detect that the build is a Test Flight delivered build so we know "this is beta" and do the same as before with the AdHoc compiler constant?
Thank you

There is one way that I use it for my projects.
In Xcode, go to the the project settings (project, not target) and add "beta" configuration to the list:
Then you need to create new scheme that will run project in "beta" configuration. To create scheme go here:
Name this scheme whatever you want. The you should edit settings for this scheme. To do this, tap here:
Select Archive tab where you can select Build configuration
Then you need to add a key Config with value $(CONFIGURATION) the projects info property list like this:
Then its just the matter what you need in code to do something specific to beta build:
let config = Bundle.main.object(forInfoDictionaryKey: "Config") as! String
if config == "Debug" {
// app running in debug configuration
}
else if config == "Release" {
// app running in release configuration
}
else if config == "Beta" {
// app running in beta configuration
}

Here's a simple and useful function you can use in any app to easily check if the running app was installed by TestFlight:
func isTestFlight() -> Bool {
guard let path = Bundle.main.appStoreReceiptURL?.path else {
return false
}
return path.contains("sandboxReceipt")
}
No need to create special build configs, schemes, etc.

Related

Xcode XCUItest LaunchTests - how do they work

If I create a new Xcode project with Xcode 14 with checked 'Include Tests' checkbox it creates 2 files in the UITests folder:
I am interested in the second one: the [Project]LaunchTests.swift file.
There is this automatically generated code:
func testLaunch() throws {
let app = XCUIApplication()
app.launch()
// Insert steps here to perform after app launch but before taking a screenshot,
// such as logging into a test account or navigating somewhere in the app
let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.name = "Launch Screen"
attachment.lifetime = .keepAlways
add(attachment)
}
If I run this test from the diamond in the code, it runs 4 tests that I can view in the report navigator:
Xcode runs these 4 tests, but I didn't define them anywhere.
Question: where can I find the definition of that tests? Is this kind of an internal testplan which is associated with the LaunchTests file? Where can I find more information about this? It looks like there is a way to run tests with changing light/dark mode and changing orientation without writing a line of code.
Thanks in advance.
If you don't want the four variants of the test to run, then do not (as the template does) return the runsForEachTargetApplicationUIConfiguration value for this test class as true.
As the documentation tells you, when this is true, the test runner consults your actual app target to see what variants it has (light and dark mode, orientations, language localizations).

Nativescript build to device

Whenever I try to build to a device I'm getting this error:
Error Domain=IDEProvisioningErrorDomain Code=8 "binding.node has
conflicting provisioning settings."
UserInfo={NSLocalizedDescription=binding.node has conflicting
provisioning settings., NSLocalizedRecoverySuggestion=binding.node is
automatically signed for distribution, but a conflicting code signing
identity iPhone Developer has been manually specified. Remove the
"signingCertificate" entry from your Export Options property list, or
switch to manual signing by setting "signingStyle" to "Manual.}
I can build to a simulator just fine. What would this be?
My .xconfig:
// You can add custom settings here
// for example you can uncomment the following line to force
distribution code signing
CODE_SIGN_IDENTITY = iPhone Distribution
// To build for device with XCode 8 you need to specify your
development team.
DEVELOPMENT_TEAM = <xxxxxxxx>;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage;
TARGETED_DEVICE_FAMILY = 1,2;
As I've already answered in the Github issue, most probably you have a dev dependency which cannot be signed in the dependencies list of your package.json and you need to follow the steps described in this thread in order to resolve it.

With Xcode UI tests, is it possible to test application in external project/repository?

I am searching for a way to separate the UI tests from the original repository where the main app stays. Is it possible to have the UI test code in another repository, "reference" the main app in some way, and test it?
Starting in Xcode 9, this is possible as long as you're willing to give up a few features. After creating a UI test bundle, you can go to the target settings to specify that it has no target application. (You may also be able to create a UI test bundle without specifying one to begin with.) After you've removed the target application, rather than using the default initializer for XCUIApplication, you can use the initializer that accepts a bundle identifier.
Your tests will end up looking something like the following:
var app: XCUIApplication {
return XCUIApplication(bundleIdentifier: "com.yourdomain.product")
}
func setup() {
app.launch()
}
func test() {
app.navigationBar.buttons["Add"].tap()
}
If you go this route, you will lose the ability to use a few features. Namely:
You won't be able to use Xcode's built in test recorder. The record button is disabled unless you have a target application configured. That being said, you could create an empty app in your project and just switch to the application you'd like to record instead. (That being said, I haven't found Xcode's record feature to be very useful, even for single project apps.)
Xcode won't automatically install your application for you. That usually isn't an issue since is located in a different repository (and sometimes isn't even an Xcode project), so you'll just need to install it before starting your tests. The iOS simulator allows you to drag and drop a .app file, so installing the app is easy enough.

Not able to run Test Automation using Xamarin.UITest from Visual Studio on my local emulator

We are doing investigation for the Test Clouds for our Android and IOS apps. I made a test snippet which installs and launches the android app. And then takes the screenshot. I am using Visual Studio to write the tests. And Visual Studio emulator to run the android app and xamarin test. Xamarin test is able to install the app, but then throws the error. Code and Errors can be found below.
Other observations:
I am using Test account for my investigations which is free for 30 days.
But I don't see my computer added in the link: https://store.xamarin.com/account/my/subscription/computers. While, I have logged in from Visual Studio in my PC.
Due to this I can't copy the license file too. Can that be the reason? If yes, what is the best way to investigate this without getting full subscription.
Code:
[TestFixture]
public class Tests
{
AndroidApp app;
[SetUp]
public void BeforeEachTest()
{
// TODO: If the Android app being tested is included in the solution then open
// the Unit Tests window, right click Test Apps, select Add App Project
// and select the app projects that should be tested.
app = ConfigureApp
.Android
// TODO: Update this path to point to your Android app and uncomment the
// code if the app is not included in the solution.
.ApkFile(#"C:\MobileOnly\SampleProjects\AndroidSampleProjects\InfraTest\app\build\outputs\apk\app-debug.apk")
// .InstalledApp("com.microsoft.mobile.infratest")
.StartApp(Xamarin.UITest.Configuration.AppDataMode.Clear);
}
[Test]
public void AppLaunches()
{
app.Screenshot("First screen.");
}
}
Error:
Test Name: AppLaunches
Test FullName: XamarinUITest.Tests.AppLaunches
Test Source: : line 0
Test Outcome: Failed
Test Duration: 0:00:11.233
Result StackTrace:
at Xamarin.UITest.Shared.Processes.ProcessRunner.Run(String path, String arguments)
at Xamarin.UITest.Shared.Android.Commands.CommandAdbInstallPackage.Execute(IProcessRunner processRunner, IAndroidSdkTools androidSdkTools)
at Xamarin.UITest.Shared.Android.LocalAndroidAppLifeCycle.InstallApps(ApkFile[] apkFiles)
at Xamarin.UITest.Shared.Android.LocalAndroidAppLifeCycle.EnsureInstalled(ApkFile appApkFile, ApkFile testServerApkFile)
at Xamarin.UITest.Android.AndroidApp..ctor(IAndroidAppConfiguration appConfiguration)
at Xamarin.UITest.Configuration.AndroidAppConfigurator.StartApp(AppDataMode appDataMode)
at XamarinUITest.Tests.BeforeEachTest() in C:\MobileOnly\SampleProjects\AndroidSampleProjects\XamarinUITest\XamarinUITest\Tests.cs:line 22
Result Message:
SetUp : System.Exception : Failed to execute: C:\NugetCache\androidsdk.23.0.4\platform-tools\adb.exe -s 169.254.138.177:5555 install "C:\Users\gunjansa\AppData\Local\Temp\uitest\a-6EAAB1A4CD21F05DB755FBC781EAD620D4ADACBC\final-D9BA1DA5963F9B7853DABC6DEC56BFF2F4740ADE.apk" - exit code: -1073740940
WARNING: linker: libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
pkg: /data/local/tmp/final-D9BA1DA5963F9B7853DABC6DEC56BFF2F4740ADE.apk
Update the Xamarin.UITest NuGet and try
public void BeforeEachTest()
{
// TODO: If the Android app being tested is included in the solution then open
// the Unit Tests window, right click Test Apps, select Add App Project
// and select the app projects that should be tested.
app = ConfigureApp
.Android
.StartApp();
}
I would do below actions
Restore your UITest project packages
Make sure that you dont see any app named with the package id though the app is completely uninstalled from the device. Often this is the case where uitests uninstalls the existing version of the app and leaves the folders behind causing this issue.
Hope this resolves your issue.

Cocoa Unit Testing - App is launching before tests [duplicate]

When I run my tests in XCode 5, the main window of my OS X app appears on the screen for a couple of seconds while running the tests. Why? Even if I uncomment all my tests it still opens my main window.
You are running application test, not logic test. This means an instance of your app will be started and then run the unit tests. This allow you to perform some integration test that require your app is running.
Here is the guide to setup application test and logic test.
If you want to change it to logic test (so it run faster and don't need to start your app first):
go to build settings for your unit test target
search Bundle
remove Bundle Loader and Test Host
Thats right, you have to delete the "Bundle Loader" and "Test Host" from your build settings.
But you have to add the necessary implementation files to your unit test target. The necessary files are what you want to use in your unit test cases. You need to do this because in logic tests XCode wont compile the whole application. So some of your files will be missing.
This is en error message if you have left out a file:
Undefined symbols for architecture i386:
"_OBJC_CLASS_$_Module", referenced from:
objc-class-ref in Lobic Network.o
objc-class-ref in Logic_Unit.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You can add the missing files by selecting the implementation file and bringing up the file inspector. There will be a section named "Target Membership" and there you can set the files target membership to your unit test also.
With XCTest, application files DO NOT need to be included within XCTest targets. The XCTest bundle is linked against the application which makes those files available during runtime.
To make this work, ensure the compiler option "Symbols hidden by default" is set to NO Within the Application target.
Here is a blog post with screenshots for clarity:
http://zmcartor.github.io/code/2014/02/24/slim-xctest-targets
The advantage of this approach is test target builds much much faster.
In XCode 7, removing Host Application does not work for me. Indeed I use the following to avoid app runs.
Setup Test Scheme Arguments
in main.m
static bool isRunningTests()
{
NSDictionary* environment = [[NSProcessInfo processInfo] environment];
NSString* testEnabled = environment[#"TEST_ENABLED"];
return [testEnabled isEqualToString:#"YES"];
}
modify main()
int main(int argc, char * argv[]) {
#autoreleasepool {
if (isRunningTests()) {
return UIApplicationMain(argc, argv, nil, nil);
} else {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
}
If the tests are for code that can run on desktop and mobile, you can run them without a simulator or hosting them within your app.
The trouble is that you cannot use the scheme chooser for your normal target (desktop or iOS) to run the test.
The following worked for me in Xcode6.
File > New Target...
Select Cocoa Testing Bundle from the OS X category.
Take care to select None from the target drop-down.
Click Finish. Add the relevant files to the new target as described above.
Now create a scheme to run the test.
Click the schemes chooser top-right and choose New Scheme..., click the drop-down and navigate down the list to the new target. Now you can choose the scheme from the schemes chooser, and use ⌘U to run the tests.
I just wasted a morning on this.
Project was created in XCode 4 and used SenTesting.
Tried migrating tests on XCode 5/XCTTest
Had same issue - app ran in simulator and test never started
after trying everything (change from app to logic tests, change to XCTest, remove SenTesting)
gave up created a clean XCode 5 project.
Added all my files in and tests ran ok.
May still have issues with Storyboard as these were built with XCode 4.
Drastic but it works so keep it as last resort.
On XCode5, the app does start. This answer shows how to change its delegate when running unit tests so that it exits right away: https://stackoverflow.com/a/20588035/239408

Resources