Exemplo n.º 1
0
 public void TestSetup()
 {
     TestContext.TestAdapter testData = TestContext.CurrentContext.Test;
     TestUtils.SetupLogging(eyes_, testData.Name);
     eyes_.Open(driver_, "DotNet Tests", testData.Name);
     eyes_.Logger.Log("iOS Driver Session Details: " + JsonConvert.SerializeObject(driver_.SessionDetails, Formatting.Indented));
 }
Exemplo n.º 2
0
        public static TOptions GetTestOptions <TOptions>()
            where TOptions : TestOptionAttributeBase, new()
        {
            TestContext.TestAdapter test = TestContext.CurrentContext.Test;
            var typeName   = test.ClassName;
            var methodName = test.MethodName;

            // This will only get types from whatever is already loaded in the app domain.
            var type = Type.GetType(typeName, false);

            if (type == null)
            {
                // automatically add the executing and calling assemblies to the list to scan for this type
                var scanAssemblies = ScanAssemblies.Union(new[] { Assembly.GetExecutingAssembly(), Assembly.GetCallingAssembly() }).ToList();

                type = scanAssemblies
                       .Select(assembly => assembly.GetType(typeName, false))
                       .FirstOrDefault(x => x != null);
                if (type == null)
                {
                    throw new PanicException($"Could not resolve the running test fixture from type name {typeName}.\n" +
                                             $"To use base classes from Umbraco.Tests, add your test assembly to TestOptionAttributeBase.ScanAssemblies");
                }
            }

            MethodInfo methodInfo = type.GetMethod(methodName); // what about overloads?
            TOptions   options    = GetTestOptions <TOptions>(methodInfo);

            return(options);
        }
Exemplo n.º 3
0
        //Takes the screenshot and will save file in bin/debug
        private string TakeScreenshot(TestContext.TestAdapter test)
        {
            var testName = GetScreenshotFileName(test);
            var fileName = GetFileName(testName, SeleniumCoreSettings.ScreenshotLocation);
            var tsc      = Browser as ITakesScreenshot;

            if (tsc != null)
            {
                try
                {
                    CreateDirectoryIfNotExists(fileName);
                    var ss = tsc.GetScreenshot();
                    ss.SaveAsFile(fileName, ScreenshotImageFormat.Png);
                    _log.InfoFormat("Browser saved the Screenshot: {0}", fileName);
                }
                catch (Exception ex)
                {
                    _log.ErrorFormat(string.Format("Failed to save screenshot: {0}", ex));
                }
            }
            else
            {
                _log.Error("Browser (as ITakesScreenshot) could not take the Screenshot ()");
            }

            return(fileName);
        }
        public static string NormalizedName(this TestContext.TestAdapter test)
        {
            // e.g. -
            // 'ModuleToModuleDirectMethod("Mqtt","Amqp")' ==>
            //     'moduletomoduledirectmethod-mqtt-amqp'
            IEnumerable <string> parts = Regex.Split(test.Name, @"[^\w]")
                                         .Where(s => !string.IsNullOrEmpty(s));

            return(string.Join("-", parts).ToLowerInvariant());
        }
Exemplo n.º 5
0
        public static TOptions GetTestOptions <TOptions>()
            where TOptions : TestOptionAttributeBase, new()
        {
            TestContext.TestAdapter test = TestContext.CurrentContext.Test;
            var        methodName        = test.MethodName;
            var        type       = TestExecutionContext.CurrentContext.TestObject.GetType();
            MethodInfo methodInfo = type.GetMethod(methodName); // what about overloads?
            TOptions   options    = GetTestOptions <TOptions>(methodInfo);

            return(options);
        }
Exemplo n.º 6
0
 public virtual void StartTestRecording()
 {
     // Only create test recordings for the latest version of the service
     TestContext.TestAdapter test = TestContext.CurrentContext.Test;
     if (Mode != RecordedTestMode.Live &&
         test.Properties.ContainsKey("SkipRecordings"))
     {
         throw new IgnoreException((string)test.Properties.Get("SkipRecordings"));
     }
     Recording = new TestRecording(Mode, GetSessionFilePath(), Sanitizer, Matcher);
 }
