c# selenium tests on azure download and confirm report files

huangapple go评论60阅读模式
英文:

c# selenium tests on azure download and confirm report files

问题

我们在Selenium/C#中有一组测试,这些测试会点击下载报告按钮,然后验证报告是否已在本地文件中创建。我们现在希望将这些测试部署到在Azure上运行的主要测试套件中,该套件在发布管道中运行。目前,这些测试在本地运行正常,但在Azure上运行时出现问题。

为了开始,我们尝试了不同的路径,例如:

protected const string DownloadPathExt = "C:\\TestFolder\\Release\\net6.0\\";
protected const string DownloadPathExt = "D:\\a\\r1\\a\\TestFolder Regression\\";

我注意到这些路径在构建步骤中使用。它们最初在这里定义:

var options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", DownloadPathExt);

还有在这里:

string[] filePaths = Directory.GetFiles(DownloadPath);

从这个输出中可以看出,测试正在查找我设置的任何文件夹,但没有看到报告文件。因此,要么它没有下载,要么它被创建在不同的文件夹中。

本地环境中,测试能够找到已下载的报告,但在Azure上却找不到。请问有没有人对我可能漏掉的地方有任何想法?

提前感谢。

Kev

英文:

We have a group of tests in Selenium/C# which click on download report buttons and then validate the report has been created in the local file. We now wish to deploy these tests with our main test suite which runs on azure in a release pipeline. At the moment the tests run fine locally but not on azure.
To start we have tried different paths such as

protected const string DownloadPathExt = "C:\\TestFolder\\Release\\net6.0\\";
protected const string DownloadPathExt = "D:\\a\\r1\\a\\TestFolder Regression\\";

I have noticed these are in use during the buils step. This is initially defined here

var options = new ChromeOptions();
options.AddUserProfilePreference("download.default_directory", DownloadPathExt);

And also here

string[] filePaths = Directory.GetFiles(DownloadPath);

As you can see from this output the test is looking in whatever folder I am setting but it is not seeing the report file. So either it is not downloading or it is being created in a different folder.

2023-06-05T10:52:01.9695830Z  In procedure ReadXLSFileDownloaded
2023-06-05T10:52:01.9696187Z  Checking file D:\a\r1\a\_Pi Regression\.editorconfig
2023-06-05T10:52:01.9696549Z  Checking file D:\a\r1\a\_Pi Regression\.gitattributes
2023-06-05T10:52:01.9696918Z  Checking file D:\a\r1\a\_Pi Regression\.gitignore
2023-06-05T10:52:01.9697378Z  Checking file D:\a\r1\a\_Pi Regression\azure-pipelines.yml
2023-06-05T10:52:01.9697840Z  Checking file D:\a\r1\a\_Pi Regression\azure-test-pipelines.yml
2023-06-05T10:52:01.9698236Z  Checking file D:\a\r1\a\_Pi Regression\TestApp.sln
2023-06-05T10:52:01.9698608Z  Checking file D:\a\r1\a\_Pi Regression\README.md
2023-06-05T10:52:01.9698967Z  Checking file D:\a\r1\a\_Pi Regression\xml_to_nunit.xslt

Locally this is finding the downloaded report, in azure it is not. Has anyone got any ideas on what I am missing please?

Thanks in advance.

Kev

答案1

得分: 1

按照https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml中的说明,我建议将System.DefaultWorkingDirectory系统变量作为环境变量传递给测试任务,例如:

- task: DotNetCoreCLI@2
  displayName: 测试
  env:
    DownloadDirectory: $(System.DefaultWorkingDirectory)
  inputs:
    command: 'test'
    projects: $(TestProject)

然后可以这样使用它:

Environment.GetEnvironmentVariable("DownloadDirectory");

确实,System.DefaultWorkingDirectory = "c:\agent_work\1\s",但对我来说,使用System.DefaultWorkingDirectory听起来更可靠且能应对未来的Azure更改。

英文:

Following https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml I would suggest passing System.DefaultWorkingDirectory system variable as env var to test task, e.g.:

- task: DotNetCoreCLI@2
  displayName: Test
  env:
    DownloadDirectory: $(System.DefaultWorkingDirectory)
  inputs:
    command: 'test'
    projects: $(TestProject)

and use it like that:

Environment.GetEnvironmentVariable("DownloadDirectory");

It is true that System.DefaultWorkingDirectory = "c:\agent_work\1\s" but for me usage of System.DefaultWorkingDirectory sounds more solid and future azure changes-proof.

答案2

得分: 0

已排序,如果有人需要答案
将下载路径设置为"C:\agent_work\1\s"解决了此问题
现在测试可以找到并读取下载的报告。
Coolio

英文:

Sorted, should anyone need the answer
Setting the download path to "C:\agent_work\1\s" resolvedv this issue
Tests are now finding and reading the downloaded reports.
Coolio

huangapple
  • 本文由 发表于 2023年6月5日 18:58:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76405762.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定