Ejemplo n.º 1
0
        /* void PerformVP(TestStep step)
         * perform check point
         */
        private void PerformVP(TestStep step)
        {
            try
            {

                TestObject obj = _objEngine.GetTestObject(step);

                ((IVisible)obj).HighLight();
                this._logEngine.SaveScreenPrint();

                object actualReslut;
                string message = null;

                if (_vpEngine.PerformVPCheck(obj, step._testAction, step._testVPProperty, step._testExpectResult, out actualReslut))
                {
                    message = "*** PASS: "******"\t" + actualReslut.ToString();
                }
                else
                {
                    message = "*** FAIL: " + step.ToString() + "\t" + actualReslut.ToString();
                }

                OnNewMessage(message);
                this._logEngine.TestResultInfo = message;

                this._logEngine.WriteLog();

            }
            catch (Exception ex)
            {
                throw new VerifyPointException("Can not perform VP with step [" + step.ToString() + "]: " + ex.ToString());
            }
        }
Ejemplo n.º 2
0
 /* void PerformIf(TestStep step)
  * check status, decide what to do next step.
  */
 private void PerformIf(TestStep step)
 {
 }
Ejemplo n.º 3
0
        /* void PerformJump(TestStep step)
         * Jump to other test step.
         */
        private void PerformJump(TestStep step)
        {
            int newIndex;

            if (int.TryParse(step._testData, out newIndex))
            {
                if (newIndex > 2)
                {
                    _index = newIndex - 2;
                }
            }

            this._logEngine.WriteLog("Jump to " + _index);
        }
Ejemplo n.º 4
0
        /* void PerformGo(TestStep step)
         * Perform normal actions.
         * If the first column in EXCEL driver file is "GO", we will call this method.
         */
        private void PerformGo(TestStep step)
        {
            string item = step._testControl;

            if (item.ToUpper() == "BROWSER")
            {
                if (_testBrowser == null)
                {
                    _testBrowser = (TestInternetExplorer)_objEngine.GetTestBrowser();
                }

                string action = step._testAction.ToUpper();
                if (action == "START")
                {
                    _testBrowser.Start();
                    string url = step._testData;
                    if (!String.IsNullOrEmpty(url) && (url.ToUpper().StartsWith("HTTP://")) || url.ToUpper().StartsWith("HTTPS://"))
                    {

                        _testBrowser.Load(url, false);
                    }
                }
                else if (action == "LOAD")
                {
                    _testBrowser.Load(step._testData, false);
                }
                else if (action == "FIND")
                {
                    _testBrowser.Find(step._testData);
                }
                else if (action == "WAIT")
                {
                    string data = step._testData.ToUpper().Replace(" ", "");

                    int seconds;
                    if (int.TryParse(data, out seconds))
                    {
                        _testBrowser.Wait(seconds);
                    }
                    else
                    {
                        if (data == "NEWPAGE")
                        {
                            _testBrowser.WaitForPage();
                        }
                        else
                        {
                            throw new CannotPerformActionException("Error: Bad data for Wait action: " + data);
                        }
                    }
                }
                else if (action == "MAXSIZE")
                {
                    _testBrowser.Max();
                }
                else if (action == "CLOSE")
                {
                    _testBrowser.Close();
                }
                else if (action == "REFRESH")
                {
                    _testBrowser.Refresh();
                }
                else if (action == "FORWARD")
                {
                    _testBrowser.Forward();
                }
                else if (action == "BACK")
                {
                    _testBrowser.Back();
                }
                else
                {
                    throw new CannotPerformActionException("Unsupported action: " + step._testAction);
                }

                //sleep 1 seconds after browser action, make it looks like human actions
                Thread.Sleep(1000 * 1);

            }
            else if (item.ToUpper() == "APP")
            {
                if (_testApp == null)
                {
                    _testApp = (ITestApp)_objEngine.GetTestApp();
                }
            }
            else
            {
                TestObject obj = _objEngine.GetTestObject(step);

                _testBrowser.Active();

                if (this._isHighlight)
                {
                    ((IVisible)obj).HighLight();
                }

                _actEngine.PerformAction(obj, step._testAction, step._testData);

                //sleep for 1 second, make it looks like human actions
                Thread.Sleep(1000 * 1);
            }

            this._logEngine.WriteLog();
        }
Ejemplo n.º 5
0
        /*  void PerformCall(TestStep step)
         *  call subs.
         */
        private void PerformCall(TestStep step)
        {
            string subName = step._testControl;
            List<TestStep> subSteps;
            subSteps = _subEngine.BuildTestStepBySubName(subName);

            if (subSteps == null || subSteps.Count < 1)
            {
                throw new CannotLoadSubException("Sub steps must contains step.");
            }

            TestStepStatus tmp = new TestStepStatus();
            tmp._index = _index;
            tmp._stepList = _currentTestSteps;
            _testStepStack.Push(tmp);

            _currentTestSteps = subSteps;
            _index = 0;

            this._logEngine.WriteLog();
        }
