Exemplo n.º 1
0
        public void ParallelTest_B()
        {
            string[] testParams = PNUnitServices.Get().GetTestParams();
            int      sleepTime  = int.Parse(testParams[0]);

            int count = 0;

            while (count < MAX_ITERATIONS)
            {
                PNUnitServices.Get().WriteLine(
                    string.Format("Starting  ParallelTest_B, Time: {0}. Iteration:{1}",
                                  DateTime.Now.ToString(),
                                  count + 1));

                PNUnitServices.Get().WriteLine(
                    string.Format("Sleeping  ParallelTest_B for {1} seconds, Time: {0}",
                                  DateTime.Now.ToString(),
                                  sleepTime));

                Thread.Sleep(sleepTime * 1000);

                PNUnitServices.Get().WriteLine(
                    string.Format("Waking up ParallelTest_B, Time: {0}",
                                  DateTime.Now.ToString()));

                count++;
            }
        }
Exemplo n.º 2
0
        public void ParallelTestWithBarriersA()
        {
            //First step should be the initialization of synchronization barriers
            PNUnitServices.Get().InitBarriers();

            PNUnitServices.Get().WriteLine(
                string.Format(
                    "ParallelTestWithBarriersA: Waiting for peer synchronization before starting... Time:{0}",
                    DateTime.Now.ToString()));

            PNUnitServices.Get().EnterBarrier(START_BARRIER);
            PNUnitServices.Get().WriteLine(string.Format(
                                               "ParallelTestWithBarriersA: Sync start performed!... Time:{0}", DateTime.Now.ToString()));

            PNUnitServices.Get().WriteLine(
                string.Format("Sleeping  ParallelTestWithBarriersA for 5 seconds, Time: {0}",
                              DateTime.Now.ToString()));

            Thread.Sleep(5000);

            PNUnitServices.Get().WriteLine(
                string.Format(
                    "ParallelTestWithBarriersA: Waiting for peer synchronization after sleeping... Time:{0}",
                    DateTime.Now.ToString()));

            PNUnitServices.Get().EnterBarrier(WAIT_BARRIER);
            PNUnitServices.Get().WriteLine(string.Format("ParallelTestWithBarriersA: Sync end!. Time:{0}", DateTime.Now.ToString()));
        }
Exemplo n.º 3
0
        public void ParallelTestWithBarriersB()
        {
            PNUnitServices.Get().InitBarriers();

            PNUnitServices.Get().WriteLine(
                string.Format(
                    "ParallelTestWithBarriersB: About to sleep for 4 seconds before starting... Time:{0}",
                    DateTime.Now.ToString()));

            Thread.Sleep(4000);

            PNUnitServices.Get().EnterBarrier(START_BARRIER);
            PNUnitServices.Get().WriteLine(string.Format(
                                               "ParallelTestWithBarriersB: Sync start performed!... Time:{0}", DateTime.Now.ToString()));

            PNUnitServices.Get().WriteLine(
                string.Format("Sleeping  ParallelTestWithBarriersB for 1 second, Time: {0}",
                              DateTime.Now.ToString()));

            Thread.Sleep(1000);

            PNUnitServices.Get().WriteLine(
                string.Format(
                    "ParallelTestWithBarriersB: Waiting for peer synchronization after sleeping... Time:{0}",
                    DateTime.Now.ToString()));

            PNUnitServices.Get().EnterBarrier(WAIT_BARRIER);
            PNUnitServices.Get().WriteLine(string.Format("ParallelTestWithBarriersB: Sync end!. Time:{0}", DateTime.Now.ToString()));
        }
Exemplo n.º 4
0
        public void Server()
        {
            PNUnitServices.Get().InitBarrier("BARRIER", 1);
            PNUnitServices.Get().WriteLine("Server started");

            Thread.Sleep(10000);

            PNUnitServices.Get().EnterBarrier("BARRIER");
            Assert.IsTrue(false, "The test failed");
        }
