author | Edouard Tisserant <edouard.tisserant@gmail.com> |
Tue, 29 Mar 2022 08:50:01 +0200 | |
branch | wxPython4 |
changeset 3446 | de8cc85b688a |
parent 3437 | ce366d67a5b7 |
child 3447 | 65c5f66e9298 |
permissions | -rw-r--r-- |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
1 |
"Commons definitions for sikuli based beremiz IDE GUI tests" |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
2 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
3 |
import os |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
4 |
import sys |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
5 |
import subprocess |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
6 |
from threading import Thread, Event, Lock |
3437
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
7 |
from time import time as timesec |
3432
40b8b2ffb3fd
Tests: Various enhancements in Makefile and sikuli common python code.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3431
diff
changeset
|
8 |
|
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
9 |
import sikuli |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
10 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
11 |
beremiz_path = os.environ["BEREMIZPATH"] |
3431
5bcef31e276d
Tests: Added BEREMIZPYTHONPATH to point to Python interpreter to use for tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3430
diff
changeset
|
12 |
python_bin = os.environ.get("BEREMIZPYTHONPATH", "/usr/bin/python") |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
13 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
14 |
opj = os.path.join |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
15 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
16 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
17 |
class KBDShortcut: |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
18 |
"""Send shortut to app by calling corresponding methods. |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
19 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
20 |
example: |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
21 |
k = KBDShortcut() |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
22 |
k.Clean() |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
23 |
""" |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
24 |
|
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
25 |
fkeys = {"Stop": sikuli.Key.F4, |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
26 |
"Run": sikuli.Key.F5, |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
27 |
"Transfer": sikuli.Key.F6, |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
28 |
"Connect": sikuli.Key.F7, |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
29 |
"Clean": sikuli.Key.F9, |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
30 |
"Build": sikuli.Key.F11, |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
31 |
"Save": ("s",sikuli.Key.CTRL), |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
32 |
"New": ("n",sikuli.Key.CTRL), |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
33 |
"Address": ("l",sikuli.Key.CTRL)} # to reach address bar in GTK's file selector |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
34 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
35 |
def __init__(self, app): |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
36 |
self.app = app.sikuliapp |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
37 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
38 |
def __getattr__(self, name): |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
39 |
fkey = self.fkeys[name] |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
40 |
if type(fkey) != tuple: |
3432
40b8b2ffb3fd
Tests: Various enhancements in Makefile and sikuli common python code.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3431
diff
changeset
|
41 |
fkey = (fkey,) |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
42 |
app = self.app |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
43 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
44 |
def PressShortCut(): |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
45 |
app.focus() |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
46 |
sikuli.type(*fkey) |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
47 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
48 |
return PressShortCut |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
49 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
50 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
51 |
class IDEIdleObserver: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
52 |
"Detects when IDE is idle. This is particularly handy when staring an operation and witing for the en of it." |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
53 |
|
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
54 |
def __init__(self): |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
55 |
""" |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
56 |
Parameters: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
57 |
app (class BeremizApp) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
58 |
""" |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
59 |
self.r = sikuli.Region(self.sikuliapp.window()) |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
60 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
61 |
self.idechanged = False |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
62 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
63 |
# 200 was selected because default 50 was still catching cursor blinking in console |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
64 |
# FIXME : remove blinking cursor in console |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
65 |
self.r.onChange(200,self._OnIDEWindowChange) |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
66 |
self.r.observeInBackground() |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
67 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
68 |
def __del__(self): |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
69 |
self.r.stopObserver() |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
70 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
71 |
def _OnIDEWindowChange(self, event): |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
72 |
self.idechanged = True |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
73 |
|
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
74 |
def WaitIdleUI(self, period=1, timeout=15): |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
75 |
""" |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
76 |
Wait for IDE to stop changing |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
77 |
Parameters: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
78 |
period (int): how many seconds with no change to consider idle |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
79 |
timeout (int): how long to wait for idle, in seconds |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
80 |
""" |
3437
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
81 |
c = max(timeout/period,1) |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
82 |
while c > 0: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
83 |
self.idechanged = False |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
84 |
sikuli.wait(period) |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
85 |
if not self.idechanged: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
86 |
break |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
87 |
c = c - 1 |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
88 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
89 |
if c == 0: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
90 |
raise Exception("Window did not idle before timeout") |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
91 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
92 |
|
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
93 |
class stdoutIdleObserver: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
94 |
"Detects when IDE's stdout is idle. Can be more reliable than pixel based version (false changes ?)" |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
95 |
|
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
96 |
def __init__(self): |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
97 |
""" |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
98 |
Parameters: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
99 |
app (class BeremizApp) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
100 |
""" |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
101 |
self.stdoutchanged = False |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
102 |
|
3437
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
103 |
self.event = Event() |
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
104 |
|
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
105 |
self.pattern = None |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
106 |
self.success_event = Event() |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
107 |
|
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
108 |
self.thread = Thread(target = self._waitStdoutProc).start() |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
109 |
|
3432
40b8b2ffb3fd
Tests: Various enhancements in Makefile and sikuli common python code.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3431
diff
changeset
|
110 |
def _waitStdoutProc(self): |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
111 |
while True: |
3437
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
112 |
a = self.proc.stdout.readline() |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
113 |
if len(a) == 0 or a is None: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
114 |
break |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
115 |
sys.stdout.write(a) |
3437
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
116 |
self.event.set() |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
117 |
if self.pattern is not None and a.find(self.pattern) >= 0: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
118 |
sys.stdout.write("found pattern in '" + a +"'") |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
119 |
self.success_event.set() |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
120 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
121 |
def waitForChangeAndIdleStdout(self, period=2, timeout=15): |
3437
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
122 |
""" |
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
123 |
Wait for IDE'stdout to start changing |
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
124 |
Parameters: |
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
125 |
timeout (int): how long to wait for change, in seconds |
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
126 |
""" |
ce366d67a5b7
Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3432
diff
changeset
|
127 |
start_time = timesec() |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
128 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
129 |
if self.event.wait(timeout): |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
130 |
self.event.clear() |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
131 |
else: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
132 |
raise Exception("Stdout didn't become active before timeout") |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
133 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
134 |
self.waitIdleStdout(period, timeout - (timesec() - start_time)) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
135 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
136 |
def waitIdleStdout(self, period=2, timeout=15): |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
137 |
""" |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
138 |
Wait for IDE'stdout to stop changing |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
139 |
Parameters: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
140 |
period (int): how many seconds with no change to consider idle |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
141 |
timeout (int): how long to wait for idle, in seconds |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
142 |
""" |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
143 |
end_time = timesec() + timeout |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
144 |
self.event.clear() |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
145 |
while timesec() < end_time: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
146 |
if self.event.wait(period): |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
147 |
# no timeout -> got event -> not idle -> loop again |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
148 |
self.event.clear() |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
149 |
else: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
150 |
# timeout -> no event -> idle -> exit |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
151 |
return True |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
152 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
153 |
raise Exception("Stdout did not idle before timeout") |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
154 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
155 |
def waitPatternInStdout(self, pattern, timeout, count=1): |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
156 |
found = 0 |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
157 |
self.pattern = pattern |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
158 |
end_time = timesec() + timeout |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
159 |
self.event.clear() |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
160 |
while True: |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
161 |
remain = end_time - timesec() |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
162 |
if remain <= 0 : |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
163 |
res = False |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
164 |
break |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
165 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
166 |
res = self.success_event.wait(remain) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
167 |
if res: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
168 |
self.success_event.clear() |
3424
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
169 |
found = found + 1 |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
170 |
if found >= count: |
7db96e011fe7
Tests: added tests/Makefile and a first test in tests/ide_tests. Test requires sikuli and Xvfb or Xnest.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
diff
changeset
|
171 |
break |
3446
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
172 |
self.pattern = None |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
173 |
return res |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
174 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
175 |
class BeremizApp(IDEIdleObserver, stdoutIdleObserver): |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
176 |
def __init__(self, projectpath=None, exemple=None): |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
177 |
""" |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
178 |
Starts Beremiz IDE, waits for main window to appear, maximize it. |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
179 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
180 |
Parameters: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
181 |
projectpath (str): path to project to open |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
182 |
exemple (str): path relative to exemples directory |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
183 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
184 |
Returns: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
185 |
Sikuli App class instance |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
186 |
""" |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
187 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
188 |
command = [python_bin, opj(beremiz_path,"Beremiz.py"), "--log=/dev/stdout"] |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
189 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
190 |
if exemple is not None: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
191 |
command.append(opj(beremiz_path,"exemples",exemple)) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
192 |
elif projectpath is not None: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
193 |
command.append(projectpath) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
194 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
195 |
# App class is broken in Sikuli 2.0.5: can't start process with arguments. |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
196 |
# |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
197 |
# Workaround : - use subprocess module to spawn IDE process, |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
198 |
# - use wmctrl to find IDE window details and maximize it |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
199 |
# - pass exact window title to App class constructor |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
200 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
201 |
self.proc = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=0) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
202 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
203 |
# Window are macthed against process' PID |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
204 |
ppid = self.proc.pid |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
205 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
206 |
# Timeout 5s |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
207 |
c = 50 |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
208 |
while c > 0: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
209 |
# equiv to "wmctrl -l -p | grep $pid" |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
210 |
try: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
211 |
wlist = filter(lambda l:(len(l)>2 and l[2]==str(ppid)), map(lambda s:s.split(None,4), subprocess.check_output(["wmctrl", "-l", "-p"]).splitlines())) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
212 |
except subprocess.CalledProcessError: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
213 |
wlist = [] |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
214 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
215 |
# window with no title only has 4 fields do describe it |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
216 |
# beremiz splashcreen has no title |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
217 |
# wait until main window is visible |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
218 |
if len(wlist) == 1 and len(wlist[0]) == 5: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
219 |
windowID,_zero,wpid,_XID,wtitle = wlist[0] |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
220 |
break |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
221 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
222 |
sikuli.wait(0.1) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
223 |
c = c - 1 |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
224 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
225 |
if c == 0: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
226 |
raise Exception("Couldn't find Beremiz window") |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
227 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
228 |
# Maximize window x and y |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
229 |
subprocess.check_call(["wmctrl", "-i", "-r", windowID, "-b", "add,maximized_vert,maximized_horz"]) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
230 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
231 |
# switchApp creates an App object by finding window by title, is not supposed to spawn a process |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
232 |
self.sikuliapp = sikuli.switchApp(wtitle) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
233 |
self.k = KBDShortcut(self) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
234 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
235 |
IDEIdleObserver.__init__(self) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
236 |
stdoutIdleObserver.__init__(self) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
237 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
238 |
# stubs for common sikuli calls to allow adding hooks later |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
239 |
for n in ["click","doubleClick","type"]: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
240 |
setattr(self, n, getattr(sikuli, n)) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
241 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
242 |
def close(self): |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
243 |
self.sikuliapp.close() |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
244 |
self.sikuliapp = None |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
245 |
|
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
246 |
def __del__(self): |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
247 |
if self.sikuliapp is not None: |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
248 |
self.sikuliapp.close() |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
249 |
IDEIdleObserver.__del__(self) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
250 |
stdoutIdleObserver.__del__(self) |
de8cc85b688a
Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents:
3437
diff
changeset
|
251 |