Exemplo n.º 7
0
        private string GetSessionFilePath(string name = null)
        {
            TestContext.TestAdapter testAdapter = TestContext.CurrentContext.Test;

            name ??= testAdapter.Name;

            string className = testAdapter.ClassName.Substring(testAdapter.ClassName.LastIndexOf('.') + 1);
            string fileName  = name + (IsAsync ? "Async" : string.Empty) + ".json";

            return(Path.Combine(TestContext.CurrentContext.TestDirectory, "SessionRecords", className, fileName));
        }
Exemplo n.º 8
0
        private string GetSessionFilePath()
        {
            TestContext.TestAdapter testAdapter = TestContext.CurrentContext.Test;

            string name = new string(testAdapter.Name.Select(c => s_invalidChars.Contains(c) ? '%' : c).ToArray());

            string className = testAdapter.ClassName.Substring(testAdapter.ClassName.LastIndexOf('.') + 1);
            string fileName  = name + (IsAsync ? "Async" : string.Empty) + ".json";

            return(Path.Combine(TestContext.CurrentContext.TestDirectory, "SessionRecords", className, fileName));
        }
        protected virtual string GetTestName()
        {
            StringBuilder sb = new StringBuilder();

            TestContext.TestAdapter ta = TestContext.CurrentContext.Test;
            sb.Append(ta.MethodName);

            //AppendArguments(sb, suiteArgs_.ToArray(), " [", "]");
            AppendArguments(sb, ta.Arguments, " (", ")");

            return(sb.ToString());
        }
 private void StartSessionRecording()
 {
     // Only create test recordings for the latest version of the service
     TestContext.TestAdapter test = TestContext.CurrentContext.Test;
     if (Mode != RecordedTestMode.Live &&
         test.Properties.ContainsKey("SkipRecordings"))
     {
         throw new IgnoreException((string)test.Properties.Get("SkipRecordings"));
     }
     SessionRecording = new TestRecording(Mode, GetSessionFilePath(), Sanitizer, Matcher);
     SessionEnvironment.SetRecording(SessionRecording);
     ValidateClientInstrumentation = SessionRecording.HasRequests;
 }
Exemplo n.º 11
0
        public virtual TClient InstrumentClient <TClient>(TClient client, IEnumerable <IInterceptor> preInterceptors) where TClient : class
        {
            Debug.Assert(!client.GetType().Name.EndsWith("Proxy"), $"{nameof(client)} was already instrumented");

            if (ClientValidation <TClient> .Validated == false)
            {
                foreach (MethodInfo methodInfo in typeof(TClient).GetMethods(BindingFlags.Instance | BindingFlags.Public))
                {
                    if (methodInfo.Name.EndsWith("Async") && !methodInfo.IsVirtual)
                    {
                        ClientValidation <TClient> .ValidationException = new InvalidOperationException($"Client type contains public non-virtual async method {methodInfo.Name}");

                        break;
                    }
                }

                ClientValidation <TClient> .Validated = true;
            }

            if (ClientValidation <TClient> .ValidationException != null)
            {
                throw ClientValidation <TClient> .ValidationException;
            }

            List <IInterceptor> interceptors = new List <IInterceptor>();

            if (preInterceptors != null)
            {
                interceptors.AddRange(preInterceptors);
            }

            if (TestDiagnostics)
            {
                interceptors.Add(s_diagnosticScopeValidatingInterceptor);
            }

            // Ignore the async method interceptor entirely if we're running a
            // a SyncOnly test
            TestContext.TestAdapter test = TestContext.CurrentContext.Test;
            bool?isSyncOnly = (bool?)test.Properties.Get(ClientTestFixtureAttribute.SyncOnlyKey);

            if (isSyncOnly != true)
            {
                interceptors.Add(IsAsync ? s_avoidSyncInterceptor : s_useSyncInterceptor);
            }

            return(s_proxyGenerator.CreateClassProxyWithTarget(client, interceptors.ToArray()));
        }
