2017 bis heute 2016 2015 2014 | 2013 | 2012 | 2011 2010 2009 | 2008 | 2007

(ältere Archiveinträge vor 2007 nicht dargestellt, aber in der Suche enthalten)

Mailingliste - Einträge 2007


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[QF-Test] Handling AWT menus


  • Subject: [QF-Test] Handling AWT menus
  • From: "Robert Lahmer, QFS support" <support@?.de>
  • Date: Thu, 26 Apr 2007 22:04:08 +0200


Dear QF-Test users,

even though QF-Test does not support AWT menus, it is possible to trigger
the corresponding actions for them by means of a Jython SUT script. Because
it is not unlikely that a modal dialog is displayed subsequently, you
should take care to implement the simulated click on a menu item in an
asynchronous way. Here are two proposals how to do this:


1) using postEvent()

from java.awt.event import ActionEvent
from java.awt import Toolkit

# change the frameID accordingly
frameID = "frameAwt1"
f = rc.getComponent(frameID)
menubar = f.getMenuBar()
# this is the first item in the first menu
item = menubar.getMenu(0).getItem(0)

event = ActionEvent(item, ActionEvent.ACTION_PERFORMED,
item.getActionCommand())
Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event)


2) using invokeLater()

from java.awt.event import ActionEvent
from javax.swing import SwingUtilities
from java.lang import Runnable

class InvokeListeners(Runnable):
   def __init__(self, event, listeners):
       self._event = event
       self._listeners = listeners
   def run(self):
       for i in range(len(self._listeners)):
           self._listeners[i].actionPerformed(self._event)

frameID = "frameAwt1"
f = rc.getComponent(frameID)
menubar = f.getMenuBar()
item = menubar.getMenu(0).getItem(0)

event = ActionEvent(item, ActionEvent.ACTION_PERFORMED,
item.getActionCommand())
listeners = item.getActionListeners()
SwingUtilities.invokeLater(InvokeListeners(event, listeners))


Best Regards,
   Robert


--
Robert Lahmer
Quality First Software GmbH                http://www.qfs.de
Tulpenstr. 41                           Tel: +49 8171 919874
DE-82538 Geretsried                     Fax: +49 8171 919876
GF: Gregor Schmid, Karlheinz Kellerer     HRB München 140833