Quantcast
Channel: froglogic
Viewing all articles
Browse latest Browse all 398

Restarting an Attachable AUT after a failure

$
0
0

With Squish, attaching to the already running application might be beneficial in many cases. E.g. this approach might be worth considering if the application startup time is long.

A problem occurs when one of the test cases fails and leaves the AUT in an unknown state. This might cause a failure of all following test cases.

Restarting the application in such a case might be a solution for this issue. To do that we would like to propose using cleanup() and init() functions. The following test script was prepared for Windows but it might be easily modified and used on other operating systems.

import os
import subprocess
  
def kill_aut():
    os.system("taskkill /im addressbook.exe")
    os.system("taskkill /im startaut.exe")
    
def start_aut():
    subprocess.Popen([r"D:\Squish\Qt\Squish6.3.0-Qt5.9\bin\startaut.exe",
                      "--port=7777",
                      r"D:\Squish\Qt\Squish6.3.0-Qt5.9\examples\qt\addressbook\addressbook.exe"
                      ])
        
    
def init():
    proc = subprocess.Popen(['tasklist', '/fo', 'list'],
                           stdout=subprocess.PIPE)
    out, err = proc.communicate()
    #Check if AUT and startaut.exe are running
    if ("addressbook.exe" not in out) or ("startaut.exe" not in out):
        kill_aut()
        start_aut()

def main():
    attachToApplication("addressbook")
    clickButton(waitForObject(":Address Book.New_QToolButton"))
    clickButton(waitForObject(":Address Book - Unnamed.Add_QToolButton"))
    clickButton(waitForObject(":Address Book - Add.Cancel_QPushButton"))
    
def cleanup():
    #Check if results contain FAIL, ERROR or FATAL Entry
    if test.resultCount('fails') > 0 or test.resultCount('errors') > 0 or test.resultCount('fatals') > 0:
        kill_aut()
    

Please note that you can use a global cleanup() and init() to implement this solution.

The post Restarting an Attachable AUT after a failure appeared first on froglogic.


Viewing all articles
Browse latest Browse all 398

Trending Articles