Ejemplo n.º 1
0
class HwndWrapperMouseTests(unittest.TestCase):
    "Unit tests for mouse actions of the HwndWrapper class"

    def setUp(self):
        """Start the application set some data and ensure the application
        is in the state we want it."""

        # start the application
        self.app = Application()
        if is_x64_Python() or not is_x64_OS():
            self.app.start_(r"C:\Windows\System32\notepad.exe")
        else:
            self.app.start_(r"C:\Windows\SysWOW64\notepad.exe")

        # Get the old font
        self.app.UntitledNotepad.MenuSelect("Format->Font")

        self.old_font = self.app.Font.FontComboBox.SelectedIndex()
        self.old_font_style = self.app.Font.FontStyleCombo.SelectedIndex()

        # ensure we have the correct settings for this test
        self.app.Font.FontStyleCombo.Select(0)
        self.app.Font.FontComboBox.Select("Lucida Console")
        self.app.Font.OK.Click()

        self.dlg = self.app.Window_(title='Untitled - Notepad',
                                    class_name='Notepad')
        self.ctrl = HwndWrapper(self.dlg.Edit.handle)
        self.dlg.edit.SetEditText("Here is some text\r\n and some more")

    def tearDown(self):
        "Close the application after tests"

        # Set the old font again
        self.app.UntitledNotepad.MenuSelect("Format->Font")
        self.app.Font.FontComboBox.Select(self.old_font)
        self.app.Font.FontStyleCombo.Select(self.old_font_style)
        self.app.Font.OK.Click()
        self.app.Font.WaitNot('visible')

        # close the application
        try:
            self.dlg.Close(0.5)
            if self.app.Notepad["Do&n't Save"].Exists():
                self.app.Notepad["Do&n't Save"].Click()
                self.app.Notepad["Do&n't Save"].WaitNot('visible')
        except:  # timings.TimeoutError:
            pass
        finally:
            self.app.kill_()

    #def testText(self):
    #    "Test getting the window Text of the dialog"
    #    self.assertEquals(self.dlg.WindowText(), "Untitled - Notepad")

    def testClick(self):
        self.ctrl.Click(coords=(50, 10))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (6, 6))

    def testClickInput(self):
        self.ctrl.ClickInput(coords=(50, 10))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (6, 6))

    def testDoubleClick(self):
        self.ctrl.DoubleClick(coords=(60, 30))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (24, 29))

    def testDoubleClickInput(self):
        self.ctrl.DoubleClickInput(coords=(60, 30))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (24, 29))

    def testMenuSelectNotepad_bug(self):
        "In notepad - MenuSelect Edit->Paste did not work"

        text = b'Here are some unicode characters \xef\xfc\r\n'
        app2 = Application.start("notepad")
        app2.UntitledNotepad.Edit.SetEditText(text)

        app2.UntitledNotepad.MenuSelect("Edit->Select All")
        app2.UntitledNotepad.MenuSelect("Edit->Copy")

        self.dlg.MenuSelect("Edit->Select All")
        self.dlg.MenuSelect("Edit->Paste")
        self.dlg.MenuSelect("Edit->Paste")
        self.dlg.MenuSelect("Edit->Paste")

        app2.UntitledNotepad.MenuSelect("File->Exit")
        app2.Window_(title='Notepad',
                     class_name='#32770')["Don't save"].Click()

        self.assertEquals(
            self.dlg.Edit.TextBlock().encode(locale.getpreferredencoding()),
            text * 3)
