public void GetEvironmentTypeTest_ValidWebEnvironment_ReturnWebEnvironment()
        {
            EnvironmentType type =
                ParallelRunnerEnvironmentUtil.GetEnvironmentType(WebEnvironment);

            Assert.AreEqual(EnvironmentType.WEB, type);
        }
        public void GetEvironmentTypeTest_EnvironmentEmpty_ReturnUnknownEnvironment()
        {
            EnvironmentType type =
                ParallelRunnerEnvironmentUtil.GetEnvironmentType("");

            Assert.AreEqual(EnvironmentType.UNKNOWN, type);
        }
        public void ParseMobileEnvironmentTest_ValidMobileEnvironment_ReturnsExpectedMobileEnvironment()
        {
            MobileEnvironment mobileEnvironment = ParallelRunnerEnvironmentUtil.
                                                  ParseMobileEnvironment(MobileEnvironment);

            // function suceeded
            Assert.IsNotNull(mobileEnvironment);

            // propertes should be non-null
            Assert.IsNotNull(mobileEnvironment.device);
            Assert.IsNotNull(mobileEnvironment.lab);

            Device device = mobileEnvironment.device;

            // not present in the string
            Assert.IsNull(device.deviceID);

            // only the manufacturer should be filled
            Assert.IsNull(device.model);

            // must be present
            Assert.IsNotNull(device.manufacturer);
            Assert.IsNotNull(device.osType);
            Assert.IsNotNull(device.osVersion);

            Assert.AreEqual("android", device.osType);
            Assert.AreEqual("4.4.2", device.osVersion);
            Assert.AreEqual("\"samsung gt-i9515\"", device.manufacturer);
        }
        public void GetEvironmentTypeTest_ValidMobileEnvironment_ReturnMobileEnvironment()
        {
            EnvironmentType type =
                ParallelRunnerEnvironmentUtil.GetEnvironmentType(MobileEnvironment);

            Assert.AreEqual(EnvironmentType.MOBILE, type);
        }
        public void ParseEnvironmentStringsTest_ValidEnvironments_ReturnValidRunConfiguration()
        {
            IList <string> environments = new List <string> {
                MobileEnvironment,
                WebEnvironment
            };

            TestInfo mockTesInfo = new TestInfo("c:\tests\test1",
                                                "c:\tests\test1", "1", "Test1");

            mockTesInfo.ReportPath = mockTesInfo.TestPath;

            ParallelTestRunConfiguration configuration = null;

            try
            {
                configuration = ParallelRunnerEnvironmentUtil.
                                ParseEnvironmentStrings(environments, mockTesInfo);
            }
            catch (ParallelRunnerConfigurationException)
            {
                // since the environments are valid there should be no exception
                Assert.Fail();
            }

            // report paths should be equal
            Assert.AreEqual(mockTesInfo.ReportPath, configuration.reportPath);

            // we have two parallel runs
            // one for web and one for mobile
            Assert.AreEqual(2, configuration.parallelRuns.Length);
        }
        public void ParseMCSettingsTest_InvalidMCSettings_ReturnsNullSettings()
        {
            McConnectionInfo mcConnectionInfo = new McConnectionInfo();

            UFTSettings settings = ParallelRunnerEnvironmentUtil.ParseMCSettings(mcConnectionInfo);

            Assert.IsNull(settings);
        }
        public void ParseWebEnvironmentTest_EmptyWebEnvironment_ReturnsExpectedWebEnvironment()
        {
            WebEnvironment webEnvironment = ParallelRunnerEnvironmentUtil.
                                            ParseWebEnvironment("");

            // function suceeded
            Assert.IsNull(webEnvironment);
        }
        public void ParseMobileEnvironmentTest_EmptyMobileEnvironment_ReturnsNull()
        {
            MobileEnvironment mobileEnvironment = ParallelRunnerEnvironmentUtil.
                                                  ParseMobileEnvironment("");

            // function suceeded
            Assert.IsNull(mobileEnvironment);
        }
        public void GetMCProxySettingsTest_InvalidMCSettings_ReturnsNullProxySettings()
        {
            McConnectionInfo mcConnectionInfo = new McConnectionInfo();

            ProxySettings settings = ParallelRunnerEnvironmentUtil.GetMCProxySettings(mcConnectionInfo);

            Assert.IsNull(settings);
        }
        public void IsKnownMobilePropertyTest_KnownProperty_ReturnsTrue()
        {
            bool isKnown = ParallelRunnerEnvironmentUtil.IsKnownMobileProperty("deviceId") &&
                           ParallelRunnerEnvironmentUtil.IsKnownMobileProperty("osVersion") &&
                           ParallelRunnerEnvironmentUtil.IsKnownMobileProperty("osType") &&
                           ParallelRunnerEnvironmentUtil.IsKnownMobileProperty("manufacturerAndModel");

            Assert.IsTrue(isKnown);
        }
        public void ParseWebEnvironmentTest_InvalidKeyWebEnvironment_ReturnsExpectedWebEnvironment()
        {
            string invalidKey = "brows: Chrome";

            WebEnvironment webEnvironment = ParallelRunnerEnvironmentUtil.
                                            ParseWebEnvironment(invalidKey);

            // function suceeded
            Assert.IsNull(webEnvironment);
        }
        public void ParseMobileEnvironmentTest_InvalidKeyMobileEnvironment_ReturnsNull()
        {
            string invalidEnvironment = "invalid: android";

            MobileEnvironment mobileEnvironment = ParallelRunnerEnvironmentUtil.
                                                  ParseMobileEnvironment(invalidEnvironment);

            // function suceeded
            Assert.IsNull(mobileEnvironment);
        }
        public void GetEnvironmentPropertiesTest_EmptyEnvironment_ReturnsEmptyDictionary()
        {
            string environment = "";

            Dictionary <string, string> properties = ParallelRunnerEnvironmentUtil.
                                                     GetEnvironmentProperties(environment);

            // there should be 0 properties
            Assert.AreEqual(0, properties.Count);
        }
        public void ParseEnvironmentStringsTest_InvalidEnvironments_ThrowException()
        {
            // the list of supported browsers
            IList <string> environments = new List <string> {
                "browser: unknown",
            };

            TestInfo mockTesInfo = new TestInfo("c:\tests\test1",
                                                "c:\tests\test1", "1", "Test1");

            mockTesInfo.ReportPath = mockTesInfo.TestPath;

            ParallelTestRunConfiguration configuration = ParallelRunnerEnvironmentUtil.
                                                         ParseEnvironmentStrings(environments, mockTesInfo);
        }
        public void GetEnvironmentPropertiesTest_ValidEnvironment_ReturnsExpectedProperties()
        {
            Dictionary <string, string> properties = ParallelRunnerEnvironmentUtil.
                                                     GetEnvironmentProperties(MobileEnvironment);

            // there should be 3 properties
            Assert.AreEqual(properties.Count, 3);

            // check if all the properties are present
            Assert.IsTrue(properties.ContainsKey("ostype"));
            Assert.IsTrue(properties.ContainsKey("osversion"));
            Assert.IsTrue(properties.ContainsKey("manufacturerandmodel"));

            Assert.AreEqual("android", properties["ostype"]);
            Assert.AreEqual("4.4.2", properties["osversion"]);
            Assert.AreEqual("\"samsung gt-i9515\"", properties["manufacturerandmodel"]);
        }
        public void ParseWebEnvironmentTest_ValidWebEnvironment_ReturnsExpectedWebEnvironment()
        {
            WebEnvironment webEnvironment = ParallelRunnerEnvironmentUtil.
                                            ParseWebEnvironment(WebEnvironment);

            // function suceeded
            Assert.IsNotNull(webEnvironment);

            // browser should be present
            Assert.IsNotNull(webEnvironment.browser);

            // local browser lab should be present
            Assert.IsNotNull(webEnvironment.lab);

            // browser should be 'chrome'
            Assert.AreEqual("chrome", webEnvironment.browser);

            Assert.AreEqual("LocalBrowser", webEnvironment.lab);
        }
        public void ParseMCSettingsTest_ValidMCSettingsNonSSL_ReturnsExpectedSettings()
        {
            McConnectionInfo mcConnectionInfo = new McConnectionInfo();

            mcConnectionInfo.MobileHostAddress = "192.168.1.1";
            mcConnectionInfo.MobileHostPort    = "8080";
            mcConnectionInfo.MobileUserName    = "******";
            mcConnectionInfo.MobilePassword    = "******";

            UFTSettings settings = ParallelRunnerEnvironmentUtil.ParseMCSettings(mcConnectionInfo);

            Assert.IsNotNull(settings);
            Assert.IsNotNull(settings.mc);

            Assert.AreEqual(mcConnectionInfo.MobileHostAddress, settings.mc.hostname);
            Assert.AreEqual(mcConnectionInfo.MobileHostPort, settings.mc.port.ToString());
            Assert.AreEqual(mcConnectionInfo.MobileUserName, settings.mc.username);
            Assert.AreEqual("http", settings.mc.protocol);
        }
        public void GetMCProxySettingsTest_ValidMCSettings_ReturnsExpectedProxySettings()
        {
            McConnectionInfo mcConnectionInfo = new McConnectionInfo();

            mcConnectionInfo.MobileProxySetting_Address        = "192.168.1.1";
            mcConnectionInfo.MobileProxySetting_Port           = 8080;
            mcConnectionInfo.MobileProxySetting_Authentication = 1;
            mcConnectionInfo.MobileProxySetting_UserName       = "******";
            mcConnectionInfo.MobileProxySetting_Password       = "******";

            ProxySettings settings = ParallelRunnerEnvironmentUtil.GetMCProxySettings(mcConnectionInfo);

            Assert.IsNotNull(settings);
            Assert.IsNotNull(settings.authentication);

            Assert.AreEqual(mcConnectionInfo.MobileProxySetting_UserName, settings.authentication.username);
            Assert.AreEqual(mcConnectionInfo.MobileProxySetting_Address, settings.hostname);
            Assert.AreEqual(mcConnectionInfo.MobileProxySetting_Port, settings.port);
        }
        public void ParseEnvironmentStringsTest_UnknownEnvironments_ReturnEmptyConfiguration()
        {
            // the list of supported browsers
            IList <string> environments = new List <string> {
                "test: ",
            };

            TestInfo mockTesInfo = new TestInfo("c:\tests\test1",
                                                "c:\tests\test1", "1", "Test1");

            mockTesInfo.ReportPath = mockTesInfo.TestPath;
            ParallelTestRunConfiguration configuration = null;

            try
            {
                configuration = ParallelRunnerEnvironmentUtil.
                                ParseEnvironmentStrings(environments, mockTesInfo);
            }catch (ParallelRunnerConfigurationException)
            {
                Assert.Fail();
            }

            Assert.AreEqual(0, configuration.parallelRuns.Length);
        }
        /// <summary>
        /// Runs the provided test on all the environments.
        /// </summary>
        /// <param name="testInfo"> The test information. </param>
        /// <param name="errorReason"> failure reason </param>
        /// <param name="runCancelled"> delegate to RunCancelled </param>
        /// <returns>
        /// The run results for the current test.
        /// </returns>
        public TestRunResults RunTest(TestInfo testInfo, ref string errorReason, RunCancelledDelegate runCancelled)
        {
            ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Running in parallel: " + testInfo.TestPath);

            if (string.IsNullOrWhiteSpace(testInfo.ReportPath))
            {
                // maybe the report base directory is set, if so,
                // the report path for parallel runner shall be populated here
                if (!string.IsNullOrWhiteSpace(testInfo.ReportBaseDirectory))
                {
                    // "<report-base-dir>\<test-name>_ParallelReport"
                    testInfo.ReportPath = Path.Combine(testInfo.ReportBaseDirectory,
                                                       testInfo.TestName.Substring(testInfo.TestName.LastIndexOf('\\') + 1) + "_ParallelReport");
                    ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is generated under base directory: " + testInfo.ReportPath);
                }
                else
                {
                    // neither ReportPath nor ReportBaseDirectory is given, use default report path:
                    // "<TestPath>\ParallelReport"
                    testInfo.ReportPath = testInfo.TestPath + @"\ParallelReport";
                    ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is automatically generated: " + testInfo.ReportPath);
                }
            }
            else
            {
                ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " Report path is set explicitly: " + testInfo.ReportPath);
            }

            // this is to make sure that we do not overwrite the report
            // when we run the same test multiple times on the same build
            string resFolder = Helper.GetNextResFolder(testInfo.ReportPath, "Res");

            var runResults = new TestRunResults
            {
                ReportLocation = testInfo.ReportPath,
                ErrorDesc      = errorReason,
                TestState      = TestState.Unknown,
                TestPath       = testInfo.TestPath,
                TestType       = TestType.ParallelRunner.ToString()
            };

            // set the active test run
            ConsoleWriter.ActiveTestRun = runResults;

            if (!_canRun)
            {
                ConsoleWriter.WriteLine("Could not find parallel runner executable!");
                errorReason          = Resources.ParallelRunnerExecutableNotFound;
                runResults.TestState = TestState.Error;
                runResults.ErrorDesc = errorReason;
                return(runResults);
            }

            // change the DCOM setting for qtp application
            Helper.ChangeDCOMSettingToInteractiveUser();

            // try to check if the UFT process already exists
            bool uftProcessExist = false;
            bool isNewInstance;

            using (Mutex m = new Mutex(true, "per_process_mutex_UFT", out isNewInstance))
            {
                if (!isNewInstance)
                {
                    uftProcessExist = true;
                }
            }

            // try to get qtp status via qtp automation object since the uft process exists
            if (uftProcessExist)
            {
                var  type               = Type.GetTypeFromProgID("Quicktest.Application");
                var  qtpApplication     = Activator.CreateInstance(type) as QTObjectModelLib.Application;
                bool needKillUFTProcess = false;
                // status: Not launched / Ready / Busy / Running / Recording / Waiting / Paused
                string status = qtpApplication.GetStatus();
                switch (status)
                {
                case "Not launched":
                    if (uftProcessExist)
                    {
                        // UFT process exist but the status retrieved from qtp automation object is Not launched
                        // it means the UFT is launched but not shown the main window yet
                        // in which case it shall be considered as UFT is not used at all
                        // so here can kill the UFT process to continue
                        needKillUFTProcess = true;
                    }
                    break;

                case "Ready":
                case "Waiting":
                    // UFT is launched but not running or recording, shall be considered as UFT is not used
                    // so here can kill the UFT process to continue
                    needKillUFTProcess = true;
                    break;

                case "Busy":
                case "Running":
                case "Recording":
                case "Paused":
                    // UFT is launched and somehow in use now, shouldn't kill UFT process
                    // here make the test fail
                    errorReason          = Resources.UFT_Running;
                    runResults.ErrorDesc = errorReason;
                    runResults.TestState = TestState.Error;
                    return(runResults);

                default:
                    // by default, let the tool run test, the behavior might be unexpected
                    break;
                }

                if (needKillUFTProcess)
                {
                    Process[] procs = Process.GetProcessesByName("uft");
                    if (procs != null)
                    {
                        foreach (Process proc in procs)
                        {
                            proc.Kill();
                        }
                    }
                }
            }

            // Try to create the ParalleReport path
            try
            {
                Directory.CreateDirectory(runResults.ReportLocation);
            }
            catch (Exception)
            {
                errorReason          = string.Format(Resources.FailedToCreateTempDirError, runResults.ReportLocation);
                runResults.TestState = TestState.Error;
                runResults.ErrorDesc = errorReason;

                Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed;
                return(runResults);
            }

            ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " => Using ParallelRunner to execute test: " + testInfo.TestPath);

            _runCancelled = runCancelled;

            // prepare the json file for the process
            var configFilePath = string.Empty;

            try
            {
                configFilePath = ParallelRunnerEnvironmentUtil.GetConfigFilePath(testInfo, _mcConnectionInfo, _environments);
                _configFiles.Add(configFilePath);
            }
            catch (ParallelRunnerConfigurationException ex) // invalid configuration
            {
                errorReason          = ex.Message;
                runResults.ErrorDesc = errorReason;
                runResults.TestState = TestState.Error;
                return(runResults);
            }

            // Parallel runner argument "-c" for config path and "-o static" so that
            // the output from ParallelRunner is compatible with Jenkins
            var arguments = String.Format(ParallelRunnerArguments, configFilePath);

            // the test can be started now
            runResults.TestState = TestState.Running;

            var runTime = new Stopwatch();

            runTime.Start();

            string failureReason = null;

            runResults.ErrorDesc = null;

            // execute parallel runner and get the run result status
            int exitCode = ExecuteProcess(_parallelRunnerPath, arguments, ref failureReason);

            // set the status of the build based on the exit code
            RunResultsFromParallelRunnerExitCode(runResults, exitCode, failureReason, ref errorReason);

            // update the run time
            runResults.Runtime = runTime.Elapsed;

            // update the report location as the report should be
            // generated by now
            runResults.ReportLocation = resFolder;

            return(runResults);
        }
        public void IsKnownMobilePropertyTest_UnknownProperty_ReturnsTrue()
        {
            bool isKnown = ParallelRunnerEnvironmentUtil.IsKnownMobileProperty("unknown");

            Assert.IsFalse(isKnown);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Runs the provided test on all the environments.
        /// </summary>
        /// <param name="testInfo"> The test information. </param>
        /// <param name="errorReason"> failure reason </param>
        /// <param name="runCancelled"> delegate to RunCancelled </param>
        /// <returns>
        /// The run results for the current test.
        /// </returns>
        public TestRunResults RunTest(TestInfo testInfo, ref string errorReason, RunCancelledDelegate runCancelled)
        {
            // change the DCOM setting for qtp application
            Helper.ChangeDCOMSettingToInteractiveUser();

            testInfo.ReportPath = testInfo.TestPath + @"\ParallelReport";

            // this is to make sure that we do not overwrite the report
            // when we run the same test multiple times on the same build
            string resFolder = Helper.GetNextResFolder(testInfo.ReportPath, "Res");

            var runResults = new TestRunResults
            {
                ReportLocation = testInfo.ReportPath,
                ErrorDesc      = errorReason,
                TestState      = TestState.Unknown,
                TestPath       = testInfo.TestPath,
                TestType       = TestType.ParallelRunner.ToString()
            };

            // set the active test run
            ConsoleWriter.ActiveTestRun = runResults;

            if (!_canRun)
            {
                ConsoleWriter.WriteLine("Could not find parallel runner executable!");
                errorReason          = Resources.ParallelRunnerExecutableNotFound;
                runResults.TestState = TestState.Error;
                runResults.ErrorDesc = errorReason;
                return(runResults);
            }

            // Try to create the ParalleReport path
            try
            {
                Directory.CreateDirectory(runResults.ReportLocation);
            }catch (Exception)
            {
                errorReason          = string.Format(Resources.FailedToCreateTempDirError, runResults.ReportLocation);
                runResults.TestState = TestState.Error;
                runResults.ErrorDesc = errorReason;

                Environment.ExitCode = (int)Launcher.ExitCodeEnum.Failed;
                return(runResults);
            }

            ConsoleWriter.WriteLine(DateTime.Now.ToString(Launcher.DateFormat) + " => Using ParallelRunner to execute test: " + testInfo.TestPath);

            _runCancelled = runCancelled;

            // prepare the json file for the process
            var configFilePath = string.Empty;

            try
            {
                configFilePath = ParallelRunnerEnvironmentUtil.GetConfigFilePath(testInfo, _mcConnectionInfo, _environments);
                _configFiles.Add(configFilePath);
            }catch (ParallelRunnerConfigurationException ex) // invalid configuration
            {
                errorReason          = ex.Message;
                runResults.ErrorDesc = errorReason;
                runResults.TestState = TestState.Error;
                return(runResults);
            }

            // Parallel runner argument "-c" for config path and "-o static" so that
            // the output from ParallelRunner is compatible with Jenkins
            var arguments = String.Format(ParallelRunnerArguments, configFilePath);

            // the test can be started now
            runResults.TestState = TestState.Running;

            var runTime = new Stopwatch();

            runTime.Start();

            string failureReason = null;

            runResults.ErrorDesc = null;

            // execute parallel runner and get the run result status
            int exitCode = ExecuteProcess(_parallelRunnerPath, arguments, ref failureReason);

            // set the status of the build based on the exit code
            RunResultsFromParallelRunnerExitCode(runResults, exitCode, failureReason, ref errorReason);

            // update the run time
            runResults.Runtime = runTime.Elapsed;

            // update the report location as the report should be
            // generated by now
            runResults.ReportLocation = resFolder;

            return(runResults);
        }