c# - C# - 进程对象未运行 cmd 命令
问题描述
我正在使用 WinAppDriver 在 Excel 上运行一些测试用例。我正在尝试通过代码启动服务器,这样我就不必在命令行中手动执行它。我有以下代码-
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();
}
就是这样称呼的——
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);
}
此代码打开 CMD 但未运行它。我在这里错过了什么吗?我认为 arguments 属性可以解决问题。
解决方案
尝试将/K
or/C
标志添加到startInfo.Arguments
. 这告诉cmd.exe
运行以下命令,然后关闭(在 的情况下/C
)或返回到 cmd 提示符(在 的情况下/K
)
startInfo.Arguments = $"/C WinAppDriver {port}";
推荐阅读
- java - Eclipse 详细信息格式化程序字符串未显示所有 Unicode 字符
- python - 使用 python 烧瓶框架在 html 正文中设置背景图像
- regex - 使用正则表达式匹配使用 netstat -nb python 的进程名称
- .net-core - VSTS - dotnet restore - PackageCache 不存在
- bash - 将 API 转换为 HTTPS 后 pwd 命令返回“/”
- swift3 - 简单的活动跟踪器 Swift 代码
- javascript - 使用 for 循环反转数组
- wordpress - 如何在 docker-compose.yml 中运行 wp cli
- android - 获取已安装应用程序的列表,不包括内置应用程序
- android - 通话结束后获取来电者电话号码然后开始活动