C# Selenium Tests on CodeFresh not loading test file

65 Views Asked by At

We have a batch of C#/Selenium/xUnit tests running in a CodeFresh pipeline. They all work well apart from 2, these try to upload test files. This works well when run local the code is

        var filePath = Path.Combine(Environment.CurrentDirectory, @"Data\image1.jpg");
        addFile.SendKeys(filePath);

The test files are stored here enter image description here and they are set to 'Copy always' So they deploy ok but they do not seem to be making their way up to the build yaml file. Currently the steps are clone build push_image

The clone step is pulling from the correct repo and the data files exists there. Any ideas please?

Kev

2

There are 2 best solutions below

0
On BEST ANSWER

solved it. Move the files to the project root and changed code -

var filePath = Path.Combine(Environment.CurrentDirectory, @"image1.jpg");
addFile.SendKeys(filePath);

Now all good, thanks for your help

1
On

Can you try this:

    public static string GetBasePath
    {
        get
        {
            var basePath =
                System.IO.Path.GetDirectoryName((System.Reflection.Assembly.GetExecutingAssembly().Location));
            basePath = basePath.Substring(0, basePath.Length - 10);
            return basePath;
        }
    }

var filePath = Path.Combine(GetBasePath, @"Data\image1.jpg");