appium / appium-windows-driver

Appium's interface to WindowsAppDriver provided by Microsoft
Apache License 2.0
133 stars 35 forks source link

Exception thrown when trying to execute powershell command from 'prerun' desired capability #101

Closed testifyqa closed 3 years ago

testifyqa commented 3 years ago

Language used = C#

STEPS TO REPRODUCE

  1. Start appium server with powershell insecure feature -> appium --allow-insecure=power_shell
  2. Try to run a simple powershell command driver.ExecuteScript("powerShell", new Dictionary<string, string>{{"command", "echo \"Hello World!\""}});

ACTUAL RESULTS Error is thrown stating Error: Power Shell script/command must not be empty

EXPECTED RESULTS Powershell command is executed successfully

mykola-mokhnach commented 3 years ago

This is fixed in appium@beta

testifyqa commented 3 years ago

Awesome thanks, didn’t realise, will switch to beta for now. Thanks for the fast reply :)

testifyqa commented 3 years ago

Ok so I just tried appium@beta but am now getting this error -> Error: Potentially insecure feature 'undefined' has not been enabled. If you want to enable this feature and accept the security ramifications

Am trying with 'prerun' desired capability

Appium Server started with >appium --allow-insecure=power_shell --nodeconfig=local-nodeconfig.json

testifyqa commented 3 years ago

Just checked it via driver.ExecuteScript() however and that worked successfully :)

sweiguny commented 1 year ago

I thought my follow-up question fits well here.

I'd like to run a powershell script as "prerun", as described here: https://github.com/appium/appium-windows-driver#power-shell-commands-execution

so I've added this line of code: this.options.AddAdditionalCapability("prerun", "C:\\cygwin64\\bin\\bash --login -i C:\\[..path..]\\test.bash");

As far as I can tell, nothing happens. And I don't even get some message/exception whether it works or not. But I've read, that I need to allow this, as this threas shows... But how do I allow this here?

I instantiate the options like this. protected AppiumOptions options = new AppiumOptions(); But I nowhere found how to do this here: --allow-insecure=power_shell

Here is a Link to the "Appium Security document", but this doesn't work. Hence, I am a bit clueless...

Thanks to someone in advance, who can help me.

mykola-mokhnach commented 1 year ago

this.options.AddAdditionalCapability("prerun", "C:\cygwin64\bin\bash --login -i C:\[..path..]\test.bash");

this does not look like a valid powershell script

But I nowhere found how to do this here: --allow-insecure=power_shell

This is a server command line argument. It must be provided to the server startup command line

sweiguny commented 1 year ago

Thanks for your response.

Why doesn't it look like a valid powershell script? If I can run this command in Windows PowerShell, this should work, shouldn't it? If it is invalid, why don't I get some feedback? The application just seems to ignore it....

What server? We are running WinAppDriver this way in our Application:

winAppDriver = Process.Start(new ProcessStartInfo(AppSettings.winAppPath_64, String.Format("{0} {1}", AppSettings.winAppHost, AppSettings.winAppPort)) { UseShellExecute = false, RedirectStandardInput = false/*, RedirectStandardOutput = true*/ });

How to set this allow-insecure here?

mykola-mokhnach commented 1 year ago

What server? We are running WinAppDriver this way in our Application:

This feature is specific to appium-windows-driver. If you use WAD separately (e.g. not as a part of Appium ecosystem) then please do not report issues here as the server part is maintained by Microsoft.