skip to Main Content

We have a process which creates a report file ready for downloading as a xlsx file when the user clicks the Save button
I want to view and verify the contents of this file as part of a selenium regression test.
The html for the button is

<a class="n-pad btn" download="test-report" href="blob:https://www.testurl.co.uk/9fe176ea-d339-46eb-ac46-95bf300520e5">
<span class="icon-cp-download"></span>
<span>Save</span>
</a>

And I would like to read the file at this point, can anyone advise of the best method to achieve this please.

Thanks

2

Answers


  1. Chosen as BEST ANSWER

    So we have a way round this

    By setting the download path to "C:agent_work1s" the tests are able to locate and read thje downloaded reports.

    Cool or what...


  2. Based on your question you want to read an excel file(xlsx). the best way to read the contents of it is to use package called ExcelDataReader. install it in your nuget package. it is free and open source.

    get excel sheet row id using exceldatareader into dataset

    or use this code as an example.

    public static DataTable ReadExcelFile(string filePath)
      {
         using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read))
          {
             using (var reader = ExcelReaderFactory.CreateReader(stream))
            {
            // Choose the specific sheet in the Excel file (e.g., 
             reader.AsDataSet().Tables["Sheet1"])
            var result = reader.AsDataSet().Tables[0];
    
            return result;
        }
        }
       }
    

    If does not work,

     string url = "blob:testPie.co.uk/c7a70bf0-7495-48f8-b989-be0035eb79fd";
     string fileName = Path.GetFileName(url);
    
     using (WebClient client = new WebClient())
    {
      client.DownloadFile(url, fileName);
      using (FileStream stream = File.OpenRead(fileName))
      {
        // Use the file stream here as needed
        // ...
      }
       // Once you're done with the file, you can delete it
       File.Delete(fileName);
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search