wx.PostEvent(element, wx.CommandEvent(wx.EVT_BUTTON._getEvtType(), element.GetId()))
wx.Yield()
Currently, I am stuck with emitting events for TextCtrls.
I have tried to...
* Post a key event.
charHookEvent = wx.KeyEvent(wx.EVT_CHAR_HOOK._getEvtType())
charHookEvent.SetEventObject(element)
event = DummyKeyEvent(wx.EVT_KEY_DOWN._getEvtType())The corresponding function in my dialog is called, however, the keycode is 0 and I have no chance to set it (I tried to override the KeyEvent and override the methods GetKeyCode() etc.)* I tried to hand the KeyEvent over to <TextCtrl>.EmulateKeyPress, but this somehow does nothing.* I took a look at wx.UIActionSimulator. This works for me if the dialog is shown. But if the dialog is not shown, the function outputs text to my IDE (or whatever other application currently has the focus).A third way would be to directly call SetValue, but than I may have a different behaviour of the dialog in my test. The disadvantage is, that I cannot test keyboard shortcuts like Ctrl+S etc. like this.Is there anything I am missing?Thank you for your help and best regards
Hello again,I am trying to test my dialogs in wxPython programmatically. For this, I am emitting the events of wxPython like this:wx.PostEvent(element, wx.CommandEvent(wx.EVT_BUTTON._getEvtType(), element.GetId()))wx.Yield()Currently, I am stuck with emitting events for TextCtrls.I have tried to...* Post a key event.charHookEvent = wx.KeyEvent(wx.EVT_CHAR_HOOK._getEvtType())
charHookEvent.SetEventObject(element)
event = DummyKeyEvent(wx.EVT_KEY_DOWN._getEvtType())The corresponding function in my dialog is called, however, the keycode is 0 and I have no chance to set it (I tried to override the KeyEvent and override the methods GetKeyCode() etc.)
* I tried to hand the KeyEvent over to <TextCtrl>.EmulateKeyPress, but this somehow does nothing.* I took a look at wx.UIActionSimulator. This works for me if the dialog is shown. But if the dialog is not shown, the function outputs text to my IDE (or whatever other application currently has the focus).A third way would be to directly call SetValue, but than I may have a different behaviour of the dialog in my test. The disadvantage is, that I cannot test keyboard shortcuts like Ctrl+S etc. like this.Is there anything I am missing?
I have seen in some Javascript frameworks and enzyme, that testing the GUI without real GUI can work quite well. I was surprised that this also works good in wxpython, exspecially for buttons, layouting, resizing etc. So for "dumb" events - at the moment. And of course for a lot of the logic (like "is the data really transferred to my data object if I press the OK button").
I try to manipulate the GUI the way the user would do, as far as possible. In the best case I would be able to detect forgotten event.Skip() commands that are not propagated to the parent, among other things of course.
And maybe later write some generic tests that can be applied to any dialog (does F1 open the help, does escape close the dialog from every input element, does pressing return behave the same way as hitting the OK button, is the dialog not too big, is it centered on screen etc.)
These are tasks that can be easily applied if the GUI tests are written programmatically, but hard to implement with "real" UI testing applications like Ranorex or others.