Exemple #1
0
        public Reporter(TestingFramework framework)
        {
            var fileName = ReporterHelper.GetSettingsFileName(framework);
            var settings = ReporterHelper.GetSettingsFromFile(fileName);

            InitializeReporter(settings);
        }
        protected override bool SetCore(IErrorReporter reporter, IToken valueToken)
        {
            var text = valueToken.Text;

            if (valueToken.Type == SettingTokenType.Label)
            {
                switch (text)
                {
                case "true":
                    Value = true;
                    return(true);

                case "false":
                    Value = false;
                    return(false);

                default:
                    ReporterHelper.AddError(reporter, valueToken, "'{0}' is not a valid value.", text);
                    return(false);
                }
            }
            else
            {
                ReporterHelper.AddError(reporter, valueToken, "\"{0}\" is not a valid value.", text);
                return(false);
            }
        }
        void IConfigCommandVisitor.Visit(ConfigCommandArg argValue)
        {
            var token = argValue.Value;

            if (!int.TryParse(token.Text, out var argIndex) || argIndex >= _production.Segments.Length)
            {
                ReporterHelper.AddError(_reporter, token, "Invalid argument reference");
            }
        }
Exemple #4
0
 public void SetupBeforeEverySingleTest()
 {
     Logger.Debug("*** TEST STARTED ***");
     ReporterHelper.AddTestCaseMetadataToHtmlReports(TestContext.CurrentContext);
     Driver = new WebDriverFactory().Create(BrowserType.Chrome);
     Driver.Manage().Window.Maximize();
     ScreenshotTaker = new ScreenshotTaker(Driver);
     InsightsPage    = new InsightsPage(Driver);
     InsightsPage.GoTo();
 }
Exemple #5
0
        protected override bool SetCore(IErrorReporter reporter, IToken valueToken)
        {
            if (valueToken.Type == SettingTokenType.Label)
            {
                Value = valueToken.Text;
                return(true);
            }

            ReporterHelper.AddError(reporter, valueToken, "'{0}' is not a valid value.", valueToken.Text);
            return(false);
        }
Exemple #6
0
        internal bool IsContactPageTitleCorrect()
        {
            var testStepResult = Driver.Title.Contains(ContactUsPageTitle);

            Console.WriteLine(Driver.Title);
            ReporterHelper.LogTestStep(
                testStepResult,
                "Contact Page title is correct",
                $"Expected page title was {ContactUsPageTitle} but actual page title is: {Driver.Title}"
                );
            return(testStepResult);
        }
Exemple #7
0
        internal bool IsPageTitleCorrect()
        {
            var testStepResult = Driver.Title.Equals(InsightsPageTitle);

            Console.WriteLine(Driver.Title);
            ReporterHelper.LogTestStep(
                testStepResult,
                "Insight Page title is correct",
                $"Expected page title was {InsightsPageTitle} but actual page title is: {Driver.Title}"
                );
            return(testStepResult);
        }
Exemple #8
0
 private void TakeScreenshotForTestFailure()
 {
     if (ScreenshotTaker != null)
     {
         ScreenshotTaker.CreateScreenshotIfTestFailed();
         ReporterHelper.ReportTestOutcome(ScreenshotTaker.ScreenshotFilePath);
     }
     else
     {
         ReporterHelper.ReportTestOutcome("");
     }
 }
        bool VerifyProductionReferences()
        {
            var success = true;

            var ntReferences  = new Dictionary <Segment, List <ConfigToken> >();
            var ntDefinitions = new Dictionary <Segment, List <ConfigToken> >();

            foreach (var entryPoint in _config.EntryPoints)
            {
                AddToList(ntReferences, entryPoint.Segment, entryPoint.NonTerminal);
            }

            foreach (var nonTerminal in _config.Productions)
            {
                AddToList(ntDefinitions, nonTerminal.Segment, nonTerminal.Target);

                foreach (var rule in nonTerminal.Rules)
                {
                    foreach (var segment in rule.Segments)
                    {
                        if (segment.Token.Type == ConfigTokenType.NonTerminal)
                        {
                            AddToList(ntReferences, segment.Segment, segment.Token);
                        }
                    }
                }
            }

            foreach (var pair in ntDefinitions)
            {
                ntReferences.Remove(pair.Key);

                var list = pair.Value;

                for (var i = 1; i < list.Count; i++)
                {
                    var token = list[i];
                    ReporterHelper.AddWarning(_reporter, token, "The non-terminal <{0}> has already been defined.", token.Text);
                }
            }

            foreach (var pair in ntReferences)
            {
                foreach (var token in pair.Value)
                {
                    ReporterHelper.AddError(_reporter, token, "The non-terminal <{0}> is not defined.", token.Text);
                    success = false;
                }
            }

            return(success);
        }
