4

I am using Azure DevOps Server 2019 (ADOS for short, installed on-premises) to run end to end tests based on Selenium in C#.

Every now and then a build ends badly without properly stopping the chromedriver.exe process used by my Selenium tests. As a result, the subsequent build fails at the Initialize Job step with an error that looks like this:

One or more errors occurred. (Access to path 'C:...\chromedriver.exe' is denied.)

What I understand from this is that because chromedriver.exe is still running ADOS cannot delete its .exe file when it tries to clean the working folder at the start of the build run.

I've tried disabling the Clean feature of the Get sources step definition but that only shifted the error a bit forward to the Checkout step.

To resolve the problem I am forced to manually RDP into my agent machine, taskkill /IM chromedriver.exe /F and re-run the failed build.

My question is - How can I prevent the access denied error? I've thought of these approaches but I'm not sure which is practical:

  1. Get ADOS to run taskkill automatically before the Get sources step. How?

  2. Make the agent have higher privileges so it can delete chromedriver.exe even when its process is still running. Again, how?

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
urig
  • 16,016
  • 26
  • 115
  • 184

2 Answers2

3

If your assumption is correct:

What I understand from this is that because chromedriver.exe is still running ADOS cannot delete its .exe file when it tries to clean the working folder at the start of the build run.

Make sure you are using the driver.close() as well as the driver.quit() methods at the end of every test.

Use teardown to make sure it will always happen.

EDIT:

As OP commented:

when I cancel the ADOS build, the test step is terminated abruptly and the teardown step is not executed.

My recommendation is to an atexit method.

For C# Use ProcessExit Event (credit to @Fredrik Mörk's answer)

For Python use atexit

Community
  • 1
  • 1
Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
  • Thanks @moshe-slavin. I'm actually calling those method but if I understand correctly then when I cancel the ADOS build, the test step is terminated abruptly and the teardown step is not executed. – urig Nov 14 '19 at 13:01
  • @urig what language are you using for the `selenium` scripts? if you use `python`... you can use the `atexit` [library](https://docs.python.org/3/library/atexit.html). – Moshe Slavin Nov 14 '19 at 13:19
  • 1
    @urig You can find some ways todo it [here](https://stackoverflow.com/a/1679888/6845383) – Moshe Slavin Nov 14 '19 at 13:48
  • 1
    I'll give the exit events approach a try next week and let you know how it worked. thanks – urig Nov 14 '19 at 15:04
  • Hope you'll find it helpful! Shabat shalom – Moshe Slavin Nov 14 '19 at 15:07
2

I've come up with a solution based on ADOS Pipelines' functionality. After my Visual Studio Test task I've added a Command Line task and configured it like so:

  1. The script is 'taskkill/IM chromedriver.exe /F'.
  2. Under Control Options I've set:
    • Run this task to 'Custom conditions'
    • Custom condition to 'canceled()'
    • Continue on error checked.

This way, whenever my build is cancelled manually, all instances of the chromedriver.exe process are terminated, clearing the way for subsequent builds to run.

urig
  • 16,016
  • 26
  • 115
  • 184