Пример #1
0
 def setUp(self):
     """
     Start the application, set some data and ensure the application
     is in the state we want it.
     """
     # start the application
     app = Application(backend='uia')
     self.app = app.Start(wpf_app_1)
     self.dlg = self.app.WPFSampleApplication
Пример #2
0
class FindWindowsTestCases(unittest.TestCase):
    """Unit tests for findwindows.py module"""
    def setUp(self):
        """Set some data and ensure the application is in the state we want"""
        Timings.Defaults()

        # start the application
        self.app = Application(backend='win32')
        self.app = self.app.Start(mfc_app_1)

        self.dlg = self.app.CommonControlsSample

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

    def test_find_window(self):
        """Test if function find_window() works as expected including raising the exceptions"""
        ctrl = self.dlg.OK.WrapperObject()
        handle = find_window(process=self.app.process,
                             best_match='OK',
                             top_level_only=False)

        self.assertEqual(handle, ctrl.handle)

        self.assertRaises(WindowNotFoundError,
                          find_window,
                          process=self.app.process,
                          class_name='OK')

        self.assertRaises(WindowAmbiguousError,
                          find_window,
                          process=self.app.process,
                          class_name='Button',
                          top_level_only=False)

    def test_find_windows(self):
        """Test if function find_windows() works as expected including raising the exceptions"""
        ctrl_hwnds = [
            elem.handle for elem in self.dlg.children()
            if elem.class_name() == 'Edit'
        ]
        handles = find_windows(process=self.app.process,
                               class_name='Edit',
                               top_level_only=False)

        self.assertEqual(set(handles), set(ctrl_hwnds))

        self.assertRaises(WindowNotFoundError,
                          find_windows,
                          process=self.app.process,
                          class_name='FakeClassName',
                          found_index=1)
Пример #3
0
    class UIAWrapperMouseTests(unittest.TestCase):
        """Unit tests for mouse actions of the UIAWrapper class"""
        def setUp(self):
            """
            Start the application set some data and ensure the application
            is in the state we want it.
            """

            self.app = Application(backend='uia')
            self.app = self.app.Start(wpf_app_1)

            self.dlg = self.app.WPFSampleApplication
            self.button = self.dlg.OK.WrapperObject()
            self.label = self.dlg.TestLabel.WrapperObject()

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

            self.app.kill_()

        #def testClick(self):
        #    pass

        def testClickInput(self):
            time.sleep(0.5)
            self.button.click_input()
            self.assertEqual(self.label.window_text(), "LeftClick")

        #def testDoubleClick(self):
        #    pass

        def testDoubleClickInput(self):
            self.button.double_click_input()
            self.assertEqual(self.label.window_text(), "DoubleClick")

        #def testRightClick(self):
        #    pass

        def testRightClickInput(self):
            time.sleep(0.5)
            self.button.right_click_input()
            self.assertEqual(self.label.window_text(), "RightClick")
def upgrade():
    try:
        version = copy_item()
        #current_version = check_build(version)
        #print("The Version installed is :" +current_version + "The version you are about to install is:  " +version)
        #response_from_user = input ("Do you want to Continue: ")
        #response_from_user = response_from_user.lower()
        #if (response_from_user == 'y'or "yes"):
        fsv = app.Start("FSViewerSetup46.exe")
        fsv.InstallDialog.NextButton.Wait('ready', timeout=30).ClickInput()
        fsv.InstallDialog.IAgreeRadioButton.Wait('ready',
                                                 timeout=30).ClickInput()
        fsv.InstallDialog.Edit.Wait('ready', timeout=30).TypeKeys(
            os.getcwd() + "\FastStone Image Viewer", with_spaces=True)
        fsv.InstallDialog.InstallButton.Wait('ready', timeout=30).ClickInput()
        fsv.InstallDialog.FinishButton.Wait('ready', timeout=30).ClickInput()
        #else:
        #   print("Exiting Installer")
    except:
        print("Product Not Installed")