Exemplo n.º 5
0
        public void Client()
        {
            PNUnitServices.Get().WriteLine("The client should wait until the server starts");
            PNUnitServices.Get().InitBarrier("BARRIER", 1);

            PNUnitServices.Get().EnterBarrier("BARRIER");

            Console.WriteLine("Server should be started now");
            Assert.IsTrue(true, "The test failed");
        }
Exemplo n.º 6
0
        static void EnterBarrier(string barrierName)
        {
            mBarrierLog.DebugFormat(
                ">>>Test {0} entering barrier {1}",
                PNUnitServices.Get().GetTestName(), barrierName);

            PNUnitServices.Get().EnterBarrier(barrierName);

            mBarrierLog.DebugFormat(
                "<<<Test {0} leavinf barrier {1}",
                PNUnitServices.Get().GetTestName(), barrierName);
        }
Exemplo n.º 7
0
 void PrintSeparator()
 {
     try
     {
         int repeat = Console.WindowWidth > 10 ? Console.WindowWidth - 2 : 80;
         PNUnitServices.Get().WriteLine(new string('-', repeat));
     }
     catch (IOException e)
     {
         mLog.WarnFormat("Cannot access to Console:[{0}]", e.Message);
     }
 }
Exemplo n.º 8
0
        public void Init()
        {
            testParams = PNUnitServices.Get().GetTestParams();
            string profile               = testParams[0];
            string environment           = testParams[1];
            NameValueCollection caps     = ConfigurationManager.GetSection("capabilities/" + profile) as NameValueCollection;
            NameValueCollection settings = ConfigurationManager.GetSection("environments/" + environment) as NameValueCollection;

            DesiredCapabilities capability = new DesiredCapabilities();

            foreach (string key in caps.AllKeys)
            {
                capability.SetCapability(key, caps[key]);
            }

            foreach (string key in settings.AllKeys)
            {
                capability.SetCapability(key, settings[key]);
            }

            String username = Environment.GetEnvironmentVariable("BROWSERSTACK_USERNAME");

            if (username == null)
            {
                username = ConfigurationManager.AppSettings.Get("user");
            }

            String accesskey = Environment.GetEnvironmentVariable("BROWSERSTACK_ACCESS_KEY");

            if (accesskey == null)
            {
                accesskey = ConfigurationManager.AppSettings.Get("key");
            }

            capability.SetCapability("browserstack.user", username);
            capability.SetCapability("browserstack.key", accesskey);

            if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true")
            {
                browserStackLocal = new Local();
                List <KeyValuePair <string, string> > bsLocalArgs = new List <KeyValuePair <string, string> >()
                {
                    new KeyValuePair <string, string>("key", accesskey)
                };
                browserStackLocal.start(bsLocalArgs);
            }

            driver = new RemoteWebDriver(new Uri("http://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/"), capability);
        }
Exemplo n.º 9
0
        static void LogTestException(
            string methodTestName, string testName, Exception ex)
        {
            mRunTestLog.ErrorFormat(
                "{1} {2} FAILED with exception '{3}':{0}{4}",
                Environment.NewLine,
                methodTestName,
                testName,
                ex.Message,
                ex.StackTrace);

            PNUnitServices.Get().WriteLine("Test {0} failed", methodTestName);
            PNUnitServices.Get().WriteLine("Message: {0}", ex.Message);
            PNUnitServices.Get().WriteLine("Stack trace: {0}", ex.StackTrace);
        }