class HwndWrapperMouseTests(unittest.TestCase):
    "Unit tests for mouse actions of the HwndWrapper class"

    def setUp(self):
        """Start the application set some data and ensure the application
        is in the state we want it."""

        # start the application
        self.app = Application()
        self.app.start_("notepad.exe")

        # Get the old font
        self.app.UntitledNotepad.MenuSelect("Format->Font")

        self.old_font = self.app.Font.FontComboBox.SelectedIndex()
        self.old_font_style = self.app.Font.FontStyleCombo.SelectedIndex()

        # ensure we have the correct settings for this test
        self.app.Font.FontStyleCombo.Select(0)
        self.app.Font.FontComboBox.Select("Lucida Console")
        self.app.Font.OK.Click()

        self.dlg = self.app.UntitledNotepad
        self.ctrl = HwndWrapper(self.dlg.Edit.handle)
        self.dlg.edit.SetEditText("Here is some text\r\n and some more")

    def tearDown(self):
        "Close the application after tests"

        # Set the old font again
        self.app.UntitledNotepad.MenuSelect("Format->Font")
        self.app.Font.FontComboBox.Select(self.old_font)
        self.app.Font.FontStyleCombo.Select(self.old_font_style)
        self.app.Font.OK.Click()

        # close the application
        self.dlg.TypeKeys("%{F4}")
        if self.app.Notepad.No.Exists():
            self.app.Notepad.No.Click()

    #def testText(self):
    #    "Test getting the window Text of the dialog"
    #    self.assertEquals(self.dlg.WindowText(), "Untitled - Notepad")

    def testClick(self):
        self.ctrl.Click(coords=(50, 10))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (5, 5))

    def testClickInput(self):
        self.ctrl.ClickInput(coords=(50, 10))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (5, 5))

    def testDoubleClick(self):
        self.ctrl.DoubleClick(coords=(60, 30))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (24, 29))

    def testDoubleClickInput(self):
        self.ctrl.DoubleClickInput(coords=(60, 30))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (24, 29))

    def testMenuSelectNotepad_bug(self):
        "In notepad - MenuSelect Edit->Paste did not work"

        text = u'Here are some unicode characters \xef\xfc\r\n'
        app2 = Application.start("notepad")
        app2.UntitledNotepad.Edit.SetEditText(text)

        app2.UntitledNotepad.MenuSelect("Edit->Select All")
        app2.UntitledNotepad.MenuSelect("Edit->Copy")

        self.dlg.MenuSelect("Edit->Select All")
        self.dlg.MenuSelect("Edit->Paste")
        self.dlg.MenuSelect("Edit->Paste")
        self.dlg.MenuSelect("Edit->Paste")

        app2.UntitledNotepad.MenuSelect("File->Exit")
        app2.Notepad.No.Click()

        self.assertEquals(self.dlg.Edit.TextBlock(), text * 3)
Ejemplo n.º 3
0
class HwndWrapperMouseTests(unittest.TestCase):
    "Unit tests for mouse actions of the HwndWrapper class"

    def setUp(self):
        """Start the application set some data and ensure the application
        is in the state we want it."""

        # start the application
        self.app = Application().start(
            os.path.join(mfc_samples_folder, u"CmnCtrl3.exe"))

        self.dlg = self.app.Common_Controls_Sample
        self.dlg.TabControl.Select('CButton (Command Link)')
        self.ctrl = HwndWrapper(self.dlg.NoteEdit.handle)

    def tearDown(self):
        "Close the application after tests"

        # close the application
        try:
            self.dlg.Close(0.5)
        except Exception:  # TimeoutError:
            pass
        finally:
            self.app.kill_()

    #def testText(self):
    #    "Test getting the window Text of the dialog"
    #    self.assertEquals(self.dlg.WindowText(), "Untitled - Notepad")

    def testClick(self):
        self.ctrl.Click(coords=(50, 5))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (9, 9))

    def testClickInput(self):
        self.ctrl.ClickInput(coords=(50, 5))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (9, 9))

    def testDoubleClick(self):
        self.ctrl.DoubleClick(coords=(50, 5))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (8, 13))

    def testDoubleClickInput(self):
        self.ctrl.DoubleClickInput(coords=(80, 5))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (13, 18))

#    def testRightClick(self):
#        pass

    def testRightClickInput(self):
        self.dlg.Edit.TypeKeys('{HOME}')
        self.dlg.Edit.Wait('enabled').RightClickInput()
        self.app.PopupMenu.Wait('ready').Menu().GetMenuPath(
            'Select All')[0].ClickInput()
        self.dlg.Edit.TypeKeys('{DEL}')
        self.assertEquals(self.dlg.Edit.TextBlock(), '')

    def testPressMoveRelease(self):
        self.dlg.NoteEdit.PressMouse(coords=(0, 5))
        self.dlg.NoteEdit.MoveMouse(coords=(65, 5))
        self.dlg.NoteEdit.ReleaseMouse(coords=(65, 5))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (0, 12))

    def testDragMouse(self):
        self.dlg.NoteEdit.DragMouse(press_coords=(0, 5),
                                    release_coords=(65, 5))
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (0, 12))

        # continue selection with pressed Shift key
        self.dlg.NoteEdit.DragMouse(press_coords=(65, 5),
                                    release_coords=(90, 5),
                                    pressed='shift')
        self.assertEquals(self.dlg.Edit.SelectionIndices(), (0, 17))

    def testDebugMessage(self):
        self.dlg.NoteEdit.DebugMessage('Test message')
        # TODO: add screenshots comparison

    #def testDrawOutline(self):
    #    # TODO: add screenshots comparison
    #    self.dlg.DrawOutline()


#    def testSetWindowText(self):
#        pass
#
#    def testTypeKeys(self):
#        pass

    def testSetTransparency(self):
        self.dlg.SetTransparency()
        self.assertRaises(ValueError, self.dlg.SetTransparency, 256)