Пример #5
0
class ButtonTestCases(unittest.TestCase):
    """Unit tests for the ButtonWrapper class"""
    def setUp(self):
        """Set some data and ensure the application is in the state we want"""
        _set_timings_fast()

        self.app = Application()
        self.app = self.app.Start(
            os.path.join(mfc_samples_folder, u"CmnCtrl1.exe"))

        self.app.Common_Controls_Sample.TabControl.Select("CDateTimeCtrl")

        self.ctrl = self.app.Common_Controls_Sample

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

    def testGetProperties(self):
        """Test getting the properties for the button control"""
        props = self.ctrl.Button2.GetProperties()

        self.assertEquals("Button", props['friendly_class_name'])

        self.assertEquals(self.ctrl.Button2.texts(), props['texts'])

        for prop_name in props:
            self.assertEquals(
                getattr(self.ctrl.Button2, prop_name)(), props[prop_name])

    def test_NeedsImageProp(self):
        """Test whether an image needs to be saved with the properties"""
        self.assertEquals(self.ctrl.OKButton._needs_image_prop, True)
        self.assertEquals('image' in self.ctrl.OKButton.GetProperties(), True)

    def testFriendlyClass(self):
        """Test the friendly_class_name method"""
        self.assertEquals(self.ctrl.Button2.friendly_class_name(), "Button")
        self.assertEquals(self.ctrl.RadioButton2.friendly_class_name(),
                          "RadioButton")

    def testCheckUncheck(self):
        """Test unchecking a control"""
        self.ctrl.RadioButton2.Check()
        self.assertEquals(self.ctrl.RadioButton2.GetCheckState(), 1)
        self.ctrl.RadioButton2.UnCheck()
        self.assertEquals(self.ctrl.RadioButton2.GetCheckState(), 0)

    def testGetCheckState_unchecked(self):
        """Test whether the control is unchecked"""
        self.assertEquals(self.ctrl.RadioButton.GetCheckState(), 0)

    def testGetCheckState_checked(self):
        """Test whether the control is checked"""
        self.ctrl.RadioButton2.Check()
        self.assertEquals(self.ctrl.RadioButton2.GetCheckState(), 1)


#    def testGetCheckState_indeterminate(self):
#        "indeterminate"
#        self.calc.Inv.SetCheckIndeterminate()
#        self.assertEquals(self.calc.Inv.GetCheckState(), 0)

    def testClick(self):
        """Test clicking on buttons"""
        self.ctrl.RadioButton2.Click()  # DTS_SHORTDATEFORMAT
        self.ctrl.RadioButton.Click()  # DTS_TIMEFORMAT
        self.ctrl.RadioButton3.Click()  # DTS_LONGDATEFORMAT
        self.assertEquals(self.ctrl.RadioButton3.GetCheckState(), 1)

    def testIsSelected(self):
        """Test whether the control is selected or not"""
        # Todo - I need to find an application where a button can be
        # selected - I don't see one in Calc at least :)
        self.assertEquals(self.ctrl.RadioButton.GetCheckState(), 0)

        self.ctrl.RadioButton.Click()

        self.assertEquals(self.ctrl.RadioButton.GetCheckState(), 1)
