import os
import sys
def main():
aut = "addressbook.app"
path = os.environ["SQUISH_PREFIX"] + "/examples/qt/addressbook"
registerAUT(aut, path)
# Start first application, store application context
# and move/resize to avoid overlap:
ctx1 = startApplication('"' + aut + '"')
win = waitForObject({"type": "MainWindow", "visible": 1})
win.move(50, 30)
win.setFixedHeight(200)
# Give some time for move to take place:
snooze(0.5)
# Get source object screen coordinates as int values
# (extracting when application context of second
# application is active is too late):
source = waitForObject({"text": "New", "type": "QToolButton", "visible": 1})
pos1 = source.mapToGlobal(QPoint(0, 0))
source_x = pos1.x
source_y = pos1.x
# Start second application, store application context
# and move/resize to avoid overlap:
ctx2 = startApplication('"' + aut + '"')
win = waitForObject({"type": "MainWindow", "visible": 1})
win.move(50, 270)
win.setFixedHeight(200)
# Give some time for move to take place:
snooze(0.5)
# Get target object reference and screen coordinates:
target = waitForObject({"text": "New", "type": "QToolButton", "visible": 1})
pos2 = target.mapToGlobal(QPoint(0, 0))
target_x = pos2.x
target_y = pos2.y
# Perform drag & drop "relative" to target:
x_offset = -target_x + source_x
y_offset = -target_y + source_y
dragAndDrop(target, x_offset + 20, y_offset + 20, target, 20, 20, Qt.CopyAction)
snooze(3)
def registerAUT(aut, path, squishserver_host="localhost", squishserver_port=3000):
s = '"' + os.environ["SQUISH_PREFIX"] + '/bin/squishserver"'
s += ' --host ' + squishserver_host
s += ' port=' + str(squishserver_port)
s += ' --config addAUT "' + aut + '" "' + path + '"'
if sys.platform == "win32" and s.endswith('"'):
s = '"' + s
os.system(s)