Exemplo n.º 10
0
        static void RunTest(
            string methodTestname,
            ExecuteTestDelegate testDelegate,
            string binariesPath)
        {
            mRunTestLog.Info("1 stage");
            InitLog(methodTestname);

            string testName = PNUnitServices.Get().GetTestName();

            try
            {
                mRunTestLog.Info("2 stage");
                PNUnitServices.Get().SetInfoOSVersion(GetOSVersion());

                mRunTestLog.Info("Before GetTestParams");
                string[] testParams = PNUnitServices.Get().GetTestParams();

                mRunTestLog.Info("Before InitBarriers");
                PNUnitServices.Get().InitBarriers();

                mRunTestLog.Info("3 stage");
                EnterBarrier(PNUnitServices.Get().GetTestStartBarrier());

                mRunTestLog.Info("4 stage");

                if (PlatformUtils.CurrentPlatform == PlatformUtils.Platform.Linux)
                {
                    CheckMonoLibraries(binariesPath);
                    CheckMonoLibraries(Assembly.GetExecutingAssembly().Location);
                }

                mRunTestLog.Info("5 stage");

                string actualTestName = GetCleanTestName(testName);

                testDelegate?.Invoke(GetCleanTestName(testName));
            }
            catch (Exception ex)
            {
                LogTestException(methodTestname, testName, ex);
                throw;
            }
            finally
            {
                EnterBarrier(PNUnitServices.Get().GetTestEndBarrier());
            }
        }
Exemplo n.º 11
0
        static void CreatePNUnitServices(
            PNUnitTestInfo testInfo,
            TestRunner testRunner,
            IPNUnitServices services,
            TestConsoleAccess consoleAccess,
            TestLogInfo testLogInfo,
            ITestConsoleAccess extraConsoleAccess)
        {
            // Intialize the singleton
            new PNUnitServices(testInfo, services, consoleAccess, testLogInfo);

            if (extraConsoleAccess != null)
            {
                PNUnitServices.Get().RegisterConsole(extraConsoleAccess);
            }
        }
Exemplo n.º 12
0
		public void Init()
		{
			testParams = PNUnitServices.Get().GetTestParams();
			String params1 = String.Join(",", testParams);
			Console.WriteLine(params1);
			String browser = testParams[0];
			String version = testParams[1];
			String os = testParams[2];
			String os_version = testParams[3];
			DesiredCapabilities capability =  new DesiredCapabilities();
			capability.SetCapability("browserName", browser);
			capability.SetCapability(CapabilityType.Version, version);
			capability.SetCapability("os", os);
			capability.SetCapability("os_version", os_version);
			capability.SetCapability("browserstack.user", "<BrowserStack.user>");
			capability.SetCapability("browserstack.key", "<BrowserStack.key>");

			Console.WriteLine("Capabilities" + capability.ToString());

			driver = new RemoteWebDriver(new Uri("http://hub.browserstack.com:80/wd/hub/"), capability);
		}
Exemplo n.º 13
0
        public void Init()
        {
            testParams = PNUnitServices.Get().GetTestParams();
            String params1 = String.Join(",", testParams);

            Console.WriteLine(params1);
            String browser           = testParams[0];
            String version           = testParams[1];
            String platform          = testParams[2];
            DesiredCapabilities caps = new DesiredCapabilities();

            caps.SetCapability("browserName", browser);
            caps.SetCapability(CapabilityType.Version, version);
            caps.SetCapability(CapabilityType.Platform, platform);
            caps.SetCapability("username", Constants.SAUCE_LABS_ACCOUNT_NAME);
            caps.SetCapability("accessKey", Constants.SAUCE_LABS_ACCOUNT_KEY);
            caps.SetCapability("name", TestContext.CurrentContext.Test.Name);

            Console.WriteLine("Capabilities" + caps.ToString());

            driver = new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), caps, TimeSpan.FromSeconds(600));
            //driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(180));
        }
