1

wxPython アプリケーションのテスト中に開いたダイアログを処理するには?

誰かがすでに同様の問題を抱えていたので:

問題は、アプリがモーダル ダイアログを開始するとすぐに、モーダル ダイアログが終了するまでコントロールが返されないことです。モーダル ダイアログが終了すると、テスト スクリプトがデータを入力するには遅すぎます。

一般的に、次のワークフローのテスト ケースを書きたいと思います。

  1. ユーザーがボタン「SomeProcessing」を押す
  2. 開いたダイアログで、ユーザーは「選択 1」を選択し、OK を押します
  3. データは選択に基づいて処理され、既知の結果と比較されます ( 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()  
4

2 に答える 2

3

GUI テスト用に、次のアプリケーションのいずれかをチェックアウトすることをお勧めします。

于 2012-08-10T17:30:38.783 に答える
0

誰かが同じ問題に遭遇した場合に備えて、解決策を投稿してください。

def test():
    app = wx.PySimpleApp()
    mf = MyFrame(None, 'testgui')
    for item in mf.GetChildren():
        if item.GetLabel() == 'SomeProcessing':
            btn = item
            break

    def clickOK():
        dlg = wx.GetActiveWindow()
        dlg.sel1.SetValue(True)
        clickEvent = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, wx.ID_OK)
        dlg.ProcessEvent(clickEvent)

    event = wx.CommandEvent(wx.wxEVT_COMMAND_BUTTON_CLICKED, btn.GetId())   
    wx.CallAfter(clickOK)
    mf.GetEventHandler().ProcessEvent(event)

    print 'data_after_processing:', mf.data_after_processing
    mf.Destroy()
于 2012-08-14T12:19:43.957 に答える