Unit testing of Realm in Xamarin iOS - c#

Xamarin iOS native app. I have to write unit test for Realm api. It is the layer with ability to filter data. It can contain complicated Linq queries, so testing is necessary.
For instance, method:
Task<List<T>> Get(int count, int type, int? id);
Creating NUnit test I need to get Realm object:
var realm = Realm.GetInstance(new InMemoryConfiguration("test"));
but getting an exception:
System.TypeInitializationException : The type initializer for 'Realms.SharedRealmHandle' threw an exception.
----> System.DllNotFoundException : realm-wrappers assembly:<unknown assembly> type:<unknown type> member:(null)
at Realms.InMemoryConfiguration.CreateRealm (Realms.Schema.RealmSchema schema) [0x0003e] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Configurations\InMemoryConfiguration.cs:62
at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config, Realms.Schema.RealmSchema schema) [0x0003c] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Realm.cs:136
at Realms.Realm.GetInstance (Realms.RealmConfigurationBase config) [0x00000] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Realm.cs:81
at UnitTestREALM.TransactionsRealmApiTest.RealmApi () [0x00001] in /Users/user/Projects/myApp/UnitTestREALM/TransactionsRealmApiTest.cs:26
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395
--DllNotFoundException
at (wrapper managed-to-native) Realms.SynchronizationContextEventLoopSignal.install_eventloop_callbacks(Realms.SynchronizationContextEventLoopSignal/get_eventloop,Realms.SynchronizationContextEventLoopSignal/post_on_event_loop,Realms.SynchronizationContextEventLoopSignal/release_eventloop)
at Realms.SynchronizationContextEventLoopSignal.Install () [0x0003b] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Native\SynchronizationContextEventLoopSignal.cs:122
at Realms.NativeCommon.Initialize () [0x00112] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Native\NativeCommon.cs:91
at Realms.SharedRealmHandle..cctor () [0x00000] in C:\jenkins\workspace\realm_realm-dotnet_PR\Realm\Realm\Handles\SharedRealmHandle.cs:128
So, main point that I can't create Realm instance.
Is launched iphone simulator necessary to work with Realm?
Are there some possibility to create unit tests for Realm?
Or should it be some kind of Auto tests?

As I found, solution is iOS Unit Test App (Solution -> Add -> New Project -> iOS -> Tests -> Unit Test App).
There are few disadvantages, but it is possible to test Realm. The next challenge is to run it and get result with TeamCity.

Related

Cannot debug C# tests with visual studio code on linux

