Пример #1
0
 public void AttachStepScreenshot(ScenarioContext scenarioContext, FeatureContext featureContext)
 {
     if (featureContext.TryGetValue("ScenarioScreenshots", out Dictionary <string, string> screenshots) && (featureContext.TryGetValue(out FeatureDto featureDto) && featureDto.Scenarios.TryGetValue(GetScenarioTitle(scenarioContext), out ScenarioDto scenario)))
     {
         scenario.Screenshots = screenshots;
     }
 }
Пример #2
0
 private static List <DateTime> GetRegistrationAttempts(this FeatureContext featureContext)
 {
     if (!featureContext.TryGetValue(RegistrationAttempts, out List <DateTime> _))
     {
         SetRegistrationAttempts(featureContext, new List <DateTime>());
     }
     return(featureContext.Get <List <DateTime> >(RegistrationAttempts));
 }
 public static BoardImageBehavior ImageBehavior(this FeatureContext featureContext)
 {
     if (featureContext.TryGetValue <BoardImageBehavior>(nameof(ImageBehavior), out var behavior))
     {
         return(behavior);
     }
     featureContext[nameof(ImageBehavior)] = BoardImageBehavior.EveryChange;
     return(BoardImageBehavior.EveryChange);
 }
        private static List <DateTime> GetLoginAttempts(this FeatureContext featureContext)
        {
            List <DateTime> loginAttempts;

            if (!featureContext.TryGetValue(LoginAttempts, out loginAttempts))
            {
                SetLoginAttempts(featureContext, new List <DateTime>());
            }
            return(featureContext.Get <List <DateTime> >(LoginAttempts));
        }
        private static List <DateTime> GetLoginAttempts(this FeatureContext featureContext)
        {
            List <DateTime> loginAttempts = null;

            if (!featureContext.TryGetValue <List <DateTime> >(LOGIN_ATTEMPTS, out loginAttempts))
            {
                SetLoginAttempts(featureContext, new List <DateTime>());
            }
            return(featureContext.Get <List <DateTime> >(LOGIN_ATTEMPTS));
        }
Пример #6
0
        public void DoCleanUp()
        {
            _featureContext.TryGetValue("currentEnvironment", out IServer currentEnvironment);
            _featureContext.TryGetValue("environment", out IServer server);
            _featureContext.TryGetValue("initialSettings", out Data.Settings.Settings currentSettings);

            if (server != null)
            {
                try
                {
                    if (currentSettings != null)
                    {
                        server.ResourceRepository.WriteSettings(server, currentSettings);
                    }
                }
                finally { server.Disconnect(); }
            }
            currentEnvironment?.Disconnect();
        }
Пример #7
0
        public static T GetApplication <T>(this FeatureContext featureContext) where T : Application
        {
            var browser = default(object);

            if (featureContext.TryGetValue(ApplicationKey, out browser) && browser is T)
            {
                return(browser as T);
            }

            throw new ApplicationException("Application is not stored in context as expected");
        }
Пример #8
0
        public static IWebDriver GetBrowser(this FeatureContext featureContext)
        {
            var browser = default(object);

            if (featureContext.TryGetValue(BrowserKey, out browser) && browser is IWebDriver)
            {
                return(browser as IWebDriver);
            }

            throw new ApplicationException("Browser is not stored in context as expcected");
        }
Пример #9
0
        public void TakeScreenshotToContext(FeatureContext FeatureContext, string fileNameKey = null, string prefix = null)
        {
            var featureTitle = FeatureContext.FeatureInfo.Title;

            featureTitle = featureTitle.Length > 10 ? featureTitle.Substring(0, 10) : featureTitle;
            var screenshotPath = TakeScreenshot(featureTitle, prefix);

            if (!FeatureContext.TryGetValue("ScenarioScreenshots", out Dictionary <string, string> screenshots))
            {
                screenshots = new Dictionary <string, string>();
                FeatureContext.Add("ScenarioScreenshots", screenshots);
            }
            screenshots.Add(fileNameKey ?? screenshotPath.Split("\\")[^ 1], screenshotPath);
Пример #10
0
        /// <summary>
        /// Gets the electronic reader service.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns>Reader service.</returns>
        /// <exception cref="System.ArgumentNullException">context - The 'context' argument cannot be null</exception>
        /// <exception cref="System.InvalidOperationException">Cannot get reader service: the value is not set for the key 'readerService'</exception>
        public static ElectronicReaderService GetElectronicReaderService(this FeatureContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context), "The 'context' argument cannot be null");
            }

            ElectronicReaderService readerService;

            if (!context.TryGetValue("readerService", out readerService))
            {
                throw new InvalidOperationException("Cannot get reader service: the value is not set for the key 'readerService'");
            }

            return(readerService);
        }
        public static Random GetRandom(FeatureContext featureContext, ScenarioContext scenarioContext)
        {
            Assert.NotNull(featureContext);
            Assert.NotNull(scenarioContext);

            object randomObject;

            if (featureContext.TryGetValue(EmuRandomGeneratorKey, out randomObject))
            {
                if (randomObject is Random)
                {
                    return(randomObject as Random);
                }
            }

            var random = new Random();

            featureContext[EmuRandomGeneratorKey] = random;
            return(random);
        }
        public static bool HasWebDriver(this FeatureContext fc)
        {
            IWebDriver webDriver;

            return(fc.TryGetValue(out webDriver));
        }
