简体   繁体   中英

Checking if an application is already open with Sikuli

I'm creating a script in Sikuli for automated testing but have come across what seems a basic issue that I cannot seem to find a workaround for.

The problem I have is that I am trying to use 2 different apps for the script I am working on. To be exact, if the applications are already open, the program fails to focus on them and tries to run onto the next couple of lines

I have read through the limited documentation Sikuli has online and seen many other's similar issues but I cannot apply any of that to fix this issue.

Code:

appone = App("C:\Program Files (x86)\appone.exe")
apptwo = App("C:\Program Files (x86)\apptwo.exe")

if(appone.isRunning(3)):
    appone.focus()
else:
    appone.open()

if(apptwo.isRunning(3)):
    #do nothing#
else:
    apptwo.open()

wait(5)

click("image.png")

I have tried using image recognition to check the window's taskbar to see if the app is running but that throws out other errors as well.

Appone is the main application running which I am using Sikuli for, and apptwo is a helper application that needs to be running for appone to do what I need it to do.

What is the best way to solve this issue?

EDIT: I found a great solution that I tweaked to fit my situation from the answer of this thread: Check if Window is already exist , then make the window as active else open

I'm guessing the issue could be when you are using the app .exe location to identify if the app is running maybe. Could you try checking if the same is working if you use the window title to check if the app isRunning instead of .exe path. Please find an example below:

if(App("Untitled - Notepad").isRunning() == True):
  print "App found!"
  App("Untitled - Notepad").focus()
else:
  print "App not found!"
  App.open("Notepad.exe").focus()

Also, i got this to work in Sikuli 1.1.4 in case if you are wondering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM