首页 > 解决方案 > 替换在 'AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug", "");' 中不起作用 仅当我使用 Azure Devops 中的 VSTest 代理运行时。为什么?

问题描述

这是代码:

            Thread.Sleep(4000);
            ITakesScreenshot ts = (ITakesScreenshot)driver;
            Screenshot screenshot = ts.GetScreenshot();
            string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
            //var dir = System.IO.Path.GetDirectoryName(pth).Replace("\\bin\\Debug", "");
            //dir = dir.Replace("file:\\", "");
            var dir = AppDomain.CurrentDomain.BaseDirectory.Replace("\\bin\\Debug", "");
            DirectoryInfo di = Directory.CreateDirectory(dir + "\\Execution_Screenshots\\");
            string finalpth = pth.Substring(0, pth.LastIndexOf("bin")) + "Execution_Screenshots/" + screenShotName+DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss-fff") + ".jpg";
            localpath = new Uri(finalpth).LocalPath;
            screenshot.SaveAsFile(localpath, ScreenshotImageFormat.Jpeg);

当我在本地运行测试时,此代码有效。当我登录到远程机器并使用 CLI 在那里运行 VSTest 时工作。但是当我使用 VSTest 代理任务从 devops 运行它时,会在 Debug 文件夹中创建“Execution_Screenshots”文件夹。替换不起作用。为什么它不起作用?

标签: c#seleniumazure-devopsvstest

解决方案


推荐阅读