Exemple #10
0
        Graph BuildDFA(Dictionary <string, int> typeLookup)
        {
            var nfa = new Graph <NodeData, CharSet> .Builder();

            for (var i = 0; i < _config.States.Count; i++)
            {
                var state = _config.States[i];

                if (state.Rules.Count == 0)
                {
                    ReporterHelper.AddError(_reporter, state.Label, "The state '{0}' does not define any rules.", state.Label.Text);
                    continue;
                }

                var startState = nfa.NewState(true, new NodeData(i, null));

                for (var j = 0; j < state.Rules.Count; j++)
                {
                    var       rule = state.Rules[j];
                    ReElement element;

                    if (!typeLookup.TryGetValue(rule.Token.Text, out var endStateID))
                    {
                        endStateID = typeLookup.Count;
                        typeLookup.Add(rule.Token.Text, endStateID);
                    }

                    try
                    {
                        element = ReParser.Parse(rule.Regex.Text);
                    }
                    catch (ReParseException ex)
                    {
                        ReporterHelper.AddError(_reporter, rule.Regex, ex.Message);
                        continue;
                    }

                    if (element.MatchesEmptyString)
                    {
                        ReporterHelper.AddWarning(
                            _reporter,
                            rule.Regex,
                            "This regular expression claims to match the empty string, " +
                            "this is not supported and usually indicates a typeo in the regular expression");
                    }

                    element.GenerateNFA(nfa, startState, nfa.NewState(false, new NodeData(null, endStateID, j)));
                }
            }

            return(FATools.CreateDfa(nfa.Graph));
        }
