如何处理在测试wxPython应用程序时打开的对话框?
由于某人已经拥有a similar issue:
问题是,应用程序启动模式对话框后,在退出模式对话框之前,它不会返回测试脚本无法将数据输入其中为时已晚]
通常,我想为以下工作流程编写一个测试用例:
data_after_processing
)如何执行第2步,以便事情会自动发生(下面的示例打开Dlg_GetUserInput
并等待手动输入)?我对GUI测试的理解可能存在缺陷,并且不应将第3部分视为GUI测试吗?在这种情况下,我可能需要重写代码...
欢迎提出任何建议!
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title)
btn = wx.Button(self, label="SomeProcessing")
self.Bind(wx.EVT_BUTTON, self.SomeProcessing, btn)
def SomeProcessing(self,event):
self.dlg = Dlg_GetUserInput(self)
if self.dlg.ShowModal() == wx.ID_OK:
if self.dlg.sel1.GetValue():
print 'sel1 processing'
self.data_after_processing = 'boo'
if self.dlg.sel2.GetValue():
print 'sel2 processing'
self.data_after_processing = 'foo'
class Dlg_GetUserInput(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.sel1 = wx.CheckBox(self, label='Selection 1')
self.sel2 = wx.CheckBox(self, label='Selection 2')
self.OK = wx.Button(self, wx.ID_OK)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.sel1)
sizer.Add(self.sel2)
sizer.Add(self.OK)
self.SetSizer(sizer)
def test():
app = wx.PySimpleApp()
mf = MyFrame(None, 'testgui')
for item in mf.GetChildren():
if item.GetLabel() == 'SomeProcessing':
btn = item
break
event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId())
mf.GetEventHandler().ProcessEvent(event)
"""
PROBLEM: here I'd like to simulate user input
sel1 in Dlg_GetUserInput
(i.e. mf.dlg.sel1.SetValue())
and check that
data_after_processing == 'boo'
"""
mf.Destroy()
test()
如何处理在测试wxPython应用程序时打开的对话框?就像有人已经遇到过类似的问题:问题在于,应用程序启动模式对话框后,控件不会...
您可能想要检出其中一个应用程序以进行GUI测试:
发布解决方案,以防任何人遇到同一问题。