コード例 #1
0
        private void btnRunTest_Click(object sender, System.EventArgs e)
        {
            sveDataStore.Title  = "Location to save GUI test data";
            sveDataStore.Filter = "XML Files (*.xml)|*.xml|All Files (*.*)|*.*";
            if (sveDataStore.ShowDialog() == DialogResult.OK)
            {
                TestCaseStore = sveDataStore.FileName;
            }
            else
            {
                return;
            }

            GUITestSeqList.AUTStartupForm = startupForm;

            GUITestUtility.SerilizeInfo(TestCaseStore, GUITestSeqList);

            //chapter 8
            string verifyStore = TestCaseStore.Replace(".xml", "_verify.xml");

            GUITestUtility.SerilizeInfo(verifyStore, TypesToVerify);


            GUITestScript guiTS = new GUITestScript(TestCaseStore, currDir);

            GUITestSeqList = null;
        }
コード例 #2
0
        private void btnStartApp_Click(object sender, System.EventArgs e)
        {
            string AppUT  = @"C:\GUISourceCode\Chapter03\CSharpAPITextViewer\bin\Debug\CSharpAPITextViewer.exe";
            string TypeUT = "CSharpAPITextViewer.Form1";

            AUTobj = GUITestUtility.StartAUT(AppUT, TypeUT);
        }
