[英]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.