[英]C# - Process object not running cmd command
I'm using WinAppDriver in order to run some test cases on Excel. 我使用WinAppDriver以便在Excel上运行一些测试用例。 I'm trying to start the server through the code so that I don't have to manually do it in command line.
我正在尝试通过代码启动服务器,以便不必在命令行中手动进行操作。 I have the following code-
我有以下代码-
public static void StartWinAppServer(int port) {
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.FileName = "cmd.exe";
startInfo.WorkingDirectory = @"C:\Program Files (x86)\Windows Application Driver\";
startInfo.Arguments = $"WinAppDriver {port}";
process.StartInfo = startInfo;
process.Start();
}
Which is called like this- 像这样被称为-
public static WindowsDriver<WindowsElement> GetWindowsAppDriver (AppName appName) {
string appID = string.Empty;
StartWinAppServer(4723);
switch(appName) {
case AppName.Excel:
appID = @"C:\Program Files\Microsoft Office\root\Office16\Excel.exe";
break;
}
DesiredCapabilities appCapabilities = new DesiredCapabilities();
appCapabilities.SetCapability("app", appID);
return new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);
}
This code opens up the CMD but isn't running it. 这段代码打开了CMD,但没有运行它。 Am I missing something here?
我在这里想念什么吗? I thought the arguments property would've done the trick.
我认为arguments属性可以解决问题。
Try adding the /K
or /C
flag to startInfo.Arguments
. 尝试将
/K
或/C
标志添加到startInfo.Arguments
。 This tells cmd.exe
to run the following command and then close (in the case of /C
) or return to the cmd prompt (in the case of /K
) 这告诉
cmd.exe
运行以下命令,然后关闭(对于/C
)或返回到cmd提示符(对于/K
)。
startInfo.Arguments = $"/C WinAppDriver {port}";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.