コード例 #3
0
        private void btnStartGUITest_Click(object sender, System.EventArgs e)
        {
            TypesToVerify = new TypeVerificationSerializable();
            GUISequence   = 0;          //added for chapter 8

            GUITestSeqList = new GUITestUtility.GUIInfoSerializable();

            opnAUT.Title  = "Specify an Application Under Test";
            opnAUT.Filter = "GUI Applications(*.EXE; *.DLL)|*.EXE;*.DLL|All files (*.*)|*.*";
            if (opnAUT.ShowDialog() == DialogResult.OK)
            {
                applicationUT          = opnAUT.FileName;
                GUITestSeqList.AUTPath = applicationUT;

                GetTypeToTestFromAUT();
                try
                {
                    formUT = (Form)GUITestUtility.StartAUT(applicationUT, startupForm);
                }
                catch (InvalidCastException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                return;
            }
        }
コード例 #4
0
        private bool GetCheckedButtonInGroup(RadioButton rdBtn, ref string ErrorMsg)
        {
            int     parentHandle = GUITestActions.GetParent((int)rdBtn.Handle);
            Control parentGrp    = (Control)GUITestUtility.VerifyField(AUT, parentHandle);

            foreach (Control ctrl in parentGrp.Controls)
            {
                try
                {
                    RadioButton rdCtrl = (RadioButton)ctrl;
                    if (rdCtrl.Name == rdBtn.Name)
                    {
                        if (!rdBtn.Checked)
                        {
                            ErrorMsg = rdBtn.Name + " is not checked!";
                            return(false);
                        }
                    }
                    else
                    {
                        if (rdCtrl.Checked)
                        {
                            ErrorMsg = "Other than or beside the " + rdBtn.Name +
                                       " is checked, the " + rdCtrl.Name + " is also checked!";
                            return(false);
                        }
                    }
                }
                catch {}
            }
            return(true);
        }
コード例 #5
0
        private void StartAUT()
        {
            seqGUIUT = new GUITestUtility.GUIInfoSerializable();
            object obj = (object)seqGUIUT;

            GUITestUtility.DeSerializeInfo(guiTestDataStore, ref obj);
            seqGUIUT = (GUITestUtility.GUIInfoSerializable)obj;

            string AUTPath     = seqGUIUT.AUTPath;
            string startupType = seqGUIUT.AUTStartupForm;

            if (AUT == null)
            {
                AUT = (Form)GUITestUtility.StartAUT(AUTPath, startupType);
            }

            int           hwnd      = (int)AUT.Handle;
            StringBuilder sbClsName = new StringBuilder(128);

            GUITestActions.GetClassName(hwnd, sbClsName, 128);
            string clsName = sbClsName.ToString();
            string winText = AUT.Text;
            string pText   = "";

            GUITestActions.SynchronizeWindow(ref hwnd, ref winText, ref clsName, ref pText);
        }
コード例 #6
0
        private void tmrStopScript_Tick(object sender, System.EventArgs e)
        {
            GUITestUtility.GUIInfo guiUnit = (GUITestUtility.GUIInfo)seqGUIUT.GUIList[clickNum - 1];
            Control ctrlTested;

            ctrlTested = (Control)GUITestUtility.VerifyField(AUT, guiUnit.GUIControlName);
            resultList.Add(ctrlTested.Text);

            if (clickNum >= seqGUIUT.GUIList.Count)
            {
                tmrRunScript.Enabled  = false;
                tmrStopScript.Enabled = false;
                tmrVerifyTest.Enabled = true;
                try
                {
                    AUT.Dispose();
                }
                catch {}
            }
            else
            {
                tmrRunScript.Enabled  = true;
                tmrStopScript.Enabled = false;
            }
        }
コード例 #7
0
        //chapter 8
        private void AddTestVerification()
        {
            if (AUT == null)
            {
                return;
            }

            string VerifyDataStore = guiTestDataStore.Replace(".xml", "_verify.xml");

            TypeVerificationSerializable verifyTypes = new TypeVerificationSerializable();
            object obj = (object)verifyTypes;

            GUITestUtility.DeSerializeInfo(VerifyDataStore, ref obj);
            verifyTypes = (TypeVerificationSerializable)obj;

            TypeVerification oneType  = (TypeVerification)verifyTypes.TypeList[clickNum - 1];
            object           resulted = null;

            foreach (TestExpectation fieldName in oneType.MemberList)
            {
                TestExpectation tested = fieldName;
                try
                {
                    resulted       = GUITestUtility.VerifyField(AUT, tested.VerifyingMember);
                    tested.isField = true;
                }
                catch (Exception ex4)
                {
                    resulted          = GUITestUtility.VerifyProperty(AUT, tested.VerifyingMember);
                    tested.isProperty = true;
                }
                VerifyAlphanumericResult(ref tested, resulted);
                VerifyClipboard(ref tested, resulted);
            }
        }
コード例 #8
0
        private void RunsScript()
        {
            guiTestActionLib = Path.Combine(progDir, "GUITestActionLib.xml");

            GUITestUtility.GUIInfo guiUnit = (GUITestUtility.GUIInfo)seqGUIUT.GUIList[clickNum];

            string        ctrlAction = GUITestUtility.GetAGUIAction(guiTestActionLib, guiUnit.GUIControlType);
            StringBuilder sb         = new StringBuilder(10000);

            try             //chapter 12
            {
                Control ctrlTested = (Control)GUITestUtility.VerifyField(AUT, guiUnit.GUIControlName);
                GUITestActions.GetWindowText((int)ctrlTested.Handle, sb, 10000);
            }
            catch {}

            //object[] paramArr = new object[4];
            object[] paramArr = new object[5];             //chapter 10

            if (ctrlAction == "HandleMenuItems")           //chapter 12
            {
                paramArr[0] = AUT.Handle.ToInt32();
            }
            else
            {
                paramArr[0] = 0;
            }

            paramArr[1] = sb.ToString();
            paramArr[2] = guiUnit.GUIClassName;
            paramArr[3] = guiUnit.GUIParentText;
            paramArr[4] = guiUnit.TextEntry;             //chapter 10

            Type       guiTestLibType = new GUITestActions().GetType();
            object     obj            = Activator.CreateInstance(guiTestLibType);
            MethodInfo mi             = guiTestLibType.GetMethod(ctrlAction);

            //chapter 11
            preChecked = DeterminePreCheckedStatus(guiUnit);

            try
            {
                mi.Invoke(obj, paramArr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (clickNum < seqGUIUT.GUIList.Count)
            {
                clickNum++;
                tmrRunScript.Enabled  = false;
                tmrStopScript.Enabled = true;
            }
        }
コード例 #9
0
        private void tmrVerifyTest_Tick(object sender, System.EventArgs e)
        {
            tmrVerifyTest.Enabled = false;

            string resultDataStore = guiTestDataStore.Replace(".xml", "_result.xml");

            GUITestUtility.SerilizeInfo(resultDataStore, resultList);

            this.Dispose();
        }
コード例 #10
0
        private void StartNonDotNetAUT()
        {
            seqGUIUT = new GUITestUtility.GUIInfoSerializable();
            object obj = (object)seqGUIUT;

            GUITestUtility.DeSerializeInfo(guiTestDataStore, ref obj);
            seqGUIUT = (GUITestUtility.GUIInfoSerializable)obj;

            GUITestUtility.StartAUTAsProcess(seqGUIUT.AUTPath, "");
        }
コード例 #11
0
        private bool DeterminePreCheckedStatus(GUITestUtility.GUIInfo guiUnit)
        {
            bool isChecked = false;

            if (guiUnit.GUIControlType == "System.Windows.Form.CheckBox")
            {
                CheckBox chckBx = (CheckBox)GUITestUtility.VerifyField(AUT, guiUnit.GUIControlName);
                isChecked = chckBx.Checked;
            }
            return(isChecked);
        }
コード例 #12
0
 private void timer2_Tick(object sender, System.EventArgs e)
 {
     if (clickNum > 0)
     {
         Control ctrlTested;
         ctrlTested = (Control)GUITestUtility.VerifyField(AUTobj, "txtSelected");
         statusCollection.Add(ctrlTested.Text);
     }
     timer1.Enabled = true;
     timer2.Enabled = false;
 }
コード例 #13
0
        private void tmrVerifyTest_Tick(object sender, System.EventArgs e)
        {
            tmrVerifyTest.Enabled = false;

            string resultDataStore = guiTestDataStore.Replace(".xml", "_result.xml");

            //GUITestUtility.SerilizeInfo(resultDataStore, resultList);
            GUITestUtility.SerilizeInfo(resultDataStore, testResult);

            //Display the test result
            try
            {
                XmlTreeViewer.Form1 xmlTV = new XmlTreeViewer.Form1();
                xmlTV.OpenXmlDoc(resultDataStore);
                xmlTV.Show();
            }
            catch {}

            //Test completed
            this.Dispose();
        }
コード例 #14
0
        private void StartAUT()
        {
            seqGUIUT = new GUITestUtility.GUIInfoSerializable();
            object obj = (object)seqGUIUT;

            GUITestUtility.DeSerializeInfo(guiTestDataStore, ref obj);
            seqGUIUT = (GUITestUtility.GUIInfoSerializable)obj;

            string AUTPath     = seqGUIUT.AUTPath;
            string startupType = seqGUIUT.AUTStartupForm;

            int hwnd = 0;

            if (AUT == null)
            {
                try                 //chapter 13
                {
                    AUT  = (Form)GUITestUtility.StartAUT(AUTPath, startupType);
                    hwnd = (int)AUT.Handle;
                }
                catch (InvalidCastException ex)                 //chapter 13
                {
                    AUT = GUITestUtility.StartControlUT(AUTPath, startupType);
                    AUT.Show();
                    Control ctrlAUT = AUT.Controls[0];
                    hwnd = (int)ctrlAUT.Handle;
                }
            }

            //int hwnd = (int)AUT.Handle;

            StringBuilder sbClsName = new StringBuilder(128);

            GUITestActions.GetClassName(hwnd, sbClsName, 128);
            string clsName = sbClsName.ToString();
            string winText = AUT.Text;
            string pText   = "";

            GUITestActions.SynchronizeWindow(ref hwnd, ref winText, ref clsName, ref pText);
        }
コード例 #15
0
        private void RunsScript()
        {
            guiTestActionLib = Path.Combine(progDir, "GUITestActionLib.xml");

            GUITestUtility.GUIInfo guiUnit = (GUITestUtility.GUIInfo)seqGUIUT.GUIList[clickNum];

            string ctrlAction = GUITestUtility.GetAGUIAction(guiTestActionLib, guiUnit.GUIControlType);

            StringBuilder sb = new StringBuilder(10000);

            Control ctrlTested = (Control)GUITestUtility.VerifyField(AUT, guiUnit.GUIControlName);

            GUITestActions.GetWindowText((int)ctrlTested.Handle, sb, 10000);

            object[] paramArr = new object[4];
            paramArr[0] = 0;
            paramArr[1] = sb.ToString();            //.Replace("\r\n", "\n");
            paramArr[2] = guiUnit.GUIClassName;
            paramArr[3] = guiUnit.GUIParentText;

            Type       guiTestLibType = new GUITestActions().GetType();
            object     obj            = Activator.CreateInstance(guiTestLibType);
            MethodInfo mi             = guiTestLibType.GetMethod(ctrlAction);

            try
            {
                mi.Invoke(obj, paramArr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (clickNum < seqGUIUT.GUIList.Count)
            {
                clickNum++;
                tmrRunScript.Enabled  = false;
                tmrStopScript.Enabled = true;
            }
        }
コード例 #16
0
        private void GetTypeToTestFromAUT()
        {
            if (applicationUT.Length <= 0)
            {
                return;
            }
            TypeUnderTest typeDUT = new TypeUnderTest();

            try
            {
                Assembly asm = Assembly.LoadFrom(applicationUT);
                Type[]   tys = asm.GetTypes();
                foreach (Type ty in tys)
                {
                    typeDUT.chckListType.Items.Add(ty.Namespace + "." + ty.Name);
                }
            }
            //Chapter 14
            catch (BadImageFormatException badImgEx)
            {
                GUITestUtility.StartAUTAsProcess(applicationUT, "");

                applicationUT = null;
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            if (typeDUT.ShowDialog() == DialogResult.OK)
            {
                GetSelectedTypesUT(typeDUT);
            }
            else
            {
                return;
            }
        }
コード例 #17
0
        private void timer1_Tick(object sender, System.EventArgs e)
        {
            if (clickNum < 7)
            {
                clickNum++;
                timer1.Enabled = false;
                timer2.Enabled = true;
            }

            int    hwnd    = 0;
            string winText = "";
            string clsName = "";
            string pText   = "";

            switch (clickNum)
            {
            case 1:
                //1. click the list box
                hwnd    = 0;
                winText = "";
                clsName = "WindowsForms10.LISTBOX.app3";
                pText   = "C# API Text Viewer";
                GUITestActions.HandleListBox(ref hwnd, ref winText, ref clsName, ref pText);
                break;

            case 2:
                //2. click the Add button
                winText = "Add";
                clsName = "";
                GUITestActions.HandleCommandButton(ref hwnd, ref winText, ref clsName, ref pText);
                break;

            case 3:
                //3. Click the Copy button
                winText = "Copy";
                clsName = "";
                GUITestActions.HandleCommandButton(ref hwnd, ref winText, ref clsName, ref pText);

                break;

            case 4:
                //4. Click the text box
                Control ctrlTested;
                ctrlTested = (Control)GUITestUtility.VerifyField(AUTobj, "txtSelected");
                StringBuilder sb = new StringBuilder(1000);
                GUITestActions.GetWindowText((int)ctrlTested.Handle, sb, 1000);
                winText = sb.ToString();
                clsName = "WindowsForms10.RichEdit20W.app3";
                GUITestActions.HandleTextBox(ref hwnd, ref winText, ref clsName, ref pText);
                break;

            case 5:
                //5. Click the Remove button to remove one line of code
                winText = "Remove";
                clsName = "";
                GUITestActions.HandleCommandButton(ref hwnd, ref winText, ref clsName, ref pText);
                break;

            case 6:
                //6. Click the Clear button to clear the text box
                winText = "Clear";
                clsName = "";
                pText   = "C# API Text Viewer";
                GUITestActions.HandleCommandButton(ref hwnd, ref winText, ref clsName, ref pText);
                break;

            default:
                //Complet this clicking sequence
                timer1.Enabled = false;
                timer2.Enabled = false;
                break;
            }
        }