Xamarin.UITest Tests not working only on real Android devices - xamarin

I'm new to XamarinUITest and I am having trouble running it on real devices locally (in preparation for AppCenter Test).
When I run it using an Android emulator, the test runs smoothly, passes and completes.
When I run it on a real device connected to my machine (OnePlus 5T) I get the following issues:
Message: 
System.Exception : Post to endpoint '/ping' failed after 100 retries. No http result received
Stack Trace: 
AppInitializer.StartApp(Platform platform) line 24
Login.BeforeEachTest() line 25
Standard Output: 
Full log file: C:\Users\Steve\AppData\Local\Temp\uitest\log-2021-11-25_13-54-49-953.txt
Skipping IDE integration as important properties are configured. To force IDE integration, add .PreferIdeSettings() to ConfigureApp.
Android test running Xamarin.UITest version: 3.2.3
Initializing Android app on device 3acaec7 with apk: C:\Users\Steve\source\repos\MyTestApp\MyTestApp.Android\bin\Dev\com.mytestapp.dev-Signed.apk
Skipping local screenshots. Can be enabled with EnableScreenshots() when configuring app.
Signing apk with Xamarin keystore.
I have internet permissions on in my AndroidManifest.xml file.
AppInitializer
public static IApp StartApp(Platform platform)
{
try
{
if (platform == Platform.Android)
return ConfigureApp.Android.ApkFile(#"C:\Users\Steve\source\repos\MyTestApp\MyTestApp.Android\bin\Dev\com.mytestapp.dev-Signed.apk").StartApp();
else
return ConfigureApp.iOS.StartApp();
}
catch(Exception ex)
{
throw(ex);
}
}
I get this same issue if I try upload it to AppCenter. If I run the app when the APK file is already on the device then the test loading indicator keeps spinning forever.
I have tried .InstalledApp() instead and also had no luck on real devices. This is v important so I really appreciate everyone chimming in. Thanks.

Related

Need to store handled exceptions globally without calling the save log method inside Every catch in xamarin.forms

try
{
int c = 0;
int a = 5 / c;
}
catch (Exception ex)
{
}
Need to write Handled Exceptions globally in one place and without calling the errorlog method in each and every catch block in xamarin.forms and expect to get details in mainactivity for android and appdelegate for ios or any comman place in xamarin.forms
In your case you could use App Center . App Center Crashes will automatically generate a crash log every time your app crashes. The log is first written to the device's storage and when the user starts the app again, the crash report will be sent to App Center. Collecting crashes works for both beta and live apps, i.e. those submitted to the App Store. Crash logs contain valuable information for you to help fix the crash.
App Center Crashes provides you with an API to generate a test crash for easy testing of the SDK. This API checks for debug vs release configurations. So you can only use it when debugging as it won't work for release apps.
Crashes.GenerateTestCrash();
If your app crashed previously, you can get details about the last crash.
ErrorReport crashReport = await Crashes.GetLastSessionCrashReportAsync();
Set this callback if you want to decide if a particular crash needs to be processed or not. For example, there could be a system level crash that you'd want to ignore and that you don't want to send to App Center.
Crashes.ShouldProcessErrorReport = (ErrorReport report) =>
{
// Check the report in here and return true or false depending on the ErrorReport.
return true;
};
For more details about App Center you could check Get Started with Xamarin .

How do I deal with a possible exception in a Xamarin Forms application deployed to iOS or Android?

I have a finished application which I would like to make available to run on the iOS and Android platforms.  I have tested the application as much as possible and it works without problem.  But I know there is always the chance that something might go wrong and I could get an exception.
My question is how can I deal with this or what should I do. What happens on the phone, if a Forms application is deployed and there is an exception.
Would appreciate any advice or even links as to how this is handled.
If an exception is thrown and not handled by your code, the app will stop working (i.e. crash).
In order to handle these crashes we are using MS AppCenter (the successor to HockeyApp/Xamarin AppInsights).
You'll have to create a project there (one for each platform), and add the NuGet package to your projects. Afterwards you can initialize it with
AppCenter.Start("ios={Your App Secret};android={Your App Secret}",
typeof(Crashes)); // you'll get the app secrets from appcenter.ms
Crashes will be logged to AppCenter now and you'll be informed whenever there is a new crash.
Please note that it's best practice (if not required by law), that you ask the user for consent before sending the crash report (see here). You are using the delegate Crashes.ShouldAwaitUserConfirmation for that matter. You could for example show an action sheet with Acr.UserDialogs
private bool AwaitUserConfirmation()
{
// you should of course use your own strings
UserDialogs.Instance.ActionSheet(
new ActionSheetConfig
{
Title = "Oopsie",
Message = "The app crashed. Send crash to developers.",
Options = new List<ActionSheetOption>
{
new ActionSheetOption("Sure", () => Crashes.NotifyUserConfirmation(UserConfirmation.Send)),
new ActionSheetOption("Yepp, and don't bug be again.", () => Crashes.NotifyUserConfirmation(UserConfirmation.AlwaysSend)),
new ActionSheetOption("Nope", () => Crashes.NotifyUserConfirmation(UserConfirmation.DontSend))
}
});
return true;
}

Visual Studio android emulator httprequest fails

So I've been working on a xamarin PCL project targeting android and windows store app and I've had this issue for about two weeks now. One of the very first things this app does is to make an http request to a yahoo service when the user tries to search for something.
Now, on the windows store app project, this works just fine. However, whenever I'm debugging the android project, this fails miserably. It times out and I get a TaskAbortedException.
I've navigated with the browser within the android emulator to the restful service url and I do get a response in the browser but nothing when I make the http request. I have tried everything I could think of but no cigar. I have researched this for weeks now and I have yet to find an answer. It should be noted that I'm making the request within the PCL project with HttpClient.
Here's the code where this happens:
var queryUrl = string.Format(QUERY_URL_TEMPLATE, TickerSearch);
try
{
var requestTask = httpClient.GetStringAsync(queryUrl);
requestTask.ContinueWith(t =>
{
var responseDto = JsonConvert.DeserializeObject<TickerSearchResultDto>(t.Result);
TickerSearchResults = responseDto.ResultSet.Result;
});
}
catch (Exception ex)
{
}
Any help is greatly appreciated.

Session state service failed - UWP

I am working on UWP application, using Prism 6.0
My application is working totally fine in both Debug and Release modes but when i am running Windows App Certification Kit on the app packages, I keep getting this Application error - "Session state service failed". I have never seen this exception when I am installing the app packages and running the app. But I get this exception every time when WACK is running the packages.
Because of this,
I am getting error in Windows App Certification Kit - Test Results.
The error are:
FAILED
Crashes and hangs
•Error Found: The crashes and hangs test detected the following errors:◦Executable C:\Program Files\WindowsApps\10486username.SongApp_1.1.0.0_x86__5q2wmk4fv784y\SongApp.exe was detected by Windows Error Reporting and experienced a crash or hang.
◦Application 10486username.SongApp_1.1.0.0_x86__5q2wmk4fv784y was detected by Windows Error Reporting and experienced a crash or hang.
•Impact if not fixed: An app that stops responding or crashes can cause data loss and is a poor user experience.
•How to fix: Investigate and debug the app to identify and fix the problem.
FAILED
Direct3D trim after suspend
•Error Found: The Direct3D Trim after Suspend test detected the following errors:◦Application App was not running at the end of the test. It likely crashed or was terminated for having become unresponsive.
•Impact if not fixed: If the app does not call Trim on its Direct3D device, the app will not release memory allocated for its earlier 3D work. This increases the risk of apps being terminated due to system memory pressure.
•How to fix: The app should call the Trim API on its IDXGIDevice3 interface anytime it is about to be suspended.
I've built a repro with the Prism sandbox app creating a new type as model, have it serialized on suspension and watch it crash through hitting Suspend and shutdown as application lifecycle event in the Debug location toolbar.
namespace HelloWorld.Models
{
public class MyModel
{
public MyModel() {}
public MyModel(string someText)
{
SomeText = someText;
}
public string SomeText { get; set; }
}
}
In the viewmodel:
[RestorableState]
public MyModel MyModel
{
get { return _myModel; }
set { SetProperty(ref _myModel, value); }
}
After some research, I managed to solve the crash by adding following lines in the runtime directives (Default.rd.xml) file:
<!-- Add your application specific runtime directives here. -->
<Namespace Name="HelloWorld.Models" Serialize="Required PublicAndInternal">
<Type Name="MyModel" Browse="Required Public" DataContractSerializer="Required Public"/>
</Namespace>
DataContractSerializer
Optional attribute. Controls policy for serialization that uses the System.Runtime.Serialization.DataContractSerializer class.
Source: MSDN

Change Parse Application when App is running

I have an Android Application that works with locals instalations and I want use it with diferents Parse applications. Each instalation administrator will contract with Parse directly. When app start it will look for the keys for parse.
I wonder how to change the Parse App linkeded in the Android App once this is running
I have tried to call Parse.initialize (context, apllicationId, clientKey) twice but it doesn't work. I have tried the app register in diferent Parse App every time you start the App link with a different Parse App
It´s always linked only with the first application
public void onCreate(final Bundle icicle){
super.onCreate(icicle);
final Context context = this;
setContentView(R.layout.ssa);
getActionBar().hide();
// Getting the global variables
fmGlobalsBean = Utilities.getGlobals(this);
if(!"".equals(fmGlobalsBean.getUrl_server())){
Parse.initialize(contexto, "p4IWkTRc0WTdKkMH6r60hjYzwX1TIXChy8VcDvPb", "KhkcX4G3dqVpRawHyIYfnHAWqj1H2vyhwD3wINlQ");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground(fmGlobalsBean.getUrl_server());
}
else
{
Parse.initialize(this, "Y3xgZ58u4Qcn9TrovFqCOe4PBzhURjXooZ3vDKgB", "ealo3nm4wa4lbJ7KrSR2OSf60DZiUjEUjdUJTQzs");
ParseInstallation.getCurrentInstallation().saveInBackground();
ParsePush.subscribeInBackground("INITIAL");
}
}

Resources