I have a c# project which I want to unit test. I'm trying to simply debug a unit test in VSCode running on linux, but I get the following error:
Failed to start debugger: "System.ArgumentException: '' is not a valid version string.
Parameter name: value
at NuGet.Versioning.SemanticVersion.Parse (System.String value) [0x0001c] in <0fb3faba525e4e72954446a9b4e57f5b>:0
at OmniSharp.Services.DotNetCliService.GetVersion (System.String workingDirectory) [0x00011] in <7c5a61c964114ca68a62c9da132f5af2>:0
at OmniSharp.DotNetTest.TestManager.Create (Microsoft.CodeAnalysis.Project project, OmniSharp.Services.IDotNetCliService dotNetCli, OmniSharp.Eventing.IEventEmitter eventEmitter, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory) [0x0000c] in <f766edfe7c324a8d817379aedddb5887>:0
at OmniSharp.DotNetTest.TestManager.Start (Microsoft.CodeAnalysis.Project project, OmniSharp.Services.IDotNetCliService dotNetCli, OmniSharp.Eventing.IEventEmitter eventEmitter, Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, System.Boolean noBuild) [0x00000] in <f766edfe7c324a8d817379aedddb5887>:0
at OmniSharp.DotNetTest.Services.BaseTestService.CreateTestManager (System.String fileName, System.Boolean noBuild) [0x00011] in <f766edfe7c324a8d817379aedddb5887>:0
at OmniSharp.DotNetTest.Services.DebugTestService.Handle (OmniSharp.DotNetTest.Models.DebugTestGetStartInfoRequest request) [0x0000d] in <f766edfe7c324a8d817379aedddb5887>:0
at OmniSharp.Endpoint.Exports.RequestHandlerExportHandler`2[TRequest,TResponse].Handle (TRequest request) [0x00000] in <7c5a61c964114ca68a62c9da132f5af2>:0
at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].GetFirstNotEmptyResponseFromHandlers (OmniSharp.Endpoint.Exports.ExportHandler`2[TRequest,TResponse][] handlers, TRequest request) [0x00022] in <7c5a61c964114ca68a62c9da132f5af2>:0
at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].HandleRequestForLanguage (System.String language, TRequest request, OmniSharp.Protocol.RequestPacket packet) [0x00163] in <7c5a61c964114ca68a62c9da132f5af2>:0
at OmniSharp.Endpoint.EndpointHandler`2[TRequest,TResponse].Process (OmniSharp.Protocol.RequestPacket packet, OmniSharp.Endpoint.LanguageModel model, Newtonsoft.Json.Linq.JToken requestObject) [0x0024b] in <7c5a61c964114ca68a62c9da132f5af2>:0
at OmniSharp.Stdio.Host.HandleRequest (System.String json, Microsoft.Extensions.Logging.ILogger logger) [0x000f3] in <a50105da3f9c45b299f1e289aba046fa>:0 "
It is an empty test project with the auto generated test method. It is a mstest project but it also throws the same error in an xunit test project.
Does anyone know what I'm missing?
I had a similar problem (VSCode, Linux, not a valid version string, though mine was null, not an empty string, mstest). It turned out that simply restarting VSCode resolved the issue, and I could run the debugger.

System.DllNotFoundException: libpcsclite.so.1 assembly:<unknown assembly> type:<unknown type> member:(null)

Researched this issue many times but didn't found solution of it. Working with xamarin forms version 5.0.0.2012, on win 10 os (saw many solutions for mac or linux but didn't found any for windows), using PCSC library version 5.0.0. Trying to invoke context.Establish method while debugging on Android 8.0:
public SimpleReader(ISCardContext context, bool releaseContextOnDispose = false)
{
if (context == null)
{
context = (ISCardContext) new SCardContext();
context.Establish(SCardScope.System);
releaseContextOnDispose = true;
}
this._context = context;
this._reader = (ISCardReader) new SCardReader(context);
this._releaseContextOnDispose = releaseContextOnDispose;
this._disconnectReaderOnDispose = true;
}
When, exception occur with message below:
System.DllNotFoundException: libpcsclite.so.1 assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) PCSC.Interop.Linux.LinuxNativeMethods.SCardEstablishContext(intptr,intptr,intptr,intptr&)
at PCSC.Interop.Linux.PCSCliteLinux.EstablishContext (PCSC.SCardScope dwScope, System.IntPtr pvReserved1, System.IntPtr pvReserved2, System.IntPtr& phContext) [0x00006] in C:\Users\danm\src\pcsc-sharp\src\PCSC\Interop\Linux\PCSCliteLinux.cs:39
at PCSC.SCardContext.Establish (PCSC.SCardScope scope) [0x00020] in C:\Users\danm\src\pcsc-sharp\src\PCSC\SCardContext.cs:81
at App1xx.Services.SimpleReader.SimpleReader..ctor (PCSC.ISCardContext context, System.Boolean releaseContextOnDispose) [0x00023] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\SimpleReaderLib\SimpleReader.cs:59
at App1xx.Services.SimpleReader.SimpleReader..ctor () [0x00000] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\SimpleReaderLib\SimpleReader.cs:70
at App1xx.Services.UaIdRLib.IdCardReader.connect () [0x00002] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\UaIdRLib\IdCardReader.cs:371
at App1xx.Views.AboutPage.OnButtonClicked (System.Object sender, System.EventArgs args) [0x0000f] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Views\AboutPage.xaml.cs:22
at Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:187
at Xamarin.Forms.ButtonElement.ElementClicked (Xamarin.Forms.VisualElement visualElement, Xamarin.Forms.Internals.IButtonElement ButtonElementManager) [0x0001f] in D:\a\1\s\Xamarin.Forms.Core\ButtonElement.cs:61
at Xamarin.Forms.Button.SendClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:173
at Xamarin.Forms.Platform.Android.ButtonElementManager.OnClick (Xamarin.Forms.VisualElement element, Xamarin.Forms.IButtonController buttonController, Android.Views.View v) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\ButtonElementManager.cs:25
at Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer.Android.Views.View.IOnClickListener.OnClick (Android.Views.View v) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ButtonRenderer.cs:72
at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00010] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.Views.View.cs:2252
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.68(intptr,intptr,intptr)
Does anyone faced with this issue?
The PCSC library does not appear to explicitly support Android. In my experience, nugets that work with Xamarin.Android have explicit dependencies set for the platform, but this one does not.
The library tries to use P/Invoke wrappers around native code. You can see that there are implementations for a number of operating systems here, but I don't see any references to Android. The stack trace shows that the code is deciding to use the Linux wrapper, which makes sense. It's looking for the libpcsclite.so.1 native "C/C++" library, but it's not finding it. That library has a home page that does not reference Android.
The PCSC nuget docs state:
pcsc-sharp does not contain any device drivers. A PC/SC compliant
reader + driver is mandatory.
That's the libpcsclite.so.1 . Either your Android device doesn't provide it, or if it does, it's not in a location that your Android app can find it. My Android device (running Android 9) does not have that library in any of /system/*lib* directories, which means that at least for my device someone would need to compile that native library for the CPU (usually arm64) for the device. If you can either compile the native code yourself or find someone who has, AND the native code supports the reader on your Android device, then you could get the whole thing to work.
I don't have any experience with PCSC myself - just some experience with Xamarin and native libraries.

DllNotFoundException: TMPro_Plugin, working with TextMesh Pro on linux

I am trying to run font asset creator of TextMesh Pro 1.2.4 on Unity 2018.1.6f1 on Fedora 27. I've got the following errors:
I've heard that TextMesh hasn't been supported on Linux yet. Is it still true?
DllNotFoundException: TMPro_Plugin
TMPro.EditorUtilities.TMPro_FontAssetCreatorWindow.DrawControls () (at
/root/.config/unity3d/cache/packages/packages.unity.com/com.unity.textmeshpro#1.2.4/Scripts/Editor/TMPro_FontAssetCreatorWindow.cs:704)
TMPro.EditorUtilities.TMPro_FontAssetCreatorWindow.OnGUI () (at
/root/.config/unity3d/cache/packages/packages.unity.com/com.unity.textmeshpro#1.2.4/Scripts/Editor/TMPro_FontAssetCreatorWindow.cs:266)
System.Reflection.MonoMethod.Invoke (System.Object obj,
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder
binder, System.Object[] parameters, System.Globalization.CultureInfo
culture) (at :0) Rethrow as
TargetInvocationException: Exception has been thrown by the target of
an invocation. System.Reflection.MonoMethod.Invoke (System.Object obj,
System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder
binder, System.Object[] parameters, System.Globalization.CultureInfo
culture) (at :0)
System.Reflection.MethodBase.Invoke (System.Object obj,
System.Object[] parameters) (at :0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object
obj) (at
/home/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:291)
UnityEditor.HostView.Invoke (System.String methodName) (at
/home/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:284)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition) (at
/home/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:257)
UnityEditor.DockArea.OldOnGUI () (at
/home/builduser/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:386)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI
(UnityEngine.Event evt) (at
/home/builduser/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:234)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleIMGUIEvent
(UnityEngine.Event e) (at
/home/builduser/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:372)
UnityEngine.Experimental.UIElements.IMGUIContainer.HandleEvent
(UnityEngine.Experimental.UIElements.EventBase evt) (at
/home/builduser/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:356)
UnityEngine.Experimental.UIElements.EventDispatcher.DispatchEvent
(UnityEngine.Experimental.UIElements.EventBase evt,
UnityEngine.Experimental.UIElements.IPanel panel) (at
/home/builduser/buildslave/unity/build/Modules/UIElements/EventDispatcher.cs:215)
UnityEngine.Experimental.UIElements.UIElementsUtility.DoDispatch
(UnityEngine.Experimental.UIElements.BaseVisualElementPanel panel) (at
/home/builduser/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:224)
UnityEngine.Experimental.UIElements.UIElementsUtility.ProcessEvent
(System.Int32 instanceID, System.IntPtr nativeEventPtr) (at
/home/builduser/buildslave/unity/build/Modules/UIElements/UIElementsUtility.cs:77)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID,
System.IntPtr nativeEventPtr) (at
/home/builduser/buildslave/unity/build/Modules/IMGUI/GUIUtility.cs:184)
llNotFoundException: TMPro_Plugin
TMPro.EditorUtilities.TMPro_FontAssetCreatorWindow.OnDisable () (at
/root/.config/unity3d/cache/packages/packages.unity.com/com.unity.textmeshpro#1.2.4/Scripts/Editor/TMPro_FontAssetCreatorWindow.cs:204)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
The native side of the code required to generate text is not available on Linux yet. The plugin itself should work during run-time in a build but its Editor tool is not supported on Linux. The Editor tool is only supported on Windows and Mac.
The original reason for the lack of support is because only few people use Linux when enveloping games with Unity. Also Unity Editor itself does not support Linux officially. Whatever support they have for it is still in experimental mode and there are many issues that makes it not worth using at this point.
Since TextMesh Pro is now bought by Unity, it's very likely that Linux will be supported. You should wait until Unity finally integrate it with Unity and maybe they will add support for Linux. At this moment, I think you should file for a bug report to remind Unity that this issue is still there then just use the Text component until they fix it. If you still want to use TextMesh Pro, a workaround is to use VMware Workstation to run Windows or MacOS on your Linux then you can use them to create the Text Assets and export and import them as Packages in your Linux project.

How to change architecture of .ipa or .app from arm64 to i386 without source code

I'm writing mobile autotests using C#, Xamarin 6.1.3, iOS 10.2, iPhone 6s Plus, Xcode 8.2, OS X El Capitan 10.11.6.
I'm trying to launch tests on simulator using the following command:
IApp iApp = ConfigureApp.iOS.AppBundle(path_to_app/Application.app).StartApp();
I've got the following error:
Calabash.XDB.Core.Exceptions.DeviceAgentException : Failed to install app /Volumes/Win7 Ultim/Framework/new2/Payload/Atom.app
ExitCode: 5
-a,--app-bundle <path/to/app-bundle.app> Path .app bundle (for .ipas, unzip and look inside of 'Payload')
-c,--codesign-identity <codesign-identity> [OPTIONAL] Identity used to codesign app bundle [device only] DEFAULT=
-d,--device-id <device-identifier> iOS Simulator GUIDs
-u,--update-app <true-or-false> [OPTIONAL] When true, will reinstall the app if the device contains an older version than the bundle specified DEFAULT=1
install
Error installing org.gamatech.Movie-Friends to 9E44D0FE-A3F9-4FC1-8635- 20FB8AD20BA4: Error Domain=com.facebook.FBSimulatorControl Code=0 "Simulator does not support any of the architectures ([arm, arm64]) of the executable at /Volumes/Win7 Ultim/Framework/new2/Payload/Atom.app/Atom. Simulator Archs ([x86_64, i386])" UserInfo={NSLocalizedDescription=Simulator does not support any of the architectures ([arm, arm64]) of the executable at /Volumes/Win7 Ultim/Framework/new2/Payload/Atom.app/Atom. Simulator Archs ([x86_64, i386])}
false
at Xamarin.UITest.iOS.iOSAppLauncher.LaunchAppLocal (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Http.HttpClient httpClient, System.Boolean clearAppData) [0x0020a] in <e747267e258a4a668973c7ca7e9014a8>:0
at Xamarin.UITest.iOS.iOSAppLauncher.LaunchApp (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration, Xamarin.UITest.Shared.Http.HttpClient httpClient, Xamarin.UITest.TestCloud.TestCloudiOSAppConfiguration testCloudAppConfiguration, Xamarin.UITest.Shared.Http.HttpClient testCloudWsClient, Xamarin.UITest.Shared.Http.HttpClient xtcServicesClient, System.Boolean testCloudUseDeviceAgent) [0x0007a] in <e747267e258a4a668973c7ca7e9014a8>:0
at Xamarin.UITest.iOS.iOSApp..ctor (Xamarin.UITest.Configuration.IiOSAppConfiguration appConfiguration) [0x00302] in <e747267e258a4a668973c7ca7e9014a8>:0
at Xamarin.UITest.Configuration.iOSAppConfigurator.StartApp (Xamarin.UITest.Configuration.AppDataMode appDataMode) [0x00017] in <e747267e258a4a668973c7ca7e9014a8>:0
at Xamarin.Application.Initialize () [0x00026] in /Volumes/Win7 Ultim/Framework/Xamarin/Application.cs:44
at Xamarin.Application..ctor () [0x00011] in /Volumes/Win7 Ultim/Framework/Xamarin/Application.cs:22
at Xamarin.Application.GetInstance () [0x0000c] in /Volumes/Win7 Ultim/Framework/Xamarin/Application.cs:62
at Xamarin.BaseTest.InitBeforeTest () [0x0000b] in /Volumes/Win7 Ultim/Framework/Xamarin/BaseTest.cs:18
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00038] in /private/tmp/source-mono-4.6.0/bockbuild-mono-4.6.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Reflection/MonoMethod.cs:305
Ios simulator supports only i386 architecture, as I know it cannot be changed.
Is it possible to change architecture of application, if I don't have source code, just .ipa and .app files?
It is not possible to change the supported architecture of an .ipa or an .app without the source code.

Timed out waiting for result of ClearAppData2 when running Xamarin UI Tests for Android

I've created automatic Android and iOS UI-Tests for my Xamarin application with the Xamarin UITest framework. When running the tests locally, they work fine, but when running them on the Bitrise CI, the iOS tests run fine, but the Android UI Tests keep failing with the following exception:
StartFirstActivity_WaitForActivity_ExpectButtonToHaveText
SetUp : System.Exception : Timed out waiting for result of ClearAppData2
Stack trace:
at Xamarin.UITest.Shared.Android.Commands.CommandAdbClearAppData.Execute (IProcessRunner processRunner, IAndroidSdkTools androidSdkTools) <0x38b3e90 + 0x0064b> in <filename unknown>:0
at Xamarin.UITest.Shared.Execution.Executor.Execute[TDep1,TDep2] (ICommand2 command) <0x32b6478 + 0x00092> in <filename unknown>:0
at Xamarin.UITest.Shared.Android.LocalAndroidAppLifeCycle.EnsureInstalled (Xamarin.UITest.Shared.Android.ApkFile appApkFile, Xamarin.UITest.Shared.Android.ApkFile testServerApkFile) <0x37418c8 + 0x0017a> in <filename unknown>:0
at Xamarin.UITest.Android.AndroidApp..ctor (IAndroidAppConfiguration appConfiguration) <0x31a15e8 + 0x0047a> in <filename unknown>:0
at Xamarin.UITest.Configuration.AndroidAppConfigurator.StartApp (AppDataMode appDataMode) <0x30b4298 + 0x00063> in <filename unknown>:0
at SightPlayer.Core.Test.AppInitializer.StartApp (Platform platform) <0x30b2448 + 0x000ef> in <filename unknown>:0
at SightPlayer.Core.Test.Tests.BeforeEachTest () <0x30b23f8 + 0x00013> in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x30b2208 + 0x00093> in <filename unknown>:0
Android test are running with Xamarin.UITest version 1.3.5. This is important, as there seems to have been a bug until version 1.3.3. I've also tried ignoring failing tests, but then the test-runner fails with other Android tests. Interestingly enough that sometimes individual tests pass.
Has anyone encountered this behaviour before? Do you have any advice on how to fix this?
When decompiling CommandAdbClearAppData (which throws the exception), I see
// ISSUE: reference to a compiler-generated field
string str1 = string.Format("/data/data/{0}/files/calabash_failure.out", (object)executeCAnonStorey0.svr);
// ISSUE: reference to a compiler-generated field
string str2 = string.Format("/data/data/{0}/files/calabash_finished.out", (object)executeCAnonStorey0.svr);
while (DateTime.UtcNow < utcNow + TimeSpan.FromSeconds(10.0))
{
if (func(string.Format("ls {0}", (object)str1)).Output.Trim().Equals(str1))
throw new Exception("Clear app data failed with " + func(string.Format("cat {0}", (object)str1)).Output);
if (func(string.Format("ls {0}", (object)str2)).Output.Trim().Equals(str2) && func(string.Format("cat {0}", (object)str2)).Output.Trim().Equals("SUCCESSFUL"))
return;
}
throw new Exception("Timed out waiting for result of ClearAppData2");
which indicates that the generated file could not be found within ten seconds. Could it be, that the emulator is simply too slow and the emulator takes longer than ten seconds to create those files?
Could it be, that the emulator is simply too slow and the emulator takes longer than ten seconds to create those files?
Yes, that could be the problem.
Do you have any advice on how to fix this?
The latest dev builds of the Xamarin.UITest nuget package have increased that timeout interval from 10 seconds to 60 seconds.
Try Xamarin.UITest 1.3.6.1476-dev or newer.
I solved this issue uploading a unsigned version of the APK to my testing device (same thing for Xamarin Android Player). I had to uncheck the "Sign the .APK file" box from the Android Package Signing option in the project properties. The WaitTimes way didn't work for me.
I think you need to look at some Configuration
If your app is not waiting to launch the test you could implement WaitTimes.
Create a class like this:
public class WaitTimes : IWaitTimes
{
public TimeSpan GestureWaitTimeout
{
get { return TimeSpan.FromMinutes(1); }
}
public TimeSpan WaitForTimeout
{
get { return TimeSpan.FromMinutes(1); }
}
}
Then implement it like this:
_app = ConfigureApp
.Android
.EnableLocalScreenshots()
.ApkFile(apkFile)
.DeviceSerial("###")
.ApiKey("###")
.Debug()
.WaitTimes(new WaitTimes())
.StartApp();
Otherwise you could just wait for a specific element to load, like this:
_app.WaitForElement(c => c.Marked("Login"), "Time out expired", TimeSpan.FromSeconds(15));
var result = _app.Query(c => c.Marked("Login"));
Assert.AreEqual(1,result.Length);
_app.Screenshot("Test passed with success");
Here is some more information about WaitTime and WaitForElement that could be helpful.

Categories