Appium - 无法创建新会话.用于启动应用的活动不存在或无法启动

本文关键字:启动 应用 不存在 用于 活动 会话 创建 新会话 Appium | 更新日期: 2023-09-27 18:34:06

当我在选择了应用程序路径、包和启动活动的情况下启动 Appium 服务器时,服务器将从我的应用程序启动,我可以运行我的测试。测试完成后,我退出了驱动程序。

接下来,我尝试在服务器已经运行的情况下再次运行相同的测试。我有在TestFixtureSetUp中编写的功能(见下文)。但是,我收到以下错误:

SetUp : System.InvalidOperationException : A new session could not be created. (Original error: Activity used to start app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity) (33)
   at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
   at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.Appium.AppiumDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
   at MobileAutomationSample.AndroidSimpleTest.BeforeAll() in AndroidSimpleTest.cs: line 42

我的代码:

[TestFixture()]
public class AndroidSimpleTest
{
    private AppiumDriver driver;
    [TestFixtureSetUp]
    public void BeforeAll()
    {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.SetCapability("appium-version", "1.2.4.1");
        capabilities.SetCapability("platformName", "Android");
        capabilities.SetCapability("platformVersion", "5.0");
        capabilities.SetCapability("deviceName", "emulator-5554");
        capabilities.SetCapability("browserName", "");
        capabilities.SetCapability("app", "app-debug.apk");
        capabilities.SetCapability("appPackage", "com.company.app");
        capabilities.SetCapability("appActivity", "com.company.app.MainActivity");
        Uri androidUri = new Uri("http://127.0.0.1:4723/wd/hub");
        driver = new AppiumDriver(androidUri, capabilities, TimeSpan.FromSeconds(180));
        driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
        WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
    }
    [TestFixtureTearDown]
    public void AfterAll()
    {
        driver.Quit();
    }

Appium - 无法创建新会话.用于启动应用的活动不存在或无法启动

需要为应用功能提供绝对路径。一旦提供,问题就解决了。

只需在方法中添加driver.closeapp()driver.resetapp() afterall