Пример #6
0
class DialogTestCases(unittest.TestCase):
    """Unit tests for the DialogWrapper class"""
    def setUp(self):
        """Set some data and ensure the application is in the state we want"""
        _set_timings_fast()

        self.app = Application()
        self.app = self.app.Start(
            os.path.join(mfc_samples_folder, u"CmnCtrl1.exe"))

        self.cmn_ctrl = self.app.Common_Controls_Sample

        # write out the XML so that we can read it in later
        self.app.Common_Controls_Sample.WriteToXML("ref_controls.xml")

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

    def testGetProperties(self):
        """Test getting the properties for the dialog box"""
        props = self.cmn_ctrl.GetProperties()

        self.assertEquals("Dialog", props['friendly_class_name'])

        self.assertEquals(self.cmn_ctrl.texts(), props['texts'])

        for prop_name in props:
            self.assertEquals(
                getattr(self.cmn_ctrl, prop_name)(), props[prop_name])

    def testRunTests(self):
        """Test running the UI tests on the dialog"""
        bugs = self.cmn_ctrl.RunTests()
        from pywinauto.controls.hwndwrapper import HwndWrapper
        self.assertEquals(True, isinstance(bugs[0][0][0], HwndWrapper))

    def testRunTestsWithReference(self):
        """Add a ref control, get the bugs and validate that the hande"""
        from pywinauto import controlproperties
        ref_controls = [
            controlproperties.ControlProps(ctrl)
            for ctrl in xml_helpers.ReadPropertiesFromFile("ref_controls.xml")
        ]

        bugs = self.cmn_ctrl.RunTests(ref_controls=ref_controls)
        from pywinauto import tests
        tests.print_bugs(bugs)
        from pywinauto.controls.hwndwrapper import HwndWrapper
        self.assertEquals(True, isinstance(bugs[0][0][0], HwndWrapper))

    def testWriteToXML(self):
        """Write the output and validate that it is the same as the test output"""
        self.cmn_ctrl.WriteToXML("test_output.xml")

        all_props = [self.cmn_ctrl.GetProperties()]
        all_props.extend([c.GetProperties() for c in self.cmn_ctrl.children()])

        props = xml_helpers.ReadPropertiesFromFile("test_output.xml")
        for i, ctrl in enumerate(props):

            for key, ctrl_value in ctrl.items():
                expected_value = all_props[i][key]

                if "Image" in expected_value.__class__.__name__:
                    expected_value = expected_value.tobytes()
                    ctrl_value = ctrl_value.tobytes()

                if isinstance(ctrl_value, (list, tuple)):
                    ctrl_value = list(ctrl_value)
                    expected_value = list(expected_value)

                if ctrl_value == 'None':
                    ctrl_value = None

                self.assertEquals(ctrl_value, expected_value)

        os.unlink("test_output.xml")

    def testClientAreaRect(self):
        """Validate that the client area rect is the right size
        (comparing against the full rectangle)
        Notice that we run an approximate comparison as the actual
        area size depends on Windows OS and a current desktop theme"""
        clientarea = self.cmn_ctrl.ClientAreaRect()
        rectangle = self.cmn_ctrl.rectangle()
        self.assertFalse((clientarea.left - rectangle.left) > 10)
        self.assertFalse((clientarea.top - rectangle.top) > 60)
        self.assertFalse((rectangle.right - clientarea.right) > 10)
        self.assertFalse((rectangle.bottom - clientarea.bottom) > 10)

    def testHideFromTaskbar(self):
        """Test that a dialog can be hidden from the Windows taskbar"""
        self.assertEquals(self.cmn_ctrl.IsInTaskbar(), True)
        self.cmn_ctrl.HideFromTaskbar()
        self.assertEquals(self.cmn_ctrl.IsInTaskbar(), False)
        self.cmn_ctrl.ShowInTaskbar()
        self.assertEquals(self.cmn_ctrl.IsInTaskbar(), True)
