[1.1.0] Linux: App.isRunning always reports false --- not yet implemented

Asked by Divick on 2016-04-07

Here is the code that I am trying to run on Linux with sikuli 1.1.0:

<code>
firefoxApp = App("firefox")
App.open("firefox")
while not firefoxApp.isRunning():
    print "Waiting for firefox.isRunning", firefoxApp.isRunning()
    wait(1)

firefoxApp.focus()
</code>

With this code, I see that it keeps on waiting for the app as firefoxApp.isRunning reports false even though the "firefox" launches fine. This code is similar to what is suggested in another question: https://answers.launchpad.net/sikuli/+question/274127.

If I change my code to following:
<code>
firefoxApp = App("firefox")
firefox = App.open("firefox")
while not firefox.isRunning():
    print "Waiting for firefox.isRunning", firefox.isRunning()
    wait(1)

firefoxApp.focus()
...
...
firefoxApp.close()
</code>

it complains with message:

[error] script [ /home/divick/work/server/tests.sikuli ] stopped with error in line 7
[error] AttributeError ( 'NoneType' object has no attribute '__exit__' )

I have tried all sort of combinations but it has issues one way or another. The code and documentation doesn't seem to match. I would appreciate any help.

Thanks,
Divick

Question information

Language:
English Edit question
Status:
Open
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Last query:
2016-04-08
Last reply:
2016-04-08
Karl (k-d) said : #1

Assuming you're using Windows, try this:
print "my.isRunning:", myApp.isRunning()
myApp = App("notepad")
print "my.isRunning:", myApp.isRunning()
App.open("notepad")
print "my.isRunning:", myApp.isRunning()
while not myApp.isRunning():
    print "my.isRunning:", myApp.isRunning()
    wait(1)
print "my.isRunning:", myApp.isRunning()
myApp.focus()
print "my.isRunning:", myApp.isRunning()

Here is my output:
my.isRunning:
False
my.isRunning:
False
[log] App.open [18252:notepad]
my.isRunning:
True
my.isRunning:
True
[log] App.focus: [18252:notepad.exe]
my.isRunning:
True

The problem may be with firefox.

Divick (divick-kishore) said : #2

No I am running this on linux. I also tried with another application like gedit but I still see this behavior. I guess sikuli is broken in revision 1.1.0.

Thanks for your answer anyways.

RaiMan (raimund-hocke) said : #3

Sorry, but isRunning() is not yet implemented on Linux.

It should issue an appropriate error message or at least be mentioned in the docs.

anyway you should work with one app instance only:
<code>
firefox = App("firefox")
firefox.open()
while not firefox.isRunning():
    print "Waiting for firefox.isRunning"
    wait(1)

firefox.focus()
...
...
firefox.close()
</code>

instead of isRunning() you might try with hasWindow(), which should work on Linux.

Divick (divick-kishore) said : #4

Thanks for your response RaiMan but now with the following code:

<code>
firefox = App("firefox")

print firefox.hasWindow()
if firefox.hasWindow():
    firefox.focus()
else:
    firefox.open()
    print firefox.hasWindow()
    firefox.focus()

with firefox.window():
    print "Now trying to type in the address"
    type('l', KEY_CTRL)
    type("some-url" + Key.ENTER)
    wait("1460032228591.png", 30)

firefox.close()
</code>

it shows the following error:

/home/divick/work/cloudzilla/server/tests.sikuli
[debug] App.create: [-1:firefox]
False
[debug] App.open [13418:firefox]
False
[debug] App.focus: [1:firefox]
[error] script [ /home/divick/work/cloudzilla/server/tests.sikuli ] stopped with error in line 9
[error] AttributeError ( 'NoneType' object has no attribute '__exit__' )

where the line number 9 is firefox.focus()

So something is not right here.

RaiMan (raimund-hocke) said : #5

the problem is the with: statement, which needs a Region object on the Python script level (firefox.window() returns a Region object from the Java level, that does not know about the with: feature).

try
with Region(firefox.window()):

or do not use with.

Divick (divick-kishore) said : #6

With your suggestion, it still does not work. It gives the following error:

[debug] App.create: [-1:firefox]
False
[debug] App.open [14172:firefox]
False
[debug] App.focus: [1:firefox]
[error] script [ /home/divick/work/cloudzilla/server/tests.sikuli ] stopped with error in line 9
[error] java.lang.NullPointerException ( java.lang.NullPointerException )

And if I remove with statement, then it opens the browser and instead of typing in the browser window it starts to type in the terminal itself. Making it wait fixes the issue but then it becomes dependent upon a fixed wait time. If i wait for firefox.hasWindow() then it keeps waiting indefinitely.

RaiMan (raimund-hocke) said : #7

ok, then you have to do it this way (apparently hasWindow() does not work on Linux either, sorry for that).

firefox = App("firefox")
firefox.focus() # should start it if not running yet
while not firefox.window():
    wait(1)
ffWindow = Region(firefox.window())
# now use ffWindow

Divick (divick-kishore) said : #8

With this suggestion, it still waits indefinitely. Code:

<code>
firefox = App("firefox")
firefox.focus()

while not firefox.window():
    print "Waiting for firefox window..."
    wait(1)

ffWindow = Region(firefox.window())
print "Now trying to type in the address"
type('l', KEY_CTRL)
type("some-url" + Key.ENTER)
wait("1460032228591.png", 30)

firefox.close()
</code>

[debug] App.create: [-1:firefox]
[debug] App.focus: [1:firefox]
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
Waiting for firefox window...
...

Divick (divick-kishore) said : #9

Forgot to mention that firefox.focus() does not even open the application.

RaiMan (raimund-hocke) said : #10

again sorry, but currently I have no possibilities to test on Linux.

Internally the command wmctrl is used, to evaluate the app and its attributes.

does FF start up?

Look, what wmctrl reports about FF from commandline.

Divick (divick-kishore) said : #11

No with firefox.focus(), firefox does not start.

Also when running wmctrl I see:
wmctrl -l

...
...
0x044000aa 0 divick-desktop wmctrl user documentation | spiralofhope - Mozilla Firefox

So it seems that the app name and title does not match, which is why it fails?

Can you help with this problem?

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

To post a message you must log in.