I have a bunch of WebDriver profiles (let's call them x, y and z) and I need to select a random profile to perform certain actions. Let's call the actions A, B and C.
In my class WebDriverManager
I've defined three methods: doA()
, doB()
and doC()
. Each method will select a random profile that a) is not currently being used and b) that is eligible to perform the given action.
If a client
calls doA(), doB() or doC()
, they will get a WebDriver
profile eligible to do action A, B or C. doA(), doB() or doC()
will also set the status of the said profile to UNAVAILABLE (via props file) so that the profile will not be returned for a different action (or the same action if called from a different thread) until it becomes available again.
My problem is the profile will only become available when the client finishes using the said profile for its intended purpose.
Since the methods doA()
etc will be accessed through many clients, how can I force the client
of doA()
, doB()
or doC()
to set the status of WebDriver
profile to AVAILABLE before it returns? If sometime in the future I forget to change the status of the given profile to AVAILABLE (in the client), it will remain UNAVAILABLE forever which will cause a lot of problems.
So how can I guarantee that whatever method calls doA()
, doB()
and doC()
sets the profile status to AVAILABLE before returning?
P.S.
This is the closest question I found on SO but I believe this does not address my issue because I cannot control the actual WebDriver
class, I simply want the client of each of the said methods to perform a certain action before they return.
AutoClosable
won't work either because I'm not trying to close a specific instance of class (I do not control the class), I want the client of a certain method to execute a specific method or code before it finishes.