Пример #1
0
        /* static ITestBrowser CreateTestBrowser()
         * return expected ITestBrowser.
         * This interface is used to control the browser.
         */
        public static ITestBrowser CreateTestBrowser()
        {
            // if it is not web application, return null.
            if (_appType != 1)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(_testBrowserDLL))
            {
                throw new CannotLoadDllException("Test browser dll can not be null.");
            }

            try
            {
                //load the dll, convert to expcted interface.
                _browser = (ITestBrowser)LoadDll(_testBrowserDLL, _testBrowserClassName);
            }
            catch (Exception ex)
            {
                throw new CannotLoadDllException("Can not create instance of Test Browser: " + ex.ToString());
            }

            if (_browser == null)
            {
                throw new CannotLoadDllException("Can not create instance of test browser.");
            }
            else
            {
                return(_browser);
            }
        }
Пример #2
0
        /* void LoadPlugin()
         * Get the dll we need.
         * use reflecting to load dll at runtime.
         */
        private void LoadPlugin()
        {
            _objPool = TestFactory.CreateTestObjectPool();

            if (TestFactory.AppType == TestAppType.Desktop)
            {
                _testApp = TestFactory.CreateTestApp();
                _objPool.SetTestWindow(_testApp.CurrentWindow);
            }
            else if (TestFactory.AppType == TestAppType.Web)
            {
                _testBrowser = TestFactory.CreateTestBrowser();
                _objPool.SetTestPage(_testBrowser.CurrentPage);
            }
            else
            {
                throw new CannotInitCoreEngineException("Unknow application type.");
            }
        }
Пример #3
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();
        }
Пример #4
0
        /* static ITestBrowser CreateTestBrowser()
         * return expected ITestBrowser.
         * This interface is used to control the browser.
         */
        public static ITestBrowser CreateTestBrowser()
        {
            // if it is not web application, return null.
            if (_appType != 1)
            {
                return null;
            }

            if (String.IsNullOrEmpty(_testBrowserDLL))
            {
                throw new CannotLoadDllException("Test browser dll can not be null.");
            }

            try
            {
                //load the dll, convert to expcted interface.
                _browser = (ITestBrowser)LoadDll(_testBrowserDLL, _testBrowserClassName);
            }
            catch (Exception ex)
            {
                throw new CannotLoadDllException("Can not create instance of Test Browser: " + ex.ToString());
            }

            if (_browser == null)
            {
                throw new CannotLoadDllException("Can not create instance of test browser.");
            }
            else
            {
                return _browser;
            }
        }
Пример #5
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();
        }