如何处理在测试 wxPython 应用程序时打开的对话框?
因为有人已经有了 a similar issue :
the problem is that as soon as the app starts a modal dialog, control does not return until the modal dialog has exited, at which time it's too late for the testing script to enter data into it
一般来说,我想为以下工作流程编写一个测试用例:
- 用户按下按钮“SomeProcessing”
- 在打开的对话框中,用户选择“选择 1”并按 OK
- 数据根据选择进行处理,并与已知结果进行比较(
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()
最佳答案
您可能想检查以下应用程序之一以进行 GUI 测试:
关于testing - 在 wxPython 应用程序的自动化测试中处理模态对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11904932/