最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

c# - Mobile Application is not launched - Stack Overflow

matteradmin7PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far