The right way to script waiting for events in multiple browser tabs?

Asked by tjonnyc

I have a small script that performs some actions in a web-based application. A cornerstone of this script is waiting for an "event complete" message, and proceeding to the next step. Here's the simplified code:

-----------------------------------
for a in range(1000):
    {start the action}
    Region(500,700,20,45)
    wait("screenshot.png", 5000) <---- this monitors a particular region of the screen for the "OK" message
    {complete the action}
-----------------------------------

This works perfectly fine. However, now I would like to run it in 10 tabs at the same time.

What would be the proper way to set up observation for a specific event (which will be the same in any tab), across multiple tabs? Using time delays will not work, since the action may take a variable time to complete.

Any advice - especially with a simple code example - would be much appreciated.

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
RaiMan (raimund-hocke) said :
#1

--- now I would like to run it in 10 tabs at the same time.
are the tab areas visible at the same time on the screen?
Is it really a parallel action (all tabs are working concurrently and might produce the same popup at any time?)

Revision history for this message
tjonnyc (tjonnyc) said :
#2

The browser window is open & visible. Each tab can be switched to at any time.

The app is running concurrently, and may or may not produce the popups at the same time. But the timing doesn't matter - the popup will stay on the screen indefinitely until clicked, so even if it appears at the same time in all 10 tabs, that's fine, it will wait to be clicked.

Basically, picture Farmville or a similar game playing in 10 Facebook accounts. Some things get done & display a popup ("Crops ready") - the popup can be clicked 1 second or 10 minutes after it shows up, it doesn't matter when, as long as it's clicked eventually.

Revision history for this message
RaiMan (raimund-hocke) said :
#3

the solution for such situations normally is to delegate the processing of the popup to a thread/subprocess, that works concurrently with the main workflow.
There are many possible solutions for that. The challenge is, to coordinate the usage of mouse and keyboard between main and sub. The easiest implementation is to simply run a second script for popup handling from commandline in parallel.

Sikuli has the observe feature, that can be run in background (only the search works in parallel, the processing in the handler is blocking the main workflow).
Here you have a similar challenge: Since the handler might take over at any time, it might interfere with the main workflow according to the current mouse movement. This problem is not solved in Sikuli yet.

Can you help with this problem?

Provide an answer of your own, or ask tjonnyc for more information if necessary.

To post a message you must log in.