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"); }
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"); }
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); } }
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); }
static void RunPreload(string pathToAssemblies) { mLog.Debug("Preload started. Path To assemblies:" + pathToAssemblies); InitServices.InitNUnitServices(); PNUnitTestRunner runner = new PNUnitTestRunner(pathToAssemblies); runner.Preload(); int pidOfThisExpectedByAgent = Codice.Test.PlatformIdentifier.IsWindows() ? System.Diagnostics.Process.GetCurrentProcess().Id : Mono.Unix.UnixEnvironment.GetParentProcessId(); string testInfoFile = Path.Combine( Path.GetTempPath(), PNUnit.Agent.AssemblyPreload.PRELOADED_PROCESS_FILE_PREFIX + pidOfThisExpectedByAgent.ToString()); int count = 0; while (!File.Exists(testInfoFile)) { System.Threading.Thread.Sleep(150); mLog.DebugFormat("Waiting for testinfo file to be created...: {0}", testInfoFile); count++; if (count >= 6000) //wait 1,5 minutes for test arrival { mLog.Fatal("Tired of waiting: Cannot execute tests without information; exiting ..."); Environment.Exit(1); } } mLog.DebugFormat("Preload read {0} from file", testInfoFile); PNUnitTestInfo info = TestInfoReader.ReadTestInfo(testInfoFile); if (info == null) { mLog.Fatal("Cannot execute tests without information; exiting ..."); Environment.Exit(1); } ProcessNameSetter.SetProcessName(info.TestName); IPNUnitServices services = PNUnitServices.GetPNunitServicesProxy(info.PNUnitServicesServer); runner.Run(info, services, null); }
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); }
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); }
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()); } }
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); } }
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); }
static void RunOnce(string testInfoFile, string pathToAssemblies) { PNUnitTestInfo info = TestInfoReader.ReadTestInfo(testInfoFile); if (info == null) { Console.WriteLine("Cannot execute tests without information; exiting ..."); Environment.Exit(1); } ProcessNameSetter.SetProcessName(info.TestName); IPNUnitServices services = PNUnitServices.GetPNunitServicesProxy(info.PNUnitServicesServer); if (info.TestName.StartsWith("run-nunit")) { new NUnitTestRunner(info, pathToAssemblies).Run(services); return; } new PNUnitTestRunner(pathToAssemblies).Run(info, services, null); }
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)); }
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); } }
static IPNUnitServices GetPNUnitServices(string server) { return(string.IsNullOrEmpty(server) ? new DummyPnunitServices() : PNUnitServices.GetPNunitServicesProxy(server)); }
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); } }
private bool ReturnTestOutput() { string returnOutput = PNUnitServices.Get().GetUserValue("return_output"); return(returnOutput == "true"); }
public virtual void Setup() { browser = PNUnitServices.Get().GetTestParams(); Selenium = new DefaultSelenium(localhost, 5555, browser, "http://www.google.com/"); Selenium.Start(); }