コード例 #1
0
        protected override void PostTestCleanup(object sender, PluginEventArgs e)
        {
            var settings = ConfigurationService.GetSection <LighthouseSettings>();

            if (settings.IsEnabled && WrappedWebDriverCreateService.BrowserConfiguration.ExecutionType == Web.Enums.ExecutionType.Regular)
            {
                lock (_lockObject)
                {
                    var driverExecutablePath = new DirectoryInfo(ExecutionDirectoryResolver.GetDriverExecutablePath());
                    var file = driverExecutablePath.GetFiles("*.report.json", SearchOption.AllDirectories).OrderByDescending(f => f.LastWriteTime).FirstOrDefault();
                    if (file != null && file.Exists)
                    {
                        TestContext.AddTestAttachment(file.FullName);
                    }

                    file = driverExecutablePath.GetFiles("*.report.html", SearchOption.AllDirectories).OrderByDescending(f => f.LastWriteTime).FirstOrDefault();
                    if (file != null && file.Exists)
                    {
                        TestContext.AddTestAttachment(file.FullName);
                    }

                    file = driverExecutablePath.GetFiles("*.report.csv", SearchOption.AllDirectories).OrderByDescending(f => f.LastWriteTime).FirstOrDefault();
                    if (file != null && file.Exists)
                    {
                        TestContext.AddTestAttachment(file.FullName);
                    }
                }
            }
        }
コード例 #2
0
        private dynamic FormatGridOptions(string option, Type testClassType)
        {
            if (bool.TryParse(option, out bool result))
            {
                return(result);
            }
            else if (option.StartsWith("env_") || option.StartsWith("vault_"))
            {
                return(SecretsResolver.GetSecret(() => option));
            }
            else if (option.StartsWith("AssemblyFolder", StringComparison.Ordinal))
            {
                var executionFolder = ExecutionDirectoryResolver.GetDriverExecutablePath();
                option = option.Replace("AssemblyFolder", executionFolder);

                if (RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX))
                {
                    option = option.Replace('\\', '/');
                }

                return(option);
            }
            else
            {
                var runName   = testClassType.Assembly.GetName().Name;
                var timestamp = $"{DateTime.Now:yyyyMMdd.HHmm}";
                return(option.Replace("{runName}", timestamp).Replace("{runName}", runName));
            }
        }
コード例 #3
0
        private string GetFFmpegPath()
        {
            string assemblyFolder    = ExecutionDirectoryResolver.GetDriverExecutablePath();
            string recorderFile      = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "ffmpeg.exe" : "ffmpeg";
            string recorderFinalPath = Path.Combine(assemblyFolder ?? throw new InvalidOperationException(), recorderFile);

            return(recorderFinalPath);
        }
コード例 #4
0
        private Root ReadPerformanceReport()
        {
            var    driverExecutablePath = ExecutionDirectoryResolver.GetDriverExecutablePath();
            var    directoryInfo        = new DirectoryInfo(driverExecutablePath);
            string pattern     = "*.report.json";
            var    file        = directoryInfo.GetFiles(pattern, SearchOption.AllDirectories).OrderByDescending(f => f.LastWriteTime).First();
            string fileContent = File.ReadAllText(file.FullName);

            return(JsonConvert.DeserializeObject <Root>(fileContent));
        }
コード例 #5
0
        public static string NormalizeAppPath(this string appPath)
        {
            if (string.IsNullOrEmpty(appPath))
            {
                return(appPath);
            }
            else if (appPath.StartsWith("AssemblyFolder", StringComparison.Ordinal))
            {
                var executionFolder = ExecutionDirectoryResolver.GetDriverExecutablePath();
                appPath = appPath.Replace("AssemblyFolder", executionFolder);
            }

            return(appPath);
        }
コード例 #6
0
        private string NormalizeRequestFilePath(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                return(path);
            }
            else if (path.StartsWith("AssemblyFolder", StringComparison.Ordinal))
            {
                var executionFolder = ExecutionDirectoryResolver.GetDriverExecutablePath();
                path = path.Replace("AssemblyFolder", executionFolder);

                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    path = path.Replace('\\', '/');
                }
            }

            return(path);
        }
コード例 #7
0
        private static IConfigurationRoot InitializeConfiguration()
        {
            var builder             = new ConfigurationBuilder();
            var executionDir        = ExecutionDirectoryResolver.GetDriverExecutablePath();
            var filesInExecutionDir = Directory.GetFiles(executionDir);
            var settingsFile        =
#pragma warning disable CA1310 // Specify StringComparison for correctness
                filesInExecutionDir.FirstOrDefault(x => x.Contains("testFrameworkSettings") && x.EndsWith(".json"));

#pragma warning restore CA1310 // Specify StringComparison for correctness
            if (settingsFile != null)
            {
                builder.AddJsonFile(settingsFile, optional: true, reloadOnChange: true);
            }

            builder.AddEnvironmentVariables();

            return(builder.Build());
        }
コード例 #8
0
        public void PerformLighthouseAnalysis(string customArgs = "", bool shouldOverrideDefaultArgs = false)
        {
            var    browserService = ServicesCollection.Current.Resolve <BrowserService>();
            string arguments;

            if (shouldOverrideDefaultArgs)
            {
                arguments = $"lighthouse {browserService.Url} --output=json,html,csv --port={WrappedWebDriverCreateService.DebuggerPort} {customArgs}";
            }
            else
            {
                var defaultArgs = GetDefaultLighthouseArgs();
                arguments = $"lighthouse {browserService.Url} --output=json,html,csv --port={WrappedWebDriverCreateService.DebuggerPort} {defaultArgs} {customArgs}";
            }

            var settings = ConfigurationService.GetSection <LighthouseSettings>();

            if (WrappedWebDriverCreateService.BrowserConfiguration.ExecutionType == Web.Enums.ExecutionType.Regular)
            {
                var driverExecutablePath = ExecutionDirectoryResolver.GetDriverExecutablePath();
                ProcessProvider.StartCLIProcessAndWaitToFinish(driverExecutablePath, arguments, false, settings.Timeout, o => Console.WriteLine(o), e => Console.WriteLine(e));

                PerformanceReport.Value = ReadPerformanceReport();
            }
            else if (WrappedWebDriverCreateService.BrowserConfiguration.ExecutionType == Web.Enums.ExecutionType.Grid)
            {
                var app = ServicesCollection.Current.Resolve <App>();
                app.ApiClient.BaseUrl = ((RemoteWebDriver)browserService.WrappedDriver).Url;
                var request     = new RestRequest($"/grid/admin/HubRemoteHostRetrieverServlet/session/{((RemoteWebDriver)browserService.WrappedDriver).SessionId}/", Method.GET);
                var queryResult = app.ApiClient.Execute(request);
                app.ApiClient.BaseUrl = $"http://{queryResult.Content}";
                request = new RestRequest($"/extra/LighthouseServlet", Method.GET);
                request.AddHeader("lighthouse", arguments.Replace("lighthouse ", string.Empty));
                PerformanceReport.Value = app.ApiClient.Get <Root>(request).Data;
            }
            else
            {
                throw new NotSupportedException("Lighthouse analysis is supported only for regular and grid mode executions.");
            }
        }