Exemple #11
0
 void ReportUnexpectedToken(ConfigToken token)
 {
     if (token.Type == ConfigTokenType.Error)
     {
         ReporterHelper.AddError(_reporter, token, token.Text);
     }
     else if (token.Type == ConfigTokenType.EOF)
     {
         ReporterHelper.AddError(_reporter, token, "Unexpected end of file.");
     }
     else
     {
         ReporterHelper.AddError(_reporter, token, "Unexpected Token.");
     }
 }
        void PopulateTopLevelSegments()
        {
            if (_config.EntryPoints.Count > 0)
            {
                var segments = new Dictionary <Segment, bool>();

                foreach (var entryPoint in _config.EntryPoints)
                {
                    var segment = GetNonTerminal(entryPoint.NonTerminal.Text);
                    entryPoint.Segment = segment;

                    if (_ntTypes.TryGetValue(segment, out var cUsing))
                    {
                        entryPoint.Using = cUsing;
                    }

                    if (segments.ContainsKey(segment))
                    {
                        ReporterHelper.AddWarning(_reporter, entryPoint.NonTerminal, "The non-terminal <{0}> is already an entry point.", entryPoint.NonTerminal.Text);
                    }
                    else
                    {
                        segments.Add(segment, true);
                    }
                }

                _config.TopLevelSegments = SegmentSet.New(segments.Keys);
            }
            else if (_config.Productions.Count > 0)
            {
                _config.TopLevelSegments = SegmentSet.New(new Segment[]
                {
                    _config.Productions[0].Segment,
                });

                _config.EntryPoints.Add(new ConfigEntryPoint()
                {
                    Segment     = _config.Productions[0].Segment,
                    NonTerminal = _config.Productions[0].Target,
                    Using       = _config.Productions[0].Using,
                });
            }
            else
            {
                _config.TopLevelSegments = SegmentSet.EmptySet;
            }
        }
        void DecorateRule(ConfigProduction cProduction, ConfigRule cRule, int ruleNum)
        {
            var cSegments = cRule.Segments;
            ImmutableArray <Segment> segments;

            if (cSegments.Count == 0)
            {
                cRule.FromPos = cProduction.Target.FromPos;
                cRule.ToPos   = cProduction.Target.ToPos;
                segments      = ImmutableArray <Segment> .Empty;
            }
            else
            {
                var builder = ImmutableArray.CreateBuilder <Segment>(cSegments.Count);
                cRule.FromPos = cSegments[0].Token.FromPos;
                cRule.ToPos   = cSegments[cSegments.Count - 1].Token.ToPos;

                for (var i = 0; i < cSegments.Count; i++)
                {
                    var cSegment = cSegments[i];
                    var segment  = GetSegment(cSegment.Token, cSegment.Modifier);

                    cSegment.Segment = segment;
                    builder.Add(segment);
                }

                segments = builder.MoveToImmutable();
            }

            var production = new Production(cProduction.Segment, segments);

            cRule.Production = production;

            PopulateCommand(cProduction, cRule, ruleNum);

            if (!_config.RuleLookup.ContainsKey(production))
            {
                _config.RuleLookup.Add(production, cRule);
            }
            else
            {
                ReporterHelper.AddWarning(_reporter, cRule, "The production '{0}' has already been defined.", production);
            }
        }
        static void ReportReduceReduceConflict(Config config, List <Production> productions, IErrorReporter reporter)
        {
            var rules  = new ConfigRule[productions.Count];
            var starts = new int[productions.Count];

            for (var i = 0; i < rules.Length; i++)
            {
                var production = productions[i];

                if (production.Target.IsInitial)
                {
                    starts[i] = -1;
                }
                else
                {
                    var rule = config.RuleLookup[production];
                    rules[i]  = rule;
                    starts[i] = rule.FromPos.Index;
                }
            }

            Array.Sort(starts, rules);

            string format;
            string val;

            if (rules[0] == null)
            {
                format = "{0} causes a reduce-accept conflict.";
                val    = null;
            }
            else
            {
                format = "{0} causes a reduce-reduce conflict with {1}.";
                val    = rules[0].Production.ToString();
            }

            for (var i = 1; i < rules.Length; i++)
            {
                ReporterHelper.AddError(reporter, rules[i], format, rules[i].Production, val);
            }
        }
Exemple #15
0
        internal bool FilterByBusinessValues()
        {
            ScrolltotheElement();
            Driver.FindElement(FilterByBusinessLocator).Click();
            SelectElement selectElement = new SelectElement(Driver.FindElement(FilterByBusinessLocator));

            selectElement.SelectByText(ExpectedResultValue);
            ScrolltotheElement();

            //Verify the result page displaying as per selected value from the drop down
            string ActualResultValue = Driver.FindElement(OctopusEnergyLocator).Text;
            var    testStepResult    = ActualResultValue.Equals(ExpectedResultValue);

            ReporterHelper.LogTestStep(
                testStepResult,
                "Page result is correct as per  selected  value from the drop down",
                $"Expected page result was {ExpectedResultValue} but actual page result is: {ActualResultValue}"
                );
            return(testStepResult);
        }
Exemple #16
0
        internal bool SearchByText()
        {
            ScrolltotheElement();

            Driver.FindElement(SearchKeywordLocator).Click();
            Driver.FindElement(SearchKeywordLocator).Clear();
            Driver.FindElement(SearchKeywordLocator).SendKeys(ExpectedResultText);
            Driver.FindElement(SubmitButton).Submit();

            ScrolltotheElement();
            //Verify the result page displaying search result text

            string ActualResultText = Driver.FindElement(OctopusGroupLocator).Text;

            var testStepResult = ActualResultText.Equals(ExpectedResultText);

            ReporterHelper.LogTestStep(
                testStepResult,
                "Search Page result is correct",
                $"Expected page result was {ExpectedResultText} but actual page result is: {ActualResultText}"
                );
            return(testStepResult);
        }
Exemple #17
0
        public Reporter()
        {
            var settings = ReporterHelper.GetSettingsFromFile();

            InitializeReporter(settings);
        }
