How to Get MainActivity from Android Driver

Hi all,

I’m new to Appium, trying to set up automation for a Xamarin app. I’ve been building some tests based on the Appium C# examples, and I can’t get the test for session creation to pass. This is my test class:

public class AppStartTests
    private AndroidDriver<AndroidElement> _driver;

    public void Setup()
        var options = new AppiumOptions();
        options.AddAdditionalCapability(MobileCapabilityType.BrowserName, "");
        options.AddAdditionalCapability(MobileCapabilityType.PlatformName, TestResources.DEVICE_PLATFORM);
        options.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, TestResources.PLATFORM_VERSION);
        options.AddAdditionalCapability(MobileCapabilityType.AutomationName, TestResources.AUTOMATION_DRIVER);
        options.AddAdditionalCapability(MobileCapabilityType.DeviceName, TestResources.DEVICE_NAME);
        options.AddAdditionalCapability(MobileCapabilityType.App, TestResources.APK_PATH);
        options.AddAdditionalCapability("adbExecTimeout", "60000");

        _driver = new AndroidDriver<AndroidElement>(TestResources.SERVER_URI, options, TestResources.INIT_TIMEOUT_SEC);
        _driver.Manage().Timeouts().ImplicitWait = TestResources.IMPLICIT_TIMEOUT_SEC;

    public void CanCreateSession()
        var currentActivity = _driver.CurrentActivity;

        Assert.AreEqual($".MainActivity", currentActivity);

And this test throws the following exception:
Expected string length 13 but was 34. Strings differ at index 0.
Expected: “.MainActivity”
But was: “crc647d3461c7d440b30f.MainActivity”

My question here is, how do you locate & account for that string of letters and numbers preceding MainActivity?


Most likely this prefix is not constant and a new value is generated for each activity run. Try to validate endsWith rather that equalTo