Пример #7
0
    def beginSetup(completePreAuth=False, completeSetup=None):

        if not completePreAuth:
            body = driver.find_element_by_tag_name("body")
            body.send_keys(Keys.CONTROL + 't')

        time.sleep(1)

        global accessCode, accessCode1
        driver.get('https://migs.mastercard.com.au/ma')
        if not completePreAuth:
            driver.maximize_window()

        loginElem = driver.find_element_by_id('ownerId')
        if completePreAuth:
            loginElem.send_keys(app.Entry3.get() + "_P")
        else:
            loginElem.send_keys(app.Entry3.get())
        loginElem = driver.find_element_by_id('userName')
        loginElem.send_keys('Administrator')
        loginElem = driver.find_element_by_id('password')
        loginElem.send_keys('----')
        loginElem = driver.find_element_by_class_name('Submitlogin')
        type(loginElem)
        loginElem.click()

        loginElem = driver.find_element_by_link_text('Admin')
        type(loginElem)
        loginElem.click()
        driver.implicitly_wait(3)

        loginElem = driver.find_element_by_link_text('Operators')
        type(loginElem)
        loginElem.click()
        driver.implicitly_wait(3)

        loginElem = driver.find_element_by_link_text(
            'Create a new Merchant Administration Operator')
        type(loginElem)
        loginElem.click()
        driver.implicitly_wait(3)

        loginElem = driver.find_element_by_id('userName')
        loginElem.send_keys('appoperator')

        loginElem = driver.find_element_by_id('name')
        loginElem.send_keys('operator')

        loginElem = driver.find_element_by_id('password')
        loginElem.send_keys('----')

        loginElem = driver.find_element_by_id('repeatPassword')
        loginElem.send_keys('----')

        pageElem = driver.find_element_by_id('moto')
        type(pageElem)
        pageElem.click()

        if completePreAuth:
            pageElem = driver.find_element_by_id('capture')
            type(pageElem)
            pageElem.click()
        else:
            pageElem = driver.find_element_by_id('purchase')
            type(pageElem)
            pageElem.click()

        pageElem = driver.find_element_by_id('standAloneCapture')
        type(pageElem)
        pageElem.click()

        pageElem = driver.find_element_by_id('refund')
        type(pageElem)
        pageElem.click()

        driver.implicitly_wait(1)

        pageElem = driver.find_element_by_id('standAloneRefund')
        type(pageElem)
        pageElem.click()

        pageElem = driver.find_element_by_id('configure')
        type(pageElem)
        pageElem.click()

        pageElem = driver.find_element_by_id('agentAdmin')
        type(pageElem)
        pageElem.click()

        pageElem = driver.find_element_by_name('submit')
        type(pageElem)
        pageElem.click()

        driver.implicitly_wait(2)

        pageElem = driver.find_element_by_link_text('Logout')
        type(pageElem)
        pageElem.click()

        driver.implicitly_wait(2)

        loginElem = driver.find_element_by_id('ownerId')

        if completePreAuth:
            loginElem.send_keys(app.Entry3.get() + "_P")
        else:
            loginElem.send_keys(app.Entry3.get())

        loginElem = driver.find_element_by_id('userName')
        loginElem.send_keys('appoperator')
        passwordElem = driver.find_element_by_id('password')
        passwordElem.send_keys('----')
        loginElem = driver.find_element_by_class_name('Submitlogin')
        type(loginElem)
        loginElem.click()

        pageElem = driver.find_element_by_link_text('Admin')
        type(pageElem)
        pageElem.click()

        driver.implicitly_wait(2)

        pageElem = driver.find_element_by_partial_link_text('Configuration')
        type(pageElem)
        pageElem.click()

        if not completePreAuth:
            accessCode = driver.find_element_by_id(
                'finTransResultaccessCode.value').text
        else:
            accessCode1 = driver.find_element_by_id(
                'finTransResultaccessCode.value').text

        pageElem = driver.find_element_by_link_text('Operators')
        type(pageElem)
        pageElem.click()

        pageElem = driver.find_element_by_link_text('Edit')
        type(pageElem)
        pageElem.click()

        pageElem = driver.find_element_by_id('advanceMA')
        type(pageElem)
        pageElem.click()

        pageElem = driver.find_element_by_name('submit')
        type(pageElem)
        pageElem.click()

        if completePreAuth and completeSetup:
            notePad = Application()
            notePad.Start('notepad.exe')

            pyperclip.copy(
                "Please continue to the intranet and paste the appropriate variables \n\r "
                + "\n\r" + "Merchant ID:     " + app.Entry3.get() + "\n\r" +
                "Access Code:     " + accessCode + "\n\r" + "Password:     "******"\n\r" + "Preauth details" + "\n\r" +
                "Merchant ID:     " + app.Entry3.get() + "_P" + "\n\r" +
                "Access Code:     " + accessCode1 + "\n\r" + "Password:     "******"Logout")
            type(pageElem)
            pageElem.click()
            whiteMigs.beginSetup(completePreAuth=True, completeSetup=True)
