appium / dotnet-client

Extension to the official Selenium dotnet webdriver
Apache License 2.0
381 stars 187 forks source link

[Bug]: System.TypeLoadException: Access is denied: 'OpenQA.Selenium.Remote.DesiredCapabilities'. at OpenQA.Selenium.Appium.AppiumOptions..ctor() #600

Closed shyampatadia closed 11 months ago

shyampatadia commented 1 year ago

Description

Hello Trying to initialize the appium options as :

AppiumOptions appiumOptions = new AppiumOptions();

Below is the Exception that I am getting: System.TypeLoadException: Access is denied: 'OpenQA.Selenium.Remote.DesiredCapabilities'. at OpenQA.Selenium.Appium.AppiumOptions..ctor()'

Environment

Below are the Package References:

    <PackageReference Include="Appium.WebDriver" Version="4.4.0" />
    <PackageReference Include="Selenium.Support" Version="4.1.1" />
    <PackageReference Include="Selenium.WebDriver" Version="4.1.1" />
    <PackageReference Include="SpecFlow" Version="3.4.8" />
    <PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.4.8" />
    <PackageReference Include="SpecFlow.xUnit" Version="3.4.8" />

Below is the netcore version that I am using:

 <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

Desktop OS version is: Windows 11. And I am trying to run it for launching WinAppDriver (1.2.1)

Code To Reproduce Issue

AppiumOptions appiumOptions = new AppiumOptions();

Exception stack traces

System.TypeLoadException: Access is denied: 'OpenQA.Selenium.Remote.DesiredCapabilities'.
   at OpenQA.Selenium.Appium.AppiumOptions..ctor()
Dor-bl commented 1 year ago

Appium web driver 4.4.0 is not compatible with selenium 4. You will need to update to appium dotnet client version 5.x beta release

shyampatadia commented 1 year ago

Tried it with that but I am getting the below error:

The Code to reproduce the same is as follows:

var appiumOptions1 = new AppiumOptions();
            appiumOptions1.AcceptInsecureCertificates = true;
            appiumOptions1.App = @"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE";
            Process.Start(
                @"WinAppDriver.exe");
            var sessionExcel = new WindowsDriver(
                new Uri("http://127.0.0.1:4723"),
                appiumOptions1
            );

I am getting the exception on the line where I initialize sessionExcel

OpenQA.Selenium.WebDriverArgumentException: Bad capabilities. Specify either app or appTopLevelWindow to create a session
   at OpenQA.Selenium.WebDriver.UnpackAndThrowOnError(Response errorResponse, String commandToExecute)
   at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.Appium.AppiumDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
   at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
   at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
   at OpenQA.Selenium.Appium.AppiumDriver..ctor(ICommandExecutor commandExecutor, ICapabilities appiumOptions)
   at OpenQA.Selenium.Appium.AppiumDriver..ctor(Uri remoteAddress, ICapabilities appiumOptions, TimeSpan commandTimeout)
   at OpenQA.Selenium.Appium.AppiumDriver..ctor(Uri remoteAddress, ICapabilities appiumOptions)
   at OpenQA.Selenium.Appium.Windows.WindowsDriver..ctor(Uri remoteAddress, AppiumOptions AppiumOptions)

And the above code works fine when I use it with following package versions:

    <PackageReference Include="Appium.WebDriver" Version="4.1.1" />
    <PackageReference Include="Selenium.Support" Version="3.141.0" />
    <PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
Dor-bl commented 1 year ago

Please see the discussion here : https://github.com/appium/dotnet-client/issues/487

shyampatadia commented 1 year ago

Hello @Dor-bl, I checked out this #487 issue, but is there any example on how can I use this package for my development? Is there any example repository for using this with C# binding?

Dor-bl commented 1 year ago

All should basically be the same. You can see an example here : https://github.com/appium/dotnet-client/blob/release/5.0.0/test/integration/Windows/ClickElementTest.cs The main idea is to use the appium window driver as a proxy, so you should start appium server regularly, just make sure you follow the guide on the corresponding repo.

Dor-bl commented 1 year ago

@shyampatadia did you get a chance to check if the solution above works for you? Can I close this issue?

shyampatadia commented 1 year ago

I tried but couldn't find a proper way how I can use that, I saw the link that you provided, but I was confused, is that a nugget package which I can install?

Dor-bl commented 1 year ago

I've sent the example code on how to use the appium windows driver. Just make sure you run via appium server and not Microsoft Windows driver

Dor-bl commented 1 year ago

@shyampatadia, any updates on this issue?

shyampatadia commented 11 months ago

Yes the issue is resolved really sorry for not replying earlier.