Silk4J: When multiple application processes are running, how can you ensure the script attaches to the one it launched?
Consider that a number of QA engineers connect to the same Server to develop their tests and run them against the same application throughout the day. At any point a variable number of application windows may be running, so how can each tester ensure that their script finds and attaches to the correct instance of the application i.e the one that it launched?
One possible approach to this problem involves maintaining multiple Object Maps, all of which are identical but tied to separate instances via their Locators; however this approach assumes that the tester knows in advance which instance they need to find and which Object Map needs to be referenced in the script.
If this is not predictable then the Window's Locator will somehow need to be generated dynamically at run-time.
Example: Assume that there are an unknown number Notepad windows running and you need to execute a script that launches and attaches to a new Notepad window.
In order to attach to the last Notepad instance launched, you need to know exactly how many Notepad windows are running. To confirm this you could use a function like the one below which accepts a Locator string and returns the number of windows that match it:
However, this Index may not be stable because other windows might open and close while the script is running potentially modifying the indexes of the remaining windows.
The recommended approach is to use the Index to extract a more stable Locator property for the window. For example if we know that the caption value is static and unique, it can be extracted as follows and subsequently used to find and interact with the window: