Inheritance: IHaveTestResults, IEntity
Ejemplo n.º 1
0
 public virtual LinkedCriterion AddCriterion(CriterionType type, Criterion criterion)
 {
     var priority = LinkedCriteria.Count() + 1;
     var linkedCriterion = new LinkedCriterion(Guid.NewGuid(), this, type, criterion, priority);
     ((IList<LinkedCriterion>)LinkedCriteria).Add(linkedCriterion);
     return linkedCriterion;
 }
Ejemplo n.º 2
0
 public void CleanUp(ScenarioContext scenarioContext, LinkedCriterion linkedCriterion)
 {
     bool isTheLastCriterion = linkedCriterion.Scenario.GetLinkedCriteria().Last() == linkedCriterion;
     if (isTheLastCriterion)
     {
         IWebDriver driver;
         Guid contextId = scenarioContext.Id;
         if (ScenarioWebDrivers.TryGetValue(contextId, out driver))
         {
             try
             {
                 driver.Close();
                 driver.Quit();
             }
             catch (Exception)
             {                        
                 //do nothing 
             }
             finally
             {
                 ScenarioWebDrivers.Remove(contextId);
             }
         }
     }
 }
Ejemplo n.º 3
0
 public bool Run(LinkedCriterion linkedCriterion, ScenarioContext scenarioContext)
 {
     PrepareStepsWithTokenReplacements(linkedCriterion, scenarioContext);
     IWebDriver webDriver = _webDriverProvider.GetForScenario(scenarioContext);
     bool runCriterion = RunCriterion(webDriver, linkedCriterion);
     _webDriverProvider.CleanUp(scenarioContext, linkedCriterion);
     return runCriterion;
 }
Ejemplo n.º 4
0
        bool RunCriterion(IWebDriver webDriver, LinkedCriterion linkedCriterion)
        {
            bool passing = true;
            foreach (Step step in linkedCriterion.Criterion.GetSteps().OrderBy(x => x.Priority))
            {
                DateTime start = DateTime.Now;
                try
                {
                    StepStarted(new StepRunnerEventArgs(linkedCriterion.Scenario.Id, linkedCriterion.Criterion.Id,
                        step.Id, DateTime.Now));

                    IBrowserStepStrategy browserStepStrategy = _browserStepStrategyFactory.Create(step);
                    browserStepStrategy.Run(webDriver, step);

                    Screenshot screenshot = ((ITakesScreenshot) webDriver).GetScreenshot();
                    Uri uri = _fileToUrlConverter.Convert(screenshot.AsByteArray);

                    TimeSpan duration = DateTime.Now - start;
                    StepPassed(
                        new StepRunnerEventArgs(linkedCriterion.Scenario.Id, linkedCriterion.Criterion.Id, step.Id,
                            DateTime.Now,
                            duration.TotalMilliseconds, TestStatus.Passing, uri.ToString()));
                }
                catch (Exception ex)
                {
                    TimeSpan duration = DateTime.Now - start;

                    Uri uri = null;
                    try
                    {
                        Screenshot screenshot = ((ITakesScreenshot)webDriver).GetScreenshot();
                        uri = _fileToUrlConverter.Convert(screenshot.AsByteArray);
                    }
                    catch (Exception seleniumException)
                    {
                        Console.WriteLine(
                            "Can't get failure screenshot because there was a Selenium error. {0}\r\nStacktrace:{1}",
                            seleniumException.Message, seleniumException.StackTrace);
                    }

                    var screenShotUrl = uri == null ? "" : uri.ToString();

                    StepFailed(
                        new StepErrorArgs(linkedCriterion.Scenario.Id, linkedCriterion.Criterion.Id, step.Id,
                            DateTime.Now, duration.TotalMilliseconds,
                            ex, screenShotUrl));
                    passing = false;
                }
            }

            return passing;
        }
Ejemplo n.º 5
0
 void PrepareStepsWithTokenReplacements(LinkedCriterion linkedCriterion, ScenarioContext context)
 {
     foreach (Step step in linkedCriterion.Criterion.GetSteps())
     {
         step.ReplaceTokens("%unique_string%", context.RandomString);
         step.ReplaceTokens("%unique_number%", context.RandomNumber);
         step.ReplaceTokens("%project_id%", linkedCriterion.Scenario.Story.Project.Id.ToString());
         step.ReplaceTokens("%story_id%", linkedCriterion.Scenario.Story.Id.ToString());
         step.ReplaceTokens("%scenario_id%", linkedCriterion.Scenario.Id.ToString());
         step.ReplaceTokens("%criterion_id%", linkedCriterion.Criterion.Id.ToString());
         step.ReplaceTokens("%step_id%", step.Id.ToString());
     }
 }