I have an application that I'm attempting to put Xamarin UI Tests on. I need to Backdoor the app to bypass my login process. My Backdoor method fires just fine.
[Activity(Label = "AppName", Icon = "@drawable/icon", Theme = "@style/Theme.Splash", MainLauncher = true, NoHistory = true)]
public class SplashActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
StartActivity(typeof(MainActivity));
}
[Java.Interop.Export("BackDoor")]
public void BackDoor()
{
var myActivity = {Magic code to get reference to the the instance of MainActivity goes here}
}
}
However its firing in my Splash screen and I need it get a reference to my actual MainActivity not my SplashActivity. How do I get a reference to the MainActivity in my BackDoor method?
Xamarin Backdoor Docs: https://developer.xamarin.com/recipes/testcloud/start-activity-with-backdoor/ https://developer.xamarin.com/guides/testcloud/uitest/working-with/backdoors/
How To Retrieve Current Activity
To retrieve the
MainActivity
, you can use @JamesMontemagno's CurrentActivityPlugin.Add the Current Activity NuGet Package into your Xamarin.Android project, and then, in your Xamarin.Android Project, you can use the following line of code to retrieve the current activity and check that it is the MainActivity.
This plugin is open-sourced on GitHub.