Exemplo n.º 12
0
        private string GetScreenshotFileName(TestContext.TestAdapter test)
        {
            var filename = SeleniumCoreSettings.ScreenShotNameFormat;

            filename = filename.Replace("{driverName}", Browser.GetType().Name);
            filename = filename.Replace("{fullDriverName}", Browser.GetType().FullName);
            filename = filename.Replace("{testName}", test.Name);
            // I don't currently have a way to get the full test name without the driver name (NUnit includes it by default)
            filename = filename.Replace("{fullTestNameWithDriver}", test.FullName);
            filename = filename.Replace("{className}", this.GetType().Name);
            filename = filename.Replace("{fullClassName}", this.GetType().FullName);
            filename = filename.Replace("{sessionId}", GetSessionId());
            filename = filename.Replace("{browserName}", BrowserName);

            filename = string.Concat(filename, "_", DateTime.Now.ToString("yyyy-MM-dd-HH-mm", CultureInfo.InvariantCulture), ".png");

            return(filename);
        }
Exemplo n.º 13
0
        private string GetSessionFilePath()
        {
            TestContext.TestAdapter testAdapter = TestContext.CurrentContext.Test;

            string name = new string(testAdapter.Name.Select(c => s_invalidChars.Contains(c) ? '%' : c).ToArray());
            string additionalParameterName = testAdapter.Properties.ContainsKey(ClientTestFixtureAttribute.RecordingDirectorySuffixKey) ?
                                             testAdapter.Properties.Get(ClientTestFixtureAttribute.RecordingDirectorySuffixKey).ToString() :
                                             null;

            string className = testAdapter.ClassName.Substring(testAdapter.ClassName.LastIndexOf('.') + 1);

            string fileName = name + (IsAsync ? "Async" : string.Empty) + ".json";

            return(Path.Combine(TestContext.CurrentContext.TestDirectory,
                                "SessionRecords",
                                additionalParameterName == null ? className : $"{className}({additionalParameterName})",
                                fileName));
        }
Exemplo n.º 14
0
        public void BeforeAll()
        {
            report = ReportManager.Instance;

            TestContext.TestAdapter testAdapter = TestContext.CurrentContext.Test;

            testInfo = new ReporterTestInfo();

            testInfo.TestName = testAdapter.Name;
            testInfo.FullyQualifiedTestClassName = testAdapter.FullName;

            testInfo.Status = DifidoTestStatus.success;

            testStopwatch = new Stopwatch();
            testStopwatch.Start();

            report.StartTest(testInfo);
        }
Exemplo n.º 15
0
        public static void ExtractImagesFromTestProperties(TestContext.TestAdapter test)
        {
            if (!(test.Properties.ContainsKey("Image") ||
                  test.Properties.ContainsKey("DiffImage")))
            {
                return;
            }

            var colorSpace     = UseGraphicsTestCasesAttribute.Provider.ColorSpace;
            var platform       = UseGraphicsTestCasesAttribute.Provider.Platform;
            var graphicsDevice = UseGraphicsTestCasesAttribute.Provider.GraphicsDevice;

            var dirName = Path.Combine(ActualImagesRoot, string.Format("{0}/{1}/{2}", colorSpace, platform, graphicsDevice));

            if (!Directory.Exists(dirName))
            {
                Directory.CreateDirectory(dirName);
            }

            var imagesWritten = new HashSet <string>();

            if (test.Properties.ContainsKey("Image"))
            {
                var bytes = Convert.FromBase64String((string)TestContext.CurrentContext.Test.Properties.Get("Image"));
                var path  = Path.Combine(dirName, TestContext.CurrentContext.Test.Name + ".png");
                File.WriteAllBytes(path, bytes);
                imagesWritten.Add(path);
            }

            if (test.Properties.ContainsKey("DiffImage"))
            {
                var bytes = Convert.FromBase64String((string)TestContext.CurrentContext.Test.Properties.Get("DiffImage"));
                var path  = Path.Combine(dirName, TestContext.CurrentContext.Test.Name + ".diff.png");
                File.WriteAllBytes(path, bytes);
                imagesWritten.Add(path);
            }

            AssetDatabase.Refresh();

            Utils.SetupReferenceImageImportSettings(imagesWritten);
        }