Exemplo n.º 14
0
        void SafeKillProcessTree(RunningTest runningTest)
        {
            if (runningTest == null)
            {
                return;
            }

            if (runningTest.TestProcess.HasExited)
            {
                return;
            }

            try
            {
                int ini = Environment.TickCount;

                string processPid = runningTest.TestProcess.Id.ToString();
                mLog.DebugFormat(
                    "SafeKillProcessTree: About to kill test with process tree PID [{0}] (Test name [{1}])",
                    processPid, runningTest.TestInfo.TestName);

                Codice.Test.OSProcessKillerCmd.KillProcessTree(processPid);

                PNUnitServices.Get().WriteLine(string.Format(
                                                   "Kill [{0}] took [{1} ms]",
                                                   runningTest.TestInfo.TestName,
                                                   Environment.TickCount - ini));
            }
            catch (Exception e)
            {
                mLog.ErrorFormat(
                    "SafeKillProcessTree: An error occurred trying " +
                    " to kill test process tree: {0}", e.Message);

                mLog.Debug(e.StackTrace);
            }
        }
Exemplo n.º 15
0
        private bool ReturnTestOutput()
        {
            string returnOutput = PNUnitServices.Get().GetUserValue("return_output");

            return(returnOutput == "true");
        }
Exemplo n.º 16
0
        public void Run(IPNUnitServices services)
        {
            try
            {
                TestResult result = null;

                TestRunner testRunner = null;

                TestConsoleAccess consoleAccess = new TestConsoleAccess(mPNUnitTestInfo.OutputFile);

                TestLogInfo testLogInfo = new TestLogInfo();

                try
                {
                    mLog.DebugFormat("Running test assembly {0}",
                                     mNUnitAssemblyPath);

                    ConsoleWriter outStream   = new ConsoleWriter(Console.Out);
                    ConsoleWriter errorStream = new ConsoleWriter(Console.Error);

                    testRunner = SetupTest(services, consoleAccess, testLogInfo);

                    if (testRunner == null)
                    {
                        return;
                    }

                    mLog.Debug("Running tests");

                    try
                    {
                        PNUnitServices.Get().InitBarriers();
                        PNUnitServices.Get().EnterBarrier(PNUnitServices.Get().GetTestStartBarrier());

                        result = RunNUnitAssembly(
                            services,
                            outStream,
                            testRunner,
                            Path.GetFileNameWithoutExtension(mPNUnitTestInfo.AssemblyName));

                        PNUnitServices.Get().EnterBarrier(PNUnitServices.Get().GetTestEndBarrier());
                    }
                    catch (Exception e)
                    {
                        mLog.ErrorFormat("Error running test {0}. {1}", mPNUnitTestInfo.TestName, e.Message);
                        mLog.Debug(e.StackTrace);

                        result = PNUnitTestRunner.BuildError(
                            mPNUnitTestInfo, e, consoleAccess, testLogInfo);
                    }
                }
                finally
                {
                    mLog.Info("Notifying the results");

                    PNUnitTestResult pnunitResult = PNUnitTestRunner.BuildResult(
                        mPNUnitTestInfo,
                        result, consoleAccess, testLogInfo);

                    mLog.Debug("Result built!! Now, notify the launcher ...");

                    try
                    {
                        services.NotifyResult(
                            mPNUnitTestInfo.TestName, pnunitResult);
                        mLog.Debug("<-Results NOTIFIED");
                    }
                    catch (Exception e)
                    {
                        mLog.ErrorFormat(
                            "Error notifying back the result of test {0}. {1}",
                            mPNUnitTestInfo.TestName, e.Message);
                        mLog.Error(
                            "If you're using a custom launcher.remoting.conf" +
                            " check that you've defined the binaryFormatter");
                    }

                    result = null;

                    UnloadTests(testRunner);
                }
            }
            catch (Exception ex)
            {
                mLog.ErrorFormat("Error running test {0} {1}",
                                 mPNUnitTestInfo.TestName, ex.Message);
                mLog.Debug(ex.StackTrace);
            }
        }
Exemplo n.º 17
0
 public virtual void Setup()
 {
     browser  = PNUnitServices.Get().GetTestParams();
     Selenium = new DefaultSelenium(localhost, 5555, browser, "http://www.google.com/");
     Selenium.Start();
 }