Zain Mecklai
Zain Mecklai

Reputation: 9

How do I run Xamarin UITests without hard coding the Device ID and path to apk?

According to the Xamarin UI Test documentation I need to do this:

IApp app = ConfigureApp.Android
.DeviceSerial("0756edf000620ace")
.ApkFile(PathToAPK)
.StartApp();

But it seems odd to me to have the DeviceSerial and the ApkFile hard coded like this. Additionally, when submitting to appcenter.ms those two settings aren't required. It seems to me that there must be some way to externalize this information so that you can run the same test on multiple devices without having to go in and change the code.

Sure, I could use some other external external resource but what I really want is to be able to specify these values at run time without recompiling

Upvotes: 1

Views: 517

Answers (2)

Leszek L
Leszek L

Reputation: 76

Try something like this in AppInitializer class for the UiTest project:

public static IApp StartApp(Platform platform)
{
  if (platform == Platform.Android)
  {
    return ConfigureApp
           .Android
           .InstalledApp(package_name)
           .StartApp();
  }
  else
  {
    return ConfigureApp
           .iOS
           .InstalledApp(package_name)
           .StartApp();
  }
}

where package_name is the name of your application package. You can get it from android manifest under the name package

Upvotes: 0

D.Mart
D.Mart

Reputation: 126

I think you don't need to specify "DeviceSerial". Try launch the test only with:

IApp app = ConfigureApp.Android
.ApkFile(PathToAPK)
.StartApp();

Upvotes: 1

Related Questions