c# - 替换在 '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”文件夹。替换不起作用。为什么它不起作用?
解决方案
推荐阅读
- .htaccess - htaccess 重写和重定向规则不起作用
- chart.js - 背景颜色隐藏 Y 标签
- microservices - 在多个微服务中使用表的最佳方式
- html - 如何在图像旁边正确放置几行文本并正确缩进
- javascript - 更新状态问题 reactjs 不工作
- python - Flask - 如何保护源文件以使其不可下载?
- angular - Angular 编译器需要 TypeScript >=4.2.3 和 <4.3.0 但找到了 4.4.0-dev.20210724
- python - 没有应用的聚合熊猫数据框
- javascript - 为什么不显示警报?
- python - Pygame:为什么代码永远不会到达第二次打印?