Пример #8
0
    class UIAWrapperTests(unittest.TestCase):

        "Unit tests for the UIAWrapper 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(backend='uia')
            self.app = self.app.Start(wpf_app_1)

            self.dlg = self.app.WPFSampleApplication

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

        def testFriendlyClassName(self):
            "Test getting the friendly classname of the dialog"
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.friendly_class_name(), "Button")

        def test_find_nontop_ctl_by_class_name_and_title(self):
            """Test getting a non-top control by a class name and a title"""
            # Look up for a non-top button control with 'Apply' caption
            self.dlg.Wait('ready')
            caption = 'Apply'
            wins = self.app.windows_(top_level_only=False,
                                     class_name='Button',
                                     title=caption)

            # Verify the number of found wrappers
            self.assertEqual(len(wins), 1)

            # Verify the caption of the found wrapper
            self.assertEqual(wins[0].texts()[0], caption)

        def test_find_top_win_by_class_name_and_title(self):
            """Test getting a top window by a class name and a title"""
            # Since the top_level_only is True by default
            # we don't specify it as a criteria argument
            self.dlg.Wait('ready')
            caption = 'WPF Sample Application'
            wins = self.app.windows_(class_name='Window', title=caption)

            # Verify the number of found wrappers
            self.assertEqual(len(wins), 1)

            # Verify the caption of the found wrapper
            self.assertEqual(wins[0].texts()[0], caption)

        def testClass(self):
            "Test getting the classname of the dialog"
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.class_name(), "Button")

        def testWindowText(self):
            "Test getting the window Text of the dialog"
            label = self.dlg.TestLabel.WrapperObject()
            self.assertEqual(label.window_text(), u"TestLabel")

        def testControlID(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.control_id(), None)

        def testIsVisible(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.is_visible(), True)

        def testIsEnabled(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.is_enabled(), True)

        def testProcessID(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.process_id(), self.dlg.process_id())
            self.assertNotEqual(button.process_id(), 0)

        def testIsDialog(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.is_dialog(), False)

        def testParent(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.parent(), self.dlg.WrapperObject())

        def testTopLevelParent(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.top_level_parent(),
                             self.dlg.WrapperObject())

        def testTexts(self):
            self.assertEqual(self.dlg.texts(), ['WPF Sample Application'])

        def testChildren(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(len(button.children()), 1)
            self.assertEqual(button.children()[0].class_name(), "TextBlock")

        def testIsChild(self):
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.is_child(self.dlg.WrapperObject()), True)

        def testEquals(self):
            button = self.dlg.OK.WrapperObject()
            self.assertNotEqual(button, self.dlg.WrapperObject())
            self.assertEqual(button, button.element_info)
            self.assertEqual(button, button)

        #def testVerifyActionable(self):
        #    self.assertRaises()

        #def testVerifyEnabled(self):
        #    self.assertRaises()

        #def testVerifyVisible(self):
        #    self.assertRaises()

        def testIsKeyboardFocusable(self):
            edit = self.dlg.TestLabelEdit.WrapperObject()
            label = self.dlg.TestLabel.WrapperObject()
            button = self.dlg.OK.WrapperObject()
            self.assertEqual(button.is_keyboard_focusable(), True)
            self.assertEqual(edit.is_keyboard_focusable(), True)
            self.assertEqual(label.is_keyboard_focusable(), False)

        def testHasKeyboardFocus(self):
            edit = self.dlg.TestLabelEdit.WrapperObject()
            edit.set_focus()
            self.assertEqual(edit.has_keyboard_focus(), True)

        def testSetFocus(self):
            edit = self.dlg.TestLabelEdit.WrapperObject()
            edit.set_focus()
            self.assertEqual(edit.has_keyboard_focus(), True)

        def testTypeKeys(self):
            edit = self.dlg.TestLabelEdit.WrapperObject()
            edit.type_keys("testTypeKeys")
            self.assertEqual(edit.window_text(), "testTypeKeys")

        def testNoPatternInterfaceError(self):
            "Test a query interface exception handling"
            button = self.dlg.OK.WrapperObject()
            elem = button.element_info.element
            self.assertRaises(
                uia_defs.NoPatternInterfaceError,
                uia_defs.get_elem_interface,
                elem,
                "Selection",
            )

        def testGetProperties(self):
            uia_props = set([
                'class_name',
                'friendly_class_name',
                'texts',
                'control_id',
                'rectangle',
                'is_visible',
                'is_enabled',
                'control_count',
                'is_keyboard_focusable',
                'has_keyboard_focus',
                'selection_indices',
            ])
            edit = self.dlg.TestLabelEdit.WrapperObject()
            props = set(edit.get_properties().keys())
            self.assertEqual(props, uia_props)
Пример #9
0
def launchDesktopApplication(path):
    try:
        app = Application.Start(path)
    except FileNotFoundError as fnfe:
        print('File is not present in specified location', fnfe)