c# - 系统.ComponentModel.Win32Exception : 'Access is denied' error while Automating a WPF app using FlaUI+SpecFlow

标签 c# wpf process specflow flaui

我遇到了一个不常发生的问题。我正在尝试使用 FlaUI 和 SpecFlow 自动执行 UI 测试。我正在尝试启动应用程序 exe应用程序运行了一段时间然后抛出错误。 我收到以下错误。

System.ComponentModel.Win32Exception: 'Access is denied'

代码:

public void Start()
        {
            try
            {
                _logger.Info("Synergy TestHub starting up in memory");

                _testHub = new SynergyTestHub(locator =>
                {
                    locator.RegisterFeatureService(Substitute.For<ISynergyLogger>());
                    locator.RegisterFeatureService(Substitute.For<ISynergyClientConfigService>());
                }, Config.SynergyEnvironment);


                // Run the Synergy Test Hub In Memory
                AsyncBlockingDeadlockAvoidanceHack.SafeWait(
                    async () => await _testHub.RunUiApplicationAsync(
                        _pathBuilder.ShipTrackerExePath,
                        600,
                        false));

                _controlAction.WaitFor(new TimeSpan(0, 0, 0, 50)); // Average time for ref data to load

                var process = Process.GetProcessesByName(Config.ShipTrackerFileName)[0];
                process.WaitForInputIdle();
                Application = Application.Attach(process.Id);
                ShipTrackerWindow = GetMainWindow();
            }
            catch (Exception exception)
            {
                _logger.Error($"Error Starting up Synergy TestHub in Memory. {exception.Message}");
                _logger.Warning("Killing processes that could be hanging around .. please try to run the test again");
                _processTerminator.KillProcess(new List<string>
                {
                    Config.ShipTrackerFileName, Config.SynergyHubAppName

                });

                throw;
            }
        }

StackTrace

堆栈跟踪:

ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)
Process.GetProcessHandle(Int32 access, Boolean throwIfExited)
Process.WaitForInputIdle(Int32 milliseconds)
Process.WaitForInputIdle()
ApplicationDriver.Start() line 79
Hooks.BeforeScenario() line 133
lambda_method(Closure , IContextManager )
BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration) line 69
TestExecutionEngine.InvokeHook(IBindingInvoker invoker, IHookBinding hookBinding, HookType hookType) line 351
TestExecutionEngine.FireEvents(HookType hookType) line 340
TestExecutionEngine.FireScenarioEvents(HookType bindingEvent) line 321
TestExecutionEngine.OnScenarioStart() line 198
TestRunner.OnScenarioStart() line 54
RefreshTheViewsFeature.ScenarioStart()
RefreshTheViewsFeature.AutomationOfRefreshInManualPublishMode() line 34

process.WaitForInputIdle(); 行抛出上述错误。

最佳答案

您没有权限读取您设备中的所有进程,请尝试以管理员模式运行

关于c# - 系统.ComponentModel.Win32Exception : 'Access is denied' error while Automating a WPF app using FlaUI+SpecFlow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60495468/

相关文章:

c# - "does not contain a definition...and no extension method.."错误

c - UNIX 中的 Fork() 创建的进程是一致运行还是顺序运行?

javascript - 如何在 child_process spawn() 调用的输出的每一行加上文本前缀?

c# - 列表框的多数据触发条件来检查是否选择了某个项目

c# - 如何将 C# 中的 DateTime.now 转换为 yyyy-mm-dd hh :mm:ss. sssssss?

c# - 只有属性具有特定值的 Concat 列表

c# - OxyPlot 绘图 Controller

c# - 这样显示菜单方便吗?

Python multiprocessing.Process 对象的行为就像它持有对另一个进程中的对象的引用。为什么?

C# 正则表达式替换模式(替换字符串)返回 $1