Exemple #18
0
        internal void GoTo()
        {
            Driver.Navigate().GoToUrl(InsightsPageUrl);

            ReporterHelper.LogPassingTestStep($"Opening Octopus.com InsightsPage");
        }
Exemple #19
0
 public void SetupBeforeAllTests()
 {
     ReporterHelper.StartReporter();
 }
        void PopulateUsings()
        {
            var usingLookup = new Dictionary <string, ConfigUsing>();

            foreach (var cUsing in _config.Usings)
            {
                var label = cUsing.Label.Text;

                if (!usingLookup.ContainsKey(label))
                {
                    usingLookup.Add(label, cUsing);
                }
                else
                {
                    ReporterHelper.AddError(_reporter, cUsing.Label, "Type reference already defined.");
                }
            }

            {
                var label = _config.Manager.TokenType;

                if (!string.IsNullOrEmpty(label) && usingLookup.TryGetValue(label, out var terminalType))
                {
                    _config.TerminalType = terminalType;
                }
            }

            var pending = new List <Segment>();

            foreach (var cProduction in _config.Productions)
            {
                var name    = cProduction.Target.Text;
                var segment = GetNonTerminal(name);
                cProduction.Segment = segment;

                if (cProduction.TypeRef == null)
                {
                    pending.Add(segment);
                }
                else
                {
                    if (!usingLookup.TryGetValue(cProduction.TypeRef.Text, out var cUsing))
                    {
                        ReporterHelper.AddError(_reporter, cProduction.TypeRef, "Unknown type reference.");
                    }
                    else if (!_ntTypes.TryGetValue(segment, out var cExistingUsing))
                    {
                        _ntTypes.Add(segment, cUsing);
                    }
                    else if (cUsing != cExistingUsing)
                    {
                        ReporterHelper.AddError(_reporter, cProduction.TypeRef, "This type conflicts with a previous definition of <{0}>.", name);
                    }
                }
            }

            ConfigUsing defaultUsing = null;

            if (_config.TerminalType == null)
            {
                defaultUsing = CreateDefaultUsing(usingLookup);
                _config.Usings.Add(defaultUsing);
                _config.TerminalType = defaultUsing;
            }

            foreach (var segment in pending)
            {
                if (_ntTypes.ContainsKey(segment))
                {
                    continue;
                }

                if (defaultUsing == null)
                {
                    defaultUsing = CreateDefaultUsing(usingLookup);
                    _config.Usings.Add(defaultUsing);
                }

                _ntTypes.Add(segment, defaultUsing);
            }
        }
        void DetectUnreachableNonTerminals()
        {
            var references = new Dictionary <Segment, List <Segment> >();

            foreach (var production in _config.Productions)
            {
                var list = new List <Segment>();

                if (!references.TryGetValue(production.Segment, out list))
                {
                    list = new List <Segment>();
                    references.Add(production.Segment, list);
                }

                foreach (var rule in production.Rules)
                {
                    foreach (var seg in rule.Segments)
                    {
                        var segment = seg.Segment;

                        if (!segment.IsTerminal)
                        {
                            list.Add(segment);
                        }
                    }
                }
            }

            var reachable = new Dictionary <Segment, bool>();
            var pending   = new Queue <Segment>();

            foreach (var entryPoint in _config.EntryPoints)
            {
                var segment = entryPoint.Segment;

                if (!reachable.ContainsKey(segment))
                {
                    pending.Enqueue(segment);
                    reachable.Add(segment, true);
                }
            }

            while (pending.Count > 0)
            {
                var segment = pending.Dequeue();

                if (references.TryGetValue(segment, out var reach))
                {
                    foreach (var next in reach)
                    {
                        if (!reachable.ContainsKey(next))
                        {
                            pending.Enqueue(next);
                            reachable.Add(next, true);
                        }
                    }
                }
            }

            foreach (var production in _config.Productions)
            {
                if (!reachable.ContainsKey(production.Segment))
                {
                    ReporterHelper.AddWarning(_reporter, production.Target, "The non-terminal <{0}> is not reachable.", production.Target.Text);
                }
            }
        }