Ejemplo n.º 6
0
        /* void GetTestSteps(string DriverFile)
         * Parse main test steps, the first tab in EXCEl, store test steps in a list.
         */
        private void GetTestSteps(string DriverFile)
        {
            if (String.IsNullOrEmpty(DriverFile) || !File.Exists(this._driveFile))
            {
                throw new DriveNotFoundException("Can not find driven file:" + DriverFile);
            }

            try
            {
                _excelReader.FileName = DriverFile;
                _excelReader.Sheet = "TestSteps";
                _excelReader.Open();

                //read execl line by line
                while (_excelReader.MoveNext())
                {
                    //each line is a test step
                    TestStep tmp = new TestStep();
                    tmp._testCommand = _excelReader.ReadByIndex(0);
                    tmp._testControl = _excelReader.ReadByIndex(1);
                    tmp._testProperty = _excelReader.ReadByIndex(2);
                    tmp._testAction = _excelReader.ReadByIndex(3);
                    tmp._testData = _excelReader.ReadByIndex(4);
                    tmp._testVPProperty = _excelReader.ReadByIndex(5);
                    tmp._testExpectResult = _excelReader.ReadByIndex(6);

                    //store each test step to a list.
                    this._myTestStepList.Add(tmp);

                    //meet "END", stop.
                    if (tmp._testCommand.ToUpper() == "END")
                    {
                        break;
                    }
                }

            }
            catch (Exception ex)
            {
                throw new BadFormatDriverFileException("Can not get main test steps: " + ex.ToString());
            }
            finally
            {
                _excelReader.Close();
            }
        }
Ejemplo n.º 7
0
        /* void GetSubSteps(string DriverFile)
         * Parse the 2nd "Sub" tab, store subs to a list.
         */
        private void GetSubSteps(string DriverFile)
        {
            if (String.IsNullOrEmpty(DriverFile) || !File.Exists(this._driveFile))
            {
                throw new DriveNotFoundException("Can not find driven file:" + DriverFile);
            }

            try
            {
                _excelReader.FileName = DriverFile;
                _excelReader.Sheet = "Sub";
                _excelReader.Open();

                TestSub tmpSub = new TestSub();

                //line by line
                while (_excelReader.MoveNext())
                {
                    if (String.IsNullOrEmpty(_excelReader.ReadByIndex(0)))
                    {
                        continue;
                    }

                    //if the first column is "SUB", means we find a new sub.
                    if (_excelReader.ReadByIndex(0).ToUpper() == "SUB")
                    {
                        tmpSub._subName = null;
                        tmpSub._subTestSteps = new List<TestStep>(128);

                        if (String.IsNullOrEmpty(_excelReader.ReadByIndex(1)))
                        {
                            throw new BadFormatDriverFileException("Sub must contain sub name.");
                        }
                        else
                        {
                            tmpSub._subName = _excelReader.ReadByIndex(1);
                        }

                        continue;
                    }

                    //if the first column is "EndSub" or "End Sub", means current sub is end.
                    if (_excelReader.ReadByIndex(0).ToUpper() == "ENDSUB" || _excelReader.ReadByIndex(0).ToUpper() == "END SUB")
                    {
                        _myTestSubList.Add(tmpSub);
                        continue;
                    }

                    //test steps of this sub.
                    TestStep tmp = new TestStep();
                    tmp._testCommand = _excelReader.ReadByIndex(0);
                    tmp._testControl = _excelReader.ReadByIndex(1);
                    tmp._testProperty = _excelReader.ReadByIndex(2);
                    tmp._testAction = _excelReader.ReadByIndex(3);
                    tmp._testData = _excelReader.ReadByIndex(4);
                    tmp._testVPProperty = _excelReader.ReadByIndex(5);
                    tmp._testExpectResult = _excelReader.ReadByIndex(6);

                    if (tmpSub._subTestSteps == null)
                    {
                        tmpSub._subTestSteps = new List<TestStep>(128);
                    }

                    tmpSub._subTestSteps.Add(tmp);
                }

            }
            catch (Exception ex)
            {
                throw new BadFormatDriverFileException("Can not get test subs: " + ex.ToString());
            }
            finally
            {
                _excelReader.Close();
            }
        }
Ejemplo n.º 8
0
        /* TestStep InsertDataToSingleTestStep(TestStep testStep, string[] data)
         * insert data to a single test step.
         */
        private TestStep InsertDataToSingleTestStep(TestStep testStep, string[] data)
        {
            int index = 0; //index of data value, eg: value1, value2

            //check each field
            for (int i = 0; i < testStep.Size; i++)
            {
                //if datapool found
                if (GetDataIndex(testStep[i], out index))
                {
                    testStep[i] = data[index];
                }
            }

            return testStep;
        }