tests/ide_tests/sikuliberemiz.py
author Edouard Tisserant <edouard.tisserant@gmail.com>
Tue, 15 Nov 2022 20:43:39 +0100
branchwxPython4
changeset 3677 6d9040e07c32
parent 3675 d331eb981b44
child 3679 b6bca75bf3fa
permissions -rw-r--r--
OPC-UA: only support the encryption policy selected in config.

By default open62541 client accepts all supported policies, but in makes problem
when negociating with some servers while most clients seems to only support
one policy at a time.
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
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
     6
import traceback
3668
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
     7
import signal
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
     8
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
     9
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
    10
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    11
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
    12
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
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
    14
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
    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
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
    17
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
    18
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
class KBDShortcut:
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    20
    """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
    21
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
    example:
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    23
        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
    24
        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
    25
    """
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
    26
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    27
    fkeys = {"Stop":     sikuli.Key.F4,
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    28
             "Run":      sikuli.Key.F5,
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    29
             "Transfer": sikuli.Key.F6,
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    30
             "Connect":  sikuli.Key.F7,
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    31
             "Clean":    sikuli.Key.F9,
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    32
             "Build":    sikuli.Key.F11,
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    33
             "Save":     ("s",sikuli.Key.CTRL),
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    34
             "New":      ("n",sikuli.Key.CTRL),
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    35
             "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
    36
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
    def __init__(self, app):
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
    38
        self.app = app
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
    39
    
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
    40
    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
    41
        fkey = self.fkeys[name]
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    42
        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
    43
            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
    44
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
        def PressShortCut():
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
    46
            self.app.sikuliapp.focus()
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    47
            sikuli.type(*fkey)
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
    48
            self.app.ReportText("Sending " + name + " shortcut")
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
    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
        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
    51
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
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
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
    54
    "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
    55
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    56
    def __init__(self):
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    57
        """
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    58
        Parameters: 
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    59
            app (class BeremizApp)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    60
        """
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    61
        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
    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
        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
    64
        
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
        # 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
    66
        # 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
    67
        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
    68
        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
    69
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
    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
    71
        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
    72
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
    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
    74
        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
    75
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    76
    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
    77
        """
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
        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
    79
        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
    80
            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
    81
            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
    82
        """
3437
ce366d67a5b7 Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3432
diff changeset
    83
        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
    84
        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
    85
            self.idechanged = False
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
    86
            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
    87
            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
    88
                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
    89
            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
    90
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
    91
        self.ReportScreenShot("UI is idle" if c != 0 else "UI is not idle")
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
    92
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
    93
        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
    94
            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
    95
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
    96
 
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
    97
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
    98
    "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
    99
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   100
    def __init__(self):
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   101
        """
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   102
        Parameters: 
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   103
            app (class BeremizApp)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   104
        """
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
   105
        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
   106
3437
ce366d67a5b7 Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3432
diff changeset
   107
        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
   108
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   109
        self.pattern = None
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   110
        self.success_event = Event()
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   111
3670
cfb2b05b68c4 Tests: UI tests now avoid polling stdout if process didn't start.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3669
diff changeset
   112
        if self.proc is not None:
cfb2b05b68c4 Tests: UI tests now avoid polling stdout if process didn't start.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3669
diff changeset
   113
            self.thread = Thread(target = self._waitStdoutProc).start()
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
   114
3528
c269f256a7c4 tests: add (broken) debug_project test, fix edit_project
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3448
diff changeset
   115
    def __del__(self):
c269f256a7c4 tests: add (broken) debug_project test, fix edit_project
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3448
diff changeset
   116
        pass  # self.thread.join() ?
c269f256a7c4 tests: add (broken) debug_project test, fix edit_project
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3448
diff changeset
   117
3432
40b8b2ffb3fd Tests: Various enhancements in Makefile and sikuli common python code.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3431
diff changeset
   118
    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
   119
        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
   120
            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
   121
            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
   122
                break
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   123
            self.ReportOutput(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
   124
            self.event.set()
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   125
            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
   126
                sys.stdout.write("found pattern in '" + a +"'")
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   127
                self.success_event.set()
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
    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
   130
        """
ce366d67a5b7 Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3432
diff changeset
   131
        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
   132
        Parameters: 
ce366d67a5b7 Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3432
diff changeset
   133
            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
   134
        """
ce366d67a5b7 Tests: Enhance robustness of stdout driven waiting state in Sikuli based tests.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3432
diff changeset
   135
        start_time = timesec()
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   136
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   137
        wait_result = self.event.wait(timeout)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   138
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   139
        self.ReportScreenShot("stdout changed" if wait_result else "stdout didn't change")
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   140
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   141
        if wait_result:
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   142
            self.event.clear()
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   143
        else:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   144
            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
   145
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   146
        self.waitIdleStdout(period, timeout - (timesec() - start_time))
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   147
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   148
    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
   149
        """
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
   150
        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
   151
        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
   152
            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
   153
            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
   154
        """
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   155
        end_time = timesec() + timeout
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   156
        self.event.clear()
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   157
        while timesec() < end_time:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   158
            if self.event.wait(period):
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   159
                # no timeout -> got event -> not idle -> loop again
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   160
                self.event.clear()
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   161
            else:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   162
                # timeout -> no event -> idle -> exit
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   163
                self.ReportScreenShot("stdout is idle")
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   164
                return True
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   165
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   166
        self.ReportScreenShot("stdout did not idle")
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   167
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   168
        raise Exception("Stdout did not idle before timeout")
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   169
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   170
    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
   171
        found = 0
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   172
        self.pattern = pattern
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   173
        end_time = timesec() + timeout
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
   174
        while True:
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   175
            remain = end_time - timesec()
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   176
            if remain <= 0 :
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   177
                res = False
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   178
                break
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
            res = self.success_event.wait(remain)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   181
            if res:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   182
                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
   183
                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
   184
                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
   185
                    break
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   186
        self.pattern = None
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   187
        self.ReportScreenShot("found pattern" if res else "pattern not found")
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   188
        return res
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
class BeremizApp(IDEIdleObserver, stdoutIdleObserver):
3669
ca25c686cd97 Tests: UI tests can now load projects from tests/projects
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3668
diff changeset
   191
    def __init__(self, projectpath=None, exemple=None, testproject=None):
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   192
        """
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   193
        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
   194
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   195
            Parameters: 
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   196
                projectpath (str): path to project to open
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   197
                exemple (str): path relative to exemples directory
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   198
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   199
            Returns:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   200
                Sikuli App class instance
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   201
        """
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   202
3562
165dc0e97f1d tests: Change OCR options to be more reliable on small fonts.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3547
diff changeset
   203
        sikuli.OCR.Options().smallFont()
165dc0e97f1d tests: Change OCR options to be more reliable on small fonts.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3547
diff changeset
   204
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   205
        self.screenshotnum = 0
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   206
        self.starttime = timesec()
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   207
        self.screen = sikuli.Screen()
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   208
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   209
        self.report = open("report.html", "w")
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   210
        self.report.write("""<!doctype html>
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   211
<html>
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   212
  <head>
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   213
    <meta charset="utf-8">
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   214
    <meta name="color-scheme" content="light dark">
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   215
    <title>Test report</title>
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   216
  </head>
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   217
  <body>
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   218
""")
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   219
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   220
        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
   221
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   222
        if exemple is not None:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   223
            command.append(opj(beremiz_path,"exemples",exemple))
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   224
        elif projectpath is not None:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   225
            command.append(projectpath)
3669
ca25c686cd97 Tests: UI tests can now load projects from tests/projects
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3668
diff changeset
   226
        elif testproject is not None:
ca25c686cd97 Tests: UI tests can now load projects from tests/projects
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3668
diff changeset
   227
            command.append(opj(beremiz_path,"tests","projects",testproject))
ca25c686cd97 Tests: UI tests can now load projects from tests/projects
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3668
diff changeset
   228
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   229
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   230
        # 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
   231
        # 
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   232
        # Workaround : - use subprocess module to spawn IDE process,
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   233
        #              - 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
   234
        #              - pass exact window title to App class constructor
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   235
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   236
        self.ReportText("Launching " + repr(command))
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   237
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   238
        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
   239
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   240
        # Window are macthed against process' PID
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   241
        ppid = self.proc.pid
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   242
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   243
        # Timeout 5s
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   244
        c = 50
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   245
        while c > 0:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   246
            # equiv to "wmctrl -l -p | grep $pid"
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   247
            try:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   248
                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
   249
            except subprocess.CalledProcessError:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   250
                wlist = []
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   251
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   252
            # 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
   253
            # beremiz splashcreen has no title
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   254
            # wait until main window is visible
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   255
            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
   256
                windowID,_zero,wpid,_XID,wtitle = wlist[0] 
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   257
                break
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   258
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   259
            sikuli.wait(0.1)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   260
            c = c - 1
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   261
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   262
        if c == 0:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   263
            raise Exception("Couldn't find Beremiz window")
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   264
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   265
        # Maximize window x and y
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   266
        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
   267
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   268
        # 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
   269
        self.sikuliapp = sikuli.switchApp(wtitle)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   270
        self.k = KBDShortcut(self)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   271
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   272
        IDEIdleObserver.__init__(self)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   273
        stdoutIdleObserver.__init__(self)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   274
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   275
        # stubs for common sikuli calls to allow adding hooks later
3528
c269f256a7c4 tests: add (broken) debug_project test, fix edit_project
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3448
diff changeset
   276
        for name in ["click","doubleClick","type","rightClick","wait"]:
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   277
            def makeMyMeth(n):
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   278
                def myMeth(*args, **kwargs):
3534
7f62da4362fd tests: nore details, please
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3528
diff changeset
   279
                    self.ReportScreenShot("Begin: " + n + "(" + repr(args) + "," + repr(kwargs) + ")")
3544
f2dff88db448 tests: IDE: force reporting screenshot even after failing command
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3534
diff changeset
   280
                    try:
f2dff88db448 tests: IDE: force reporting screenshot even after failing command
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3534
diff changeset
   281
                        getattr(sikuli, n)(*args, **kwargs)
f2dff88db448 tests: IDE: force reporting screenshot even after failing command
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3534
diff changeset
   282
                    finally:
f2dff88db448 tests: IDE: force reporting screenshot even after failing command
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3534
diff changeset
   283
                        self.ReportScreenShot("end: " + n + "(" + repr(args) + "," + repr(kwargs) + ")")
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   284
                return myMeth
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   285
            setattr(self, name, makeMyMeth(name))
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   286
3671
973a7681f206 Tests: Add 'dragNdrop' for UI tests with slower begining than sikuli's dragDrop
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3670
diff changeset
   287
    def dragNdrop(self, src, dst):
973a7681f206 Tests: Add 'dragNdrop' for UI tests with slower begining than sikuli's dragDrop
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3670
diff changeset
   288
        sikuli.drag(src)
973a7681f206 Tests: Add 'dragNdrop' for UI tests with slower begining than sikuli's dragDrop
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3670
diff changeset
   289
        sikuli.mouseMove(5,0)
973a7681f206 Tests: Add 'dragNdrop' for UI tests with slower begining than sikuli's dragDrop
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3670
diff changeset
   290
        sikuli.dropAt(dst)
973a7681f206 Tests: Add 'dragNdrop' for UI tests with slower begining than sikuli's dragDrop
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3670
diff changeset
   291
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   292
    def close(self):
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   293
        self.sikuliapp.close()
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   294
        self.sikuliapp = None
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   295
        self.report.write("""
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   296
  </body>
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   297
</html>""")
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   298
        self.report.close()
3446
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   299
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   300
    def __del__(self):
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   301
        if self.sikuliapp is not None:
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   302
            self.sikuliapp.close()
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   303
        IDEIdleObserver.__del__(self)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   304
        stdoutIdleObserver.__del__(self)
de8cc85b688a Tests: refactored sikuli based test
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3437
diff changeset
   305
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   306
    def ReportScreenShot(self, msg):
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   307
        elapsed = "%.3fs: "%(timesec() - self.starttime)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   308
        fname = "capture"+str(self.screenshotnum)+".png"
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   309
        cap = self.screen.capture(self.r)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   310
        cap.save(".", fname)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   311
        self.screenshotnum = self.screenshotnum + 1
3448
523f6fcc7a28 Tests: Fix missing <br/> in generated html report.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3447
diff changeset
   312
        self.report.write( "<p>" + elapsed + msg + "<br/><img src=\""+ fname + "\">" + "</p>")
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   313
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   314
    def ReportText(self, text):
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   315
        elapsed = "%.3fs: "%(timesec() - self.starttime)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   316
        self.report.write("<p>" + elapsed + text + "</p>")
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   317
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   318
    def ReportOutput(self, text):
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   319
        elapsed = "%.3fs: "%(timesec() - self.starttime)
3675
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   320
        sys.stdout.write(elapsed + text)
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   321
        self.report.write("<pre>" + elapsed + text + "</pre>")
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   322
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   323
3675
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   324
class AuxiliaryProcess(stdoutIdleObserver):
3668
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   325
    def __init__(self, beremiz_app, command):
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   326
        self.app = beremiz_app
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   327
        self.app.ReportText("Launching process " + repr(command))
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   328
        self.proc = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=0)
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   329
        self.app.ReportText("Launched process " + repr(command) + " PID: " + str(self.proc.pid))
3675
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   330
        stdoutIdleObserver.__init__(self)
3668
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   331
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   332
    def close(self):
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   333
        if self.proc is not None:
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   334
            proc = self.proc
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   335
            self.proc = None
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   336
            # self.proc.stdout.close()
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   337
            self.app.ReportText("Kill process PID: " + str(proc.pid))
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   338
            try:
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   339
                os.kill(proc.pid, signal.SIGTERM)
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   340
            except OSError:
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   341
                pass
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   342
            proc.wait()
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   343
            # self.thread.join()
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   344
3675
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   345
    def ReportOutput(self, text):
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   346
        self.app.ReportOutput("Aux: "+text)
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   347
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   348
    def ReportScreenShot(self, msg):
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   349
        self.app.ReportOutput("Aux: "+msg)
d331eb981b44 Tests: IDE: add stdout monitoring capabilities to auxiliary process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3671
diff changeset
   350
3668
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   351
    def __del__(self):
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   352
        self.close()
142c268124ab Tests: add command for UI tests to launch and close Auxiliary Process
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3562
diff changeset
   353
3447
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   354
def run_test(func, *args, **kwargs):
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   355
    app = BeremizApp(*args, **kwargs)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   356
    try:
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   357
        success = func(app)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   358
    except:
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   359
        # sadly, sys.excepthook is broken in sikuli/jython 
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   360
        # purpose of this run_test function is to work around it.
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   361
        # and catch exception cleanly anyhow
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   362
        e_type, e_value, e_traceback = sys.exc_info()
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   363
        err_msg = "\n".join(traceback.format_exception(e_type, e_value, e_traceback))
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   364
        app.ReportOutput(err_msg)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   365
        success = False
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   366
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   367
    app.close()
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   368
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   369
    if success:
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   370
        sikuli.exit(0)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   371
    else:
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   372
        sikuli.exit(1)
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   373
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   374
65c5f66e9298 Tests: add HTML report generation and a workaround to bad exception handling in sikuli.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 3446
diff changeset
   375