admin管理员组

文章数量:1025498

I need to do Appium mobile test with C# and Nunit on my real device which is "Xiaomi Poco X3" for an already installed app. I write the following code:

    public class Tests
    {
       AppiumDriver driver;
       AppiumOptions appiumOptions;

       [SetUp]
       public void Setup()
       {
        appiumOptions = new AppiumOptions();
        appiumOptions.PlatformVersion = "12"; 
        appiumOptions.DeviceName = "285f941f";
        appiumOptions.PlatformName = "Android";
        appiumOptions.PlatformVersion = "11";
        appiumOptions.AddAdditionalAppiumOption("uiautomator2ServerInstallTimeout", "6000");
        appiumOptions.AddAdditionalAppiumOption("appPackage", "com.xxxc");
        appiumOptions.AddAdditionalAppiumOption("appActivity", "com.xxxc.activity.MainActivity");  // Replace with your app's main activity
        appiumOptions.AddAdditionalAppiumOption("udid", "285f941f"); 
        appiumOptions.AddAdditionalAppiumOption("noReset", "true");  
        appiumOptions.AddAdditionalAppiumOption("adbExecTimeout", "20000");
        //appWaitForLaunch
        appiumOptions.AddAdditionalAppiumOption("appWaitForLaunch", "true");
        appiumOptions.AddAdditionalAppiumOption("AndroidMobileCapabilityType.AutoGrantPermissions", "true");  // Grant permissions = true;
     }

    [Test]
    public void Test1()
    {
        AppiumDriver driver = null;

        try
        {
            driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), appiumOptions);
            Console.WriteLine("App launched successfully!");

            // Wait for a few seconds to keep the app running
            Thread.Sleep(5000); // Adjust the sleep time as needed

        }
        catch (Exception e)
        {
            Console.WriteLine("Error: " + e.Message);
        }
        finally
        {
            // Close the driver session
            driver?.Quit();
            Console.WriteLine("Driver session ended.");
        }

    }
}

When I run the test I got the following exception: Activity name '.xxxc.activity/.MainActivity' used to start the app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity.

I am sure from the activity name as I get it from the adb command: dumpsys window displays -E "myCurrentFocus".

My code is similar to the code in the answer of this question but the application doesn't launched.

I appreciate any help you provide.

I need to do Appium mobile test with C# and Nunit on my real device which is "Xiaomi Poco X3" for an already installed app. I write the following code:

    public class Tests
    {
       AppiumDriver driver;
       AppiumOptions appiumOptions;

       [SetUp]
       public void Setup()
       {
        appiumOptions = new AppiumOptions();
        appiumOptions.PlatformVersion = "12"; 
        appiumOptions.DeviceName = "285f941f";
        appiumOptions.PlatformName = "Android";
        appiumOptions.PlatformVersion = "11";
        appiumOptions.AddAdditionalAppiumOption("uiautomator2ServerInstallTimeout", "6000");
        appiumOptions.AddAdditionalAppiumOption("appPackage", "com.xxxc");
        appiumOptions.AddAdditionalAppiumOption("appActivity", "com.xxxc.activity.MainActivity");  // Replace with your app's main activity
        appiumOptions.AddAdditionalAppiumOption("udid", "285f941f"); 
        appiumOptions.AddAdditionalAppiumOption("noReset", "true");  
        appiumOptions.AddAdditionalAppiumOption("adbExecTimeout", "20000");
        //appWaitForLaunch
        appiumOptions.AddAdditionalAppiumOption("appWaitForLaunch", "true");
        appiumOptions.AddAdditionalAppiumOption("AndroidMobileCapabilityType.AutoGrantPermissions", "true");  // Grant permissions = true;
     }

    [Test]
    public void Test1()
    {
        AppiumDriver driver = null;

        try
        {
            driver = new AndroidDriver(new Uri("http://127.0.0.1:4723/wd/hub"), appiumOptions);
            Console.WriteLine("App launched successfully!");

            // Wait for a few seconds to keep the app running
            Thread.Sleep(5000); // Adjust the sleep time as needed

        }
        catch (Exception e)
        {
            Console.WriteLine("Error: " + e.Message);
        }
        finally
        {
            // Close the driver session
            driver?.Quit();
            Console.WriteLine("Driver session ended.");
        }

    }
}

When I run the test I got the following exception: Activity name '.xxxc.activity/.MainActivity' used to start the app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity.

I am sure from the activity name as I get it from the adb command: dumpsys window displays -E "myCurrentFocus".

My code is similar to the code in the answer of this question but the application doesn't launched.

I appreciate any help you provide.

本文标签: cMobile Application is not launchedStack Overflow