Exemplo n.º 16
0
        private string GetSessionFilePath()
        {
            TestContext.TestAdapter testAdapter = TestContext.CurrentContext.Test;

            string name = new string(testAdapter.Name.Select(c => s_invalidChars.Contains(c) ? '%' : c).ToArray());
            string additionalParameterName = testAdapter.Properties.ContainsKey(ClientTestFixtureAttribute.RecordingDirectorySuffixKey) ?
                                             testAdapter.Properties.Get(ClientTestFixtureAttribute.RecordingDirectorySuffixKey).ToString() :
                                             null;

            // Use the current class name instead of the name of the class that declared a test.
            // This can be used in inherited tests that, for example, use a different endpoint for the same tests.
            string className = GetType().Name;

            string fileName = name + (IsAsync ? "Async" : string.Empty) + ".json";

            string path = ((AssemblyMetadataAttribute)GetType().Assembly.GetCustomAttribute(typeof(AssemblyMetadataAttribute))).Value;

            return(Path.Combine(path,
                                "SessionRecords",
                                additionalParameterName == null ? className : $"{className}({additionalParameterName})",
                                fileName));
        }
        protected virtual Dictionary <string, object> GetTestParameters()
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            foreach (KeyValuePair <string, object> suiteArg in suiteArgs_)
            {
                result.Add(suiteArg.Key, suiteArg.Value);
            }
            TestContext tc = TestContext.CurrentContext;

            TestContext.TestAdapter test = tc.Test;
            Type       type = Type.GetType(test.ClassName);
            MethodInfo mi   = type.GetMethod(test.MethodName);

            ParameterInfo[] pis = mi.GetParameters();
            for (int i = 0; i < pis.Length; ++i)
            {
                string paramName  = pis[i].Name;
                object paramValue = test.Arguments[i];
                result.Add(paramName, paramValue);
            }
            return(result);
        }
Exemplo n.º 18
0
        protected internal virtual object InstrumentClient(Type clientType, object client, IEnumerable <IInterceptor> preInterceptors)
        {
            if (client is IProxyTargetAccessor)
            {
                // Already instrumented
                return(client);
            }

            lock (s_clientValidation)
            {
                if (!s_clientValidation.TryGetValue(clientType, out var validationException))
                {
                    foreach (MethodInfo methodInfo in clientType.GetMethods(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (methodInfo.Name.EndsWith("Async") && !methodInfo.IsVirtual)
                        {
                            validationException = new InvalidOperationException($"Client type contains public non-virtual async method {methodInfo.Name}");

                            break;
                        }

                        if (methodInfo.Name.EndsWith("Client") &&
                            methodInfo.Name.StartsWith("Get") &&
                            !methodInfo.IsVirtual)
                        {
                            validationException = new InvalidOperationException($"Client type contains public non-virtual Get*Client method {methodInfo.Name}");

                            break;
                        }
                    }

                    s_clientValidation[clientType] = validationException;
                }

                if (validationException != null)
                {
                    throw validationException;
                }
            }

            List <IInterceptor> interceptors = new List <IInterceptor>();

            if (preInterceptors != null)
            {
                interceptors.AddRange(preInterceptors);
            }

            interceptors.Add(new GetOriginalInterceptor(client));

            if (TestDiagnostics)
            {
                interceptors.Add(s_diagnosticScopeValidatingInterceptor);
            }

            interceptors.Add(new InstrumentResultInterceptor(this));

            // Ignore the async method interceptor entirely if we're running a
            // a SyncOnly test
            TestContext.TestAdapter test = TestContext.CurrentContext.Test;
            bool?isSyncOnly = (bool?)test.Properties.Get(ClientTestFixtureAttribute.SyncOnlyKey);

            if (isSyncOnly != true)
            {
                interceptors.Add(IsAsync ? s_avoidSyncInterceptor : s_useSyncInterceptor);
            }

            return(ProxyGenerator.CreateClassProxyWithTarget(
                       clientType,
                       new[] { typeof(IInstrumented) },
                       client,
                       interceptors.ToArray()));
        }
Exemplo n.º 19
0
 public static string GetDescription(this TestContext.TestAdapter adapter)
 {
     return((string)adapter.Properties["_DESCRIPTION"].FirstOrDefault());
 }
 public static string Expectation(this TestContext.TestAdapter operand)
 {
     return(operand.Properties["Description"][0].ToString());
 }
Exemplo n.º 21
0
 private string GetScreenshotNameForTest(TestContext.TestAdapter test)
 {
     return($"{test.ClassName}_{test.MethodName}_{DateTime.Now.ToString("yyyyMMhh_HHmmss")}.png");
 }