1

When I run my automated tests in parallel in an Azure DevOps release pipeline using SpecRun.SpecFlow, I get an exception on a few of the tests in relation to Chromedriver being in use by another process (the other tests that are running). The exception is:

Error: Exception has been thrown by the target of an invocation. -> The process cannot access the file 'D:\a_temp\TestResults\Chrome\102.0.5005.61\X64\chromedriver.exe' because it is being used by another process.

This doesn't happen locally, and runs perfectly fine on multiple threads, and only seems to happen in the pipeline. Has anyone experienced this before? If so, any ideas on how to fix it?

riQQ
  • 9,878
  • 7
  • 49
  • 66
benm912
  • 77
  • 1
  • 7

1 Answers1

0

I managed to resolve this. The reason it was passing locally was because Chromedriver existed on my machine, so whenever a test ran, it didn't need to download the file. On the VM, Chromedriver didn't exist, so it had to download it. It seemed like the test was executing before whatever process was attached to downloading Chromedriver had finished, which was why the first set of tests to run failed, but subsequent tests on those threads passed.

I resolved this by popping in some retry logic and some logging to show how many times it failed to initialize.

[Before]
    public void Before()
    {

        int errorCount = 0;
        while (errorCount < 5)
        {
            try
            {
                _webDriverContext = new WebDriverContext();
                _webDriverContext.Browser = new Browser(BrowserOptionsSupport.GetBrowserOptions(new TestSettings()));

            }

            catch
            {
                Log.Info($"Failed to initialize Chrome on {errorCount} attempt");
                errorCount++;
                if (errorCount < 5)
                {
                    continue;
                }
                else
                {
                    throw;
                }
            }
            break;
        }
    }
benm912
  • 77
  • 1
  • 7