Пример #13
0
        protected override void BuildDataList()
        {
            scenarioContext.TryGetValue("variableList", out List <Tuple <string, string> > variableList);

            if (variableList == null)
            {
                variableList = new List <Tuple <string, string> >();
                scenarioContext.Add("variableList", variableList);
            }

            variableList.Add(new Tuple <string, string>(ResultVariable, ""));
            BuildShapeAndTestData();

            scenarioContext.TryGetValue("scriptToExecute", out string scriptToExecute);
            scenarioContext.TryGetValue("language", out enScriptType language);
            scenarioContext.TryGetValue("javascript", out DsfJavascriptActivity javascriptActivity);

            if (javascriptActivity != null)
            {
                javascriptActivity.Script = scriptToExecute;
                javascriptActivity.Result = ResultVariable;

                TestStartNode = new FlowStep
                {
                    Action = javascriptActivity
                };
                scenarioContext.Add("activity", javascriptActivity);
                return;
            }

            _featureContext.TryGetValue("pythonActivity", out DsfPythonActivity pythonActivity);

            if (pythonActivity != null)
            {
                pythonActivity.Script = scriptToExecute;
                pythonActivity.Result = ResultVariable;

                TestStartNode = new FlowStep
                {
                    Action = pythonActivity
                };
                scenarioContext.Add("activity", pythonActivity);
                return;
            }

            _featureContext.TryGetValue("rubyActivity", out DsfRubyActivity rubyActivity);

            if (rubyActivity != null)
            {
                rubyActivity.Script = scriptToExecute;
                rubyActivity.Result = ResultVariable;

                TestStartNode = new FlowStep
                {
                    Action = rubyActivity
                };
                scenarioContext.Add("activity", rubyActivity);
                return;
            }

            var dsfScripting = new DsfScriptingActivity
            {
                Script     = scriptToExecute,
                ScriptType = language,
                Result     = ResultVariable
            };

            TestStartNode = new FlowStep
            {
                Action = dsfScripting
            };
            scenarioContext.Add("activity", dsfScripting);
        }
        /// <summary>
        ///     Start a functions instance.
        /// </summary>
        /// <param name="featureContext">The current feature context.</param>
        /// <param name="scenarioContext">The current scenario context. Not required if using this class per-feature.</param>
        /// <param name="path">The location of the functions project.</param>
        /// <param name="port">The port on which to start the functions instance.</param>
        /// <param name="runtime">The runtime version, defaults to netcoreapp2.1.</param>
        /// <param name="provider">The functions provider. Defaults to csharp.</param>
        /// <returns>A task that completes once the function instance has started.</returns>
        public async Task StartFunctionsInstance(
            FeatureContext featureContext,
            ScenarioContext?scenarioContext,
            string path,
            int port,
            string runtime  = "netcoreapp2.1",
            string provider = "csharp")
        {
            Console.WriteLine($"Starting a function instance for project {path} on port {port}");

            string directoryExtension = $"\\bin\\release\\{runtime}";

            string lowerInvariantCurrentDirectory = TestContext.CurrentContext.TestDirectory.ToLowerInvariant();

            if (lowerInvariantCurrentDirectory.Contains("debug"))
            {
                directoryExtension = $"\\bin\\debug\\{runtime}";
            }

            Console.WriteLine($"\tCurrent directory: {lowerInvariantCurrentDirectory}");

            string root = TestContext.CurrentContext.TestDirectory.Substring(
                0,
                TestContext.CurrentContext.TestDirectory.IndexOf(@"\Solutions\") + 11);

            Console.WriteLine($"\tRoot: {root}");

            string npmPrefix = await GetNpmPrefix().ConfigureAwait(false);

            string toolsFolder = Path.Combine(
                npmPrefix,
                @"node_modules\azure-functions-core-tools\bin");

            Assert.IsTrue(
                Directory.Exists(toolsFolder),
                $"Azure Functions runtime not found at {toolsFolder}. Have you run: 'npm install -g azure-functions-core-tools --unsafe-perm true'?");
            string toolPath = Path.Combine(
                toolsFolder,
                "func");

            Console.WriteLine($"\tToolsPath: {toolPath}");

            Console.WriteLine($"\tStarting process");

            var startInfo = new ProcessStartInfo(toolPath, $"host start --port {port} --{provider}")
            {
                WorkingDirectory       = root + path + directoryExtension,
                UseShellExecute        = false,
                CreateNoWindow         = false,
                RedirectStandardError  = true,
                RedirectStandardOutput = true,
                RedirectStandardInput  = true,
                WindowStyle            = ProcessWindowStyle.Normal,
            };

            FunctionConfiguration?functionConfiguration = null;

            scenarioContext?.TryGetValue(out functionConfiguration);

            if (functionConfiguration == null)
            {
                featureContext.TryGetValue(out functionConfiguration);
            }

            if (functionConfiguration != null)
            {
                foreach (KeyValuePair <string, string> kvp in functionConfiguration.EnvironmentVariables)
                {
                    startInfo.EnvironmentVariables[kvp.Key] = kvp.Value;
                }
            }

            var bufferHandler = new FunctionOutputBufferHandler(startInfo);

            lock (this.sync)
            {
                this.output[bufferHandler.Process] = bufferHandler;
            }

            Console.WriteLine($"\tProcess started; waiting for initialisation to complete");

            await Task.WhenAny(
                bufferHandler.JobHostStarted,
                bufferHandler.ExitCode,
                Task.Delay(TimeSpan.FromSeconds(StartupTimeout))).ConfigureAwait(false);

            if (bufferHandler.ExitCode.IsCompleted)
            {
                int exitCode = await bufferHandler.ExitCode.ConfigureAwait(false);

                Assert.Fail($"Function host process terminated unexpectedly with exit code {exitCode}. Error output: {bufferHandler.StandardErrorText}");
            }
            else if (!bufferHandler.JobHostStarted.IsCompleted)
            {
                Assert.Fail("Timed out while starting functions instance.");
            }
            else
            {
                Console.WriteLine();
                Console.WriteLine("\tStarted");
            }
        }