appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
383 stars 188 forks source link

OpenQA.Selenium.WebDriverArgumentException: Bad capabilities. Specify either app or appTopLevelWindow to create a session #492

Closed tvbishan closed 2 years ago

tvbishan commented 2 years ago

Description

Got below exception when trying to work with Appium and WinAppDriver on Windows 10.

Message: Class Initialization method UIAutomation.ExcelScenario.ClassInitialize threw exception. OpenQA.Selenium.WebDriverArgumentException: OpenQA.Selenium.WebDriverArgumentException: Bad capabilities. Specify either app or appTopLevelWindow to create a session.

How cloud I solve this?

Environment

Code To Reproduce Issue [ Good To Have ]

using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Windows;
using System;

namespace UIAutomation
{
    public class ExcelSession
    {
        private const string WindowsApplicationDriverUrl = "http://127.0.0.1:4723";
        private const string ExcelAppId = "Excel";
        private const string sourceFileExcel = @"/e C:\tmp\Test.xlsx";

        protected static WindowsDriver session;

        public static void Setup(TestContext context)
        {
            if (session == null)
            {
                AppiumOptions appOptions = new AppiumOptions();
                appOptions.App = ExcelAppId;
                appOptions.DeviceName = "WindowsPC";
                appOptions.AddAdditionalAppiumOption("appArguments", sourceFileExcel);
                session = new WindowsDriver(new Uri(WindowsApplicationDriverUrl), appOptions);
                Assert.IsNotNull(session);

                session.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1.5);
            }
        }

        public static void TearDown()
        {
            // Close the application and delete the session
            if (session != null)
            {
                session.Quit();
                session = null;
            }
        }
    }
}

Exception stacktraces

image

mykola-mokhnach commented 2 years ago

Duplicate of https://github.com/appium/appium-dotnet-driver/issues/487

Dor-bl commented 2 years ago

Duplicate of https://github.com/appium/appium-dotnet-driver/issues/487