[英]Selenium C# automation test Asserting file has been downloaded on azure devops release
我目前正在计算机上本地运行我的自动化测试。 我正在考虑将它们发布到 azure devops 并在那里运行所有测试。 在我的一项测试中,我声明了应该在哪里下载、检查和删除文件。 虽然它在我通过 Visual Studio 在本地运行测试时有效但是当测试在 Azure 中运行时,我得到System.IO.DirectoryNotFoundException:找不到路径“C:\Users\Downloads”的一部分。 似乎是什么问题? 谢谢。 我的代码如下
var filedownload = driver.FindElement(WebObjects.downloadThefile);
Assert.IsTrue(downloadThefile.Enabled);
downloadThefile.Click();
System.Threading.Thread.Sleep(3000);
int fileIsDownloaded = Directory.GetFiles(@"C:\Users\Downloads\", "*.pdf", SearchOption.AllDirectories).Length;
if (fileIsDownloaded > 0)
{
Assert.IsTrue(fileIsDownloaded > 0);
}
else
{
Assert.IsTrue(fileIsDownloaded < 0);
}
string[] downloadedFiles = Directory.GetFiles(@"C:\Users\Downloads\", "*.pdf");
foreach (string file in downloadedFiles)
{
File.Delete(file);
}
}
}
}
有没有办法运行一个断言并验证某个文件已被下载的测试?
此功能应写入存储库而不是 Azure DevOps,在您的描述中,您已完成此操作。 您可以随意在 Azure DevOps 中运行测试,它应该可以工作。 您可以参考此博客在 Azure DevOps 中创建 Selenium 测试管道。
设法将下载路径设置为int fileIsDownloaded = Directory.GetFiles(AppContext.BaseDirectory,"*.pdf", SearchOption.AllDirectories).Length;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.