Ejemplo n.º 1
0
        public void can_report_meters_with_items()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter__items item=item1:value1 mtype=meter unit=none unit_rate=ms count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter__items item=item2:value2 mtype=meter unit=none unit_rate=ms count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter mtype=meter unit=none unit_rate=ms count.meter=2i rate1m=0 rate5m=0 rate15m=0" + Environment.NewLine);
        }
Ejemplo n.º 2
0
        public async Task can_pack_metrics()
        {
            // Arrange
            var token          = CancellationToken.None;
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);
            var filter         = new DefaultMetricsFilter().WithEnvironmentInfo(false);

            // Act
            await _fixture.ReportGenerator.GenerateAsync(reporter, _fixture.Metrics(), filter, token);

            var payload = payloadBuilder.PayloadFormatted();

            // Assert
            payload.Should().
            Be(
                "application__test_counter tag1=value mtype=counter unit=req value=1i" + Environment.NewLine +
                "application__test_gauge mtype=gauge unit=none value=8" + Environment.NewLine +
                "application__test_histogram mtype=histogram unit=req samples=1i last=5 count.hist=1i sum=5 min=5 max=5 mean=5 median=5 stddev=0 p999=5 p99=5 p98=5 p95=5 p75=5" +
                Environment.NewLine +
                "application__test_meter tag2=value mtype=meter unit=none unit_rate=min count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=3000" +
                Environment.NewLine +
                "application__test_timer mtype=timer unit=req unit_dur=ms unit_rate=min count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=3000 samples=1i last=10 count.hist=1i sum=10 min=10 max=10 mean=10 median=10 stddev=0 p999=10 p99=10 p98=10 p95=10 p75=10" +
                Environment.NewLine);
        }
Ejemplo n.º 3
0
        public void can_report_meters_when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter host=server1 env=staging mtype=meter unit=none unit_rate=ms count.meter=1i rate1m=0 rate5m=0 rate15m=0" +
                Environment.NewLine);
        }
Ejemplo n.º 4
0
        async Task TestMessages(CancellationToken cancellationToken)
        {
            string   endpoint       = Guid.NewGuid().ToString();
            TimeSpan timePerMessage = TimeSpan.FromMilliseconds(100);

            TestReporter reporter = this.testReporter.MakeSubcategory("Messages Sent and Recieved");

            using (reporter.MeasureDuration())
            {
                async Task CountSingleSends(int n)
                {
                    int prevSent = await this.GetNumberOfMessagesSent(cancellationToken, endpoint);

                    int prevRecieved = await this.GetNumberOfMessagesRecieved(cancellationToken, endpoint);

                    await this.SendMessages(n, cancellationToken, endpoint);

                    await Task.Delay(timePerMessage *n + TimeSpan.FromMilliseconds(1000));  // Give edgeHub time to send message upstream

                    int newSent = await this.GetNumberOfMessagesSent(cancellationToken, endpoint);

                    int newRecieved = await this.GetNumberOfMessagesRecieved(cancellationToken, endpoint);

                    reporter.Assert($"Reports {n} messages recieved", n, newRecieved - prevRecieved);
                    reporter.Assert($"Reports {n} messages sent", n, newSent - prevSent);

                    await Task.Delay(TimeSpan.FromMilliseconds(100));
                }

                await Task.Delay(TimeSpan.FromMilliseconds(2000));
                await CountSingleSends(1);
                await CountSingleSends(10);
                await CountSingleSends(100);

                async Task CountMultipleSends(int n, int m)
                {
                    int prevSent = await this.GetNumberOfMessagesSent(cancellationToken, endpoint);

                    int prevRecieved = await this.GetNumberOfMessagesRecieved(cancellationToken, endpoint);

                    await this.SendMessageBatches(n, m, cancellationToken, endpoint);

                    await Task.Delay(timePerMessage *n *m + TimeSpan.FromMilliseconds(1000));   // Give edgeHub time to send message upstream

                    int newSent = await this.GetNumberOfMessagesSent(cancellationToken, endpoint);

                    int newRecieved = await this.GetNumberOfMessagesRecieved(cancellationToken, endpoint);

                    reporter.Assert($"Reports {n * m} recieved for {n} batches of {m}", n * m, newRecieved - prevRecieved);
                    reporter.Assert($"Reports {n * m} sent for {n} batches of {m}", n * m, newSent - prevSent);

                    await Task.Delay(TimeSpan.FromMilliseconds(100));
                }

                await CountMultipleSends(1, 1);
                await CountMultipleSends(10, 1);
                await CountMultipleSends(1, 10);
                await CountMultipleSends(10, 10);
            }
        }
        public async Task TestEnvironmentVariablesAreRead()
        {
            var reporter  = new TestReporter();
            var overrides = new Overrides
            {
                Replacements = new List <ReplacementDefinition>
                {
                    new ReplacementDefinition {
                        Token = "herpa", EnvironmentVariable = "HERPA"
                    },
                    new ReplacementDefinition {
                        Token = "thomas", EnvironmentVariable = "THOMAS"
                    }
                }
            };

            Environment.SetEnvironmentVariable("HERPA", "derpa");
            Environment.SetEnvironmentVariable("THOMAS", "fromtidmouth");

            var sut = new ReplacementTokensFromEnvironmentVariablesTransformer(reporter);
            await sut.TransformAsync(overrides);

            var expectedReplacements = new List <ReplacementDefinition>
            {
                new ReplacementDefinition {
                    Token = "herpa", EnvironmentVariable = "HERPA", Value = "derpa"
                },
                new ReplacementDefinition {
                    Token = "thomas", EnvironmentVariable = "THOMAS", Value = "fromtidmouth"
                }
            };

            overrides.Replacements.ShouldDeepEqual(expectedReplacements);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Select and check a radio button by Label/name
        /// </summary>
        /// <param name="Label"></param>
        public void selectByLabel(string label)
        {
            //Set the selected Label
            this.selectedLabel = label;

            //Find the index of the radio button that has the user-defined Label
            try
            {
                this.currentIndex = this.stringLabels.IndexOf(label);
            }
            catch (ArgumentOutOfRangeException aoore)
            {
                TestReporter.log("An error occurred trying to access a member of the list of Labels.\nSTACK TRACE:\n" + aoore.StackTrace);
            }

            //Grab the radio button and click it
            try
            {
                radioButtons[this.currentIndex].Click();
            }
            catch (ElementNotVisibleException)
            {
                TestReporter.interfaceLog("Select Label <b> [ " + currentIndex + " ] </b> from the radio group [ <b>@FindBy: " + getElementLocatorInfo(element) + " </b> ]", true);
            }
            catch (StaleElementReferenceException)
            {
                TestReporter.interfaceLog("Select Label <b> [ " + currentIndex + " ] </b> from the radio group [ <b>@FindBy: " + getElementLocatorInfo(element) + " </b> ]", true);
            }
        }
Ejemplo n.º 7
0
        //*******************************
        //*** Login Page Interactions ***
        //*******************************

        /// <summary>
        ///     Logs into BlueSource by entering a username and password,
        ///     clicking the login button and verifying that the expected next page is loaded.
        /// </summary>
        public void login()
        {
            enterUsername();
            enterPassword();
            clickLogin();
            TestReporter.assertTrue(verifySucessfulLogin(), "Verify successful login.");
        }
Ejemplo n.º 8
0
        public void ShouldRunASimulation()
        {
            IPlateau p   = new MarsPlateau(new Coordinates(5, 5));
            IRover   one = new MarsRover.MarsRover(1, new Coordinates(1, 2), Direction.N,
                                                   new List <Command>
            {
                Command.L, Command.M, Command.L, Command.M, Command.L, Command.M, Command.L, Command.M, Command.M
            });
            IRover two = new MarsRover.MarsRover(2, new Coordinates(3, 3), Direction.E,
                                                 new List <Command>
            {
                Command.M, Command.M, Command.R, Command.M, Command.M, Command.R, Command.M, Command.R, Command.R,
                Command.M
            });

            var testReporter = new TestReporter();

            new Houston(p, new List <IRover> {
                one, two
            }).Control(testReporter);

            Assert.IsEmpty(testReporter.Errors);
            var expected = new Dictionary <IRover, Status>()
            {
                { one, Status.Ok },
                { two, Status.Ok }
            };

            Assert.AreEqual(expected, testReporter.Dictionary);
            Assert.AreEqual(Direction.N, one.Direction);
            Assert.AreEqual(new Coordinates(1, 3), one.Position);
            Assert.AreEqual(Direction.E, two.Direction);
            Assert.AreEqual(new Coordinates(5, 1), two.Position);
        }
Ejemplo n.º 9
0
        public void can_report_timers()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var timer       = new DefaultTimerMetric(_defaultReservoir, clock);

            timer.Record(1000, TimeUnit.Milliseconds, "client1");
            var timerValueSource = new TimerValueSource(
                "test timer",
                ConstantValue.Provider(timer.Value),
                Unit.None,
                TimeUnit.Minutes,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", timerValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_timer mtype=timer unit=none unit_dur=ms unit_rate=min count.meter=1i rate1m=0 rate5m=0 rate15m=0 samples=1i last=1000 count.hist=1i sum=1000 min=1000 max=1000 mean=1000 median=1000 stddev=0 p999=1000 p99=1000 p98=1000 p95=1000 p75=1000 user.last=\"client1\" user.min=\"client1\" user.max=\"client1\"" +
                Environment.NewLine);
        }
        [InlineData(new[] { "something something %%unreplacedTOKEN%% something else" }, new[] { "%%unreplacedTOKEN%%" })] //one unreplaced token with other ok content
        public async Task Test(IEnumerable <string> jtokenValues, IEnumerable <string> requiredTokens)
        {
            var messageCollector = new TestReporter();
            var stage            = new UnresolvedTokenVerifierStage(messageCollector);
            var json             = new JObject();

            foreach (var value in jtokenValues)
            {
                json.Add(Guid.NewGuid().ToString(), new JValue(value));
            }
            var t = new Auth0ResourceTemplate
            {
                Type     = ResourceType.Clients,
                Template = json
            };
            await stage.Process(t);

            var requiredTokenList = requiredTokens.ToList();

            if (!requiredTokenList.Any())
            {
                messageCollector.Messages.ShouldBeEmpty();
            }
            else
            {
                foreach (var token in requiredTokenList)
                {
                    messageCollector.ErrorMessages.ShouldHaveMessageThatContains(token);
                }
            }
        }
Ejemplo n.º 11
0
        public ExecutionResult Execute(WebTestHelper helper)
        {
            // Get driver initialized by TestProject Agent
            // No need to specify browser type, it can be done later via UI
            var          driver = helper.Driver;
            TestReporter report = helper.Reporter;

            // Navigate to TestProject Demo website
            driver.Navigate().GoToUrl("https://example.testproject.io/web/");

            // Initialize the properties of the LoginPage with the driver
            var loginPage = PageFactory.InitElements <LoginPage>(driver);

            report.Step("Navigated to TestProject Demo", loginPage.Displayed);

            // Login using provided credentials
            loginPage.Login(name, password);

            // Initialize the properties of the profilePage with the driver
            var profilePage = PageFactory.InitElements <ProfilePage>(driver);

            report.Step($"Logged in with {name}:{password}", profilePage.Displayed);

            // Complete profile forms and save it
            profilePage.UpdateProfile(country, address, email, phone);
            report.Step("Profile information saved", profilePage.Saved, TakeScreenshotConditionType.Never);

            report.Result = "Test completed successfully";
            return(ExecutionResult.Passed);
        }
Ejemplo n.º 12
0
        public void can_report_counter_with_items_and_tags()
        {
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                new MetricTags(new[] { "key1", "key2" }, new[] { "value1", "value2" }));
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", counterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter__items key1=value1 key2=value2 item=item1:value1 mtype=counter total=1i percent=50" +
                Environment.NewLine +
                "test__test_counter__items key1=value1 key2=value2 item=item2:value2 mtype=counter total=1i percent=50" +
                Environment.NewLine +
                "test__test_counter key1=value1 key2=value2 mtype=counter value=2i" + Environment.NewLine);
        }
Ejemplo n.º 13
0
        public void can_report_counter_with_items_tags_when_multidimensional()
        {
            var counterTags = new MetricTags(new[] { "key1", "key2" }, new[] { "value1", "value2" });
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(counter.Value),
                Unit.None,
                MetricTags.Concat(_tags, counterTags));
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", counterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter__items host=server1 env=staging key1=value1 key2=value2 item=item1:value1 mtype=counter total=1i percent=50" +
                Environment.NewLine +
                "test__test_counter__items host=server1 env=staging key1=value1 key2=value2 item=item2:value2 mtype=counter total=1i percent=50" +
                Environment.NewLine +
                "test__test_counter host=server1 env=staging key1=value1 key2=value2 mtype=counter value=2i" + Environment.NewLine);
        }
Ejemplo n.º 14
0
        public void can_report_counter_with_items_using_custom_key()
        {
            var dataKeys = new MetricValueDataKeys(
                counter: new Dictionary <CounterValueDataKeys, string> {
                { CounterValueDataKeys.MetricSetItemSuffix, " setitem" }
            });
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder, dataKeys);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", counterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter_setitem item=item1:value1 mtype=counter total=1i percent=50" + Environment.NewLine +
                "test__test_counter_setitem item=item2:value2 mtype=counter total=1i percent=50" + Environment.NewLine +
                "test__test_counter mtype=counter value=2i" + Environment.NewLine);
        }
Ejemplo n.º 15
0
        public void can_report_counter_with_items_and_custom_data_keys()
        {
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                new MetricTags(new[] { "key1", "key2" }, new[] { "value1", "value2" }));
            var payloadBuilder = new TestPayloadBuilder();
            var customDataKeys = new MetricValueDataKeys(
                counter: new Dictionary <CounterValueDataKeys, string>
            {
                { CounterValueDataKeys.SetItemPercent, "%" },
                { CounterValueDataKeys.Total, "count" }
            });
            var reporter = new TestReporter(payloadBuilder, customDataKeys);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", counterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter__items key1=value1 key2=value2 item=item1:value1 mtype=counter count=1i %=50" +
                Environment.NewLine +
                "test__test_counter__items key1=value1 key2=value2 item=item2:value2 mtype=counter count=1i %=50" +
                Environment.NewLine +
                "test__test_counter key1=value1 key2=value2 mtype=counter value=2i" + Environment.NewLine);
        }
Ejemplo n.º 16
0
        public async Task can_pack_metrics_with_custom_histogram_keys()
        {
            // Arrange
            var dataKeys = new MetricValueDataKeys(
                histogram: new Dictionary <HistogramValueDataKeys, string> {
                { HistogramValueDataKeys.P75, "75th_percentile" }
            });
            var token          = CancellationToken.None;
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(
                payloadBuilder,
                dataKeys);
            var filter = new DefaultMetricsFilter().WithEnvironmentInfo(false);

            // Act
            await _reportGenerator.GenerateAsync(reporter, _metrics, filter, token);

            var payload = payloadBuilder.PayloadFormatted();

            // Assert
            payload.Should().
            Be(
                "application__test_counter tag1=value mtype=counter value=1i" + Environment.NewLine +
                "application__test_gauge mtype=gauge value=8" + Environment.NewLine +
                "application__test_histogram mtype=histogram samples=1i last=5 count.hist=1i sum=5 min=5 max=5 mean=5 median=5 stddev=0 p999=5 p99=5 p98=5 p95=5 75th_percentile=5" +
                Environment.NewLine +
                "application__test_meter tag2=value mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=6000" +
                Environment.NewLine +
                "application__test_timer mtype=timer count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=6000 samples=1i last=10 count.hist=1i sum=10 min=10 max=10 mean=10 median=10 stddev=0 p999=10 p99=10 p98=10 p95=10 75th_percentile=10" +
                Environment.NewLine);
        }
Ejemplo n.º 17
0
        /// <summary>
        ///     Get the SOAP response and save as an XmlDocument and string
        /// </summary>
        private void GetResponse()
        {
            try
            {
                using (WebResponse response = httpRequest.GetResponse())
                {
                    //Get the response from the service
                    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                    {
                        //Set the response as a string
                        setResponseXmlAsString(rd.ReadToEnd());
                        //Set the response as an XmlDocument
                        setResponseXml(getResponseXmlAsString());
                        TestReporter.logSoapXml("SOAP RESPONSE XML: " + strResponseXml);
                    }
                    //Create an HTTP response object
                    httpResponse = (HttpWebResponse)response;

                    //Set the response status code. A value of "OK" represents a successful request.
                    setResponseStatusCode(httpResponse.StatusDescription);
                }
            }
            catch (WebException we)
            {
                TestReporter.log("An error occurred during the SOAP response: " + we.StackTrace);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        ///     Wraps Selenium's method.  Returns the selected option.
        /// </summary>
        /// <param name="element">Element from which to get the first selected option</param>
        /// <returns>IWebElement first selected option</returns>
        public IWebElement getFirstSelectedOption(Tuple <locatorType, string> element)
        {
            try
            {
                //Grab the SelectElement
                innerSelect = new SelectElement(findElement(element));
                //Grab the selected item within the select element
                we = innerSelect.SelectedOption;
            }
            catch (UnexpectedTagNameException utne)
            {
                TestReporter.log("The element defined by locatoryType ["
                                 + element.Item1.ToString() + "] and identifier ["
                                 + element.Item2 + "] is not a select-type element.\n\n"
                                 + utne.StackTrace);
            }
            catch (NoSuchElementException nsee)
            {
                TestReporter.log("The element defined by locatoryType ["
                                 + element.Item1.ToString() + "] and identifier ["
                                 + element.Item2 + "] does not exist.\n\n"
                                 + nsee.StackTrace);
            }

            return(we);
        }
Ejemplo n.º 19
0
        public void can_report_meters_with_items_tags_when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter__items host=server1 env=staging item=item1:value1 mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter__items host=server1 env=staging item=item2:value2 mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter host=server1 env=staging mtype=meter count.meter=2i rate1m=0 rate5m=0 rate15m=0" +
                Environment.NewLine);
        }
Ejemplo n.º 20
0
        public void ShouldReportFellOffOnLanding()
        {
            IPlateau p   = new MarsPlateau(new Coordinates(1, 1));
            IRover   one = new MarsRover.MarsRover(1, new Coordinates(1, 2), Direction.N,
                                                   new List <Command>
            {
                Command.L, Command.L, Command.M, Command.L, Command.M, Command.L, Command.M, Command.L, Command.M,
                Command.M
            });

            var testReporter = new TestReporter();

            new Houston(p, new List <IRover> {
                one
            }).Control(testReporter);

            Assert.AreEqual(new List <string>
            {
                $"Rover {one.Id} landed at [{one.Position.X}, {one.Position.Y}] outside the plateau"
            },
                            testReporter.Errors);

            Assert.AreEqual(new Dictionary <IRover, Status>
            {
                { one, Status.FellOff }
            }, testReporter.Dictionary);
            Assert.AreEqual(Direction.N, one.Direction);
            Assert.AreEqual(new Coordinates(1, 2), one.Position);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///     Wraps Selenium's method. Returns all options, as Strings, for a select element
        /// </summary>
        /// <param name="element">Element for which to get all options</param>
        /// <returns>string list of options</returns>
        public IList <string> getOptionsAsStrings(Tuple <locatorType, string> element)
        {
            //Define a list to hold the options
            List <string> strOptions = new List <string>();

            try
            {
                //Grab the SelectElement
                innerSelect = new SelectElement(findElement(element));
                //Grab the list of options as web elements
                IList <IWebElement> eleOptions = innerSelect.Options;

                //Add each option, as a string, to the list of options
                foreach (IWebElement ele in eleOptions)
                {
                    strOptions.Add(ele.Text);
                }
            }
            catch (UnexpectedTagNameException utne)
            {
                TestReporter.log("The element defined by locatoryType ["
                                 + element.Item1.ToString() + "] and identifier ["
                                 + element.Item2 + "] is not a select-type element.\n\n"
                                 + utne.StackTrace);
            }

            return(strOptions);
        }
Ejemplo n.º 22
0
        /// <summary>
        ///     Locates the textbox and sets the text using Selenium SendKeys then validates that the correct value is set.
        ///     The test will fail if the expected text (case sensitive) is not found.
        /// </summary>
        /// <param name="element"></param>
        /// <param name="value"></param>
        public void setValidate(Tuple <locatorType, string> element, string value)
        {
            TestReporter.log("<i>Setting the text of [ <b>@FindBy: "
                             + getElementLocatorInfo(element)
                             + "</b> ] to [ " + value + "].");
            //Grab the element
            we = findElement(element);

            //Set the text of the element
            try
            {
                we.SendKeys(value);
            }
            catch (InvalidElementStateException iese)
            {
                TestReporter.log(iese.StackTrace);
            }
            catch (ElementNotVisibleException enve)
            {
                TestReporter.log(enve.StackTrace);
            }
            catch (StaleElementReferenceException sere)
            {
                TestReporter.log(sere.StackTrace);
            }
            //Recapture the element, given the text change
            we = findElement(element);
            //Verify that the element text is that which was intended to be entered
            TestReporter.assertTrue(we.Text.Equals(value), "<i>Validating the text of [ <b>@FindBy: "
                                    + getElementLocatorInfo(element)
                                    + "</b> ] to [ " + value + "].");
        }
Ejemplo n.º 23
0
        /// <summary>
        ///     Use IWebDriver Wait to determine if object is enabled on the screen or not
        /// </summary>
        /// <param name="element">The element for which to search</param>
        /// <param name="driver">The IWebDriver</param>
        /// <returns>Boolean true if the element is enabled, false otherwise</returns>
        public Boolean webElementEnabled(Tuple <locatorType, string> element, IWebDriver driver)
        {
            //Define a new WebDriverWait object, defined in part by the driver, which will be used to wait for a condition to be met
            WebDriverWait wait       = new WebDriverWait(driver, TimeSpan.FromSeconds(0));
            string        stackTrace = null;
            Boolean       enabled    = false;

            try
            {
                //Determine if an element is clickable
                return(wait.Until(ExpectedConditions.ElementToBeClickable(findElement(element))) != null);
            }
            catch (TimeoutException e)
            {
                stackTrace = e.StackTrace;
            }
            catch (NoSuchElementException nsee)
            {
                stackTrace = nsee.StackTrace;
            }
            catch (StaleElementReferenceException sere)
            {
                stackTrace = sere.StackTrace;
            }
            TestReporter.log(stackTrace);

            return(enabled);
        }
Ejemplo n.º 24
0
 /// <summary>
 ///     Use IWebDriver Wait to determine if object is visible on the screen or not
 /// </summary>
 /// <param name="element">The element for which to search</param>
 /// <param name="driver">The IWebDriver</param>
 /// <returns>Boolean true if the element is visible on the screen, false otherwise</returns>
 public Boolean webElementVisible(Tuple <locatorType, string> element, IWebDriver driver)
 {
     //Find the element
     we = findElement(element);
     try
     {
         //Grab the element's location
         Point location = getElementLocation(element);
         //Grab the element's size
         Size size = we.Size;
         //If the x and y locations are greater than zero or the height and width are greater than zero, then the object is deemed visible on the screen
         if ((location.X > 0 & location.Y > 0)
             | (size.Height > 0 & size.Width > 0))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (WebDriverException wde)
     {
         TestReporter.log(wde.StackTrace);
         return(false);
     }
 }
Ejemplo n.º 25
0
        public void can_report_counter_with_items_with_option_not_to_report_percentage()
        {
            var metricsMock = new Mock <IMetrics>();
            var counter     = new DefaultCounterMetric();

            counter.Increment(new MetricSetItem("item1", "value1"), 1);
            counter.Increment(new MetricSetItem("item2", "value2"), 1);
            var counterValueSource = new CounterValueSource(
                "test counter",
                ConstantValue.Provider(counter.Value),
                Unit.None,
                MetricTags.Empty,
                reportItemPercentages: false);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", counterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_counter__items item=item1:value1 mtype=counter total=1i" + Environment.NewLine +
                "test__test_counter__items item=item2:value2 mtype=counter total=1i" + Environment.NewLine +
                "test__test_counter mtype=counter value=2i" + Environment.NewLine);
        }
Ejemplo n.º 26
0
        /// <summary>
        ///     Wraps Selenium method. Determine if an element is selected.
        /// </summary>
        /// <param name="element"></param>
        /// <returns>Boolean true if selected, false otherwise</returns>
        public Boolean isSelected(Tuple <locatorType, string> element)
        {
            Boolean isSelected = false;

            try
            {
                //Grab the SelectElement
                innerSelect = new SelectElement(findElement(element));
                isSelected  = ((IWebElement)innerSelect).Selected;
            }
            catch (UnexpectedTagNameException utne)
            {
                TestReporter.log("The element defined by locatoryType ["
                                 + element.Item1.ToString() + "] and identifier ["
                                 + element.Item2 + "] is not a select-type element.\n\n"
                                 + utne.StackTrace);
            }
            catch (StaleElementReferenceException sere)
            {
                TestReporter.log("The element defined by locatoryType ["
                                 + element.Item1.ToString() + "] and identifier ["
                                 + element.Item2 + "] refers to a stale element.\n\n"
                                 + sere.StackTrace);
            }
            return(isSelected);
        }
Ejemplo n.º 27
0
        public void can_report_meters_with_items_using_custom_item_key()
        {
            var dataKeys = new MetricValueDataKeys(
                meter: new Dictionary <MeterValueDataKeys, string> {
                { MeterValueDataKeys.MetricSetItemSuffix, " setitem" }
            });
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var meter       = new DefaultMeterMetric(clock);

            meter.Mark(new MetricSetItem("item1", "value1"), 1);
            meter.Mark(new MetricSetItem("item2", "value2"), 1);
            var meterValueSource = new MeterValueSource(
                "test meter",
                ConstantValue.Provider(meter.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                MetricTags.Empty);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder, dataKeys);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", meterValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_meter_setitem item=item1:value1 mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter_setitem item=item2:value2 mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 percent=50" +
                Environment.NewLine +
                "test__test_meter mtype=meter count.meter=2i rate1m=0 rate5m=0 rate15m=0" + Environment.NewLine);
        }
Ejemplo n.º 28
0
        public void can_report_timers__when_multidimensional()
        {
            var metricsMock = new Mock <IMetrics>();
            var clock       = new TestClock();
            var timer       = new DefaultTimerMetric(_defaultReservoir, clock);

            timer.Record(1000, TimeUnit.Milliseconds, "client1");
            var timerValueSource = new TimerValueSource(
                "test timer" + MultidimensionalMetricNameSuffix,
                ConstantValue.Provider(timer.Value),
                Unit.None,
                TimeUnit.Milliseconds,
                TimeUnit.Milliseconds,
                _tags);
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);

            reporter.StartReportRun(metricsMock.Object);
            reporter.ReportMetric("test", timerValueSource);

            payloadBuilder.PayloadFormatted().
            Should().
            Be(
                "test__test_timer host=server1 env=staging mtype=timer count.meter=1i rate1m=0 rate5m=0 rate15m=0 samples=1i last=1000 count.hist=1i sum=1000 min=1000 max=1000 mean=1000 median=1000 stddev=0 p999=1000 p99=1000 p98=1000 p95=1000 p75=1000 user.last=\"client1\" user.min=\"client1\" user.max=\"client1\"" +
                Environment.NewLine);
        }
Ejemplo n.º 29
0
        /**
         * Main entry point.
         * Runs unit tests for the unit testing framework.
         *
         * @param args, array of string arguments.
         */
        static void Main(string[] args)
        {
            try
            {
                // Create the test suite
                TestSuite suite = new TestSuite();

                // Add tests to the test suite
                suite.AddAll((TestCase) new Dummy_Test());
                suite.AddAll((TestCase) new Assert_Test());
                suite.AddAll((TestCase) new TestCase_Test());
                suite.AddAll((TestCase) new TestResult_Test());
                suite.AddAll((TestCase) new TestSuite_Test());
                suite.AddAll((TestCase) new TestReporter_Test());

                // Run the tests
                TestResult result = suite.Run(null);

                // Report test results
                TestReporter reporter = new TestReporter();
                reporter.LogResults(result);
            }
            catch (Exception e)
            {
                // Log uncaught exceptions
                System.Console.WriteLine(e.ToString());
            }

            // Set a break point here for testing to examine console output
            //int pause = 0;
        }
Ejemplo n.º 30
0
        protected AbstractTestSuite(TestReporter reporter)
        {
            if (reporter == null) {
                throw new ArgumentException("The reporter of a test suite mustn't be null.");
            }

            Reporter = reporter;
        }
Ejemplo n.º 31
0
 /// <summary>
 ///     Locates the textbox and sets the text using Selenium SendKeys.
 ///     The desired value should be a 64 bit encoded string.
 ///     The encoded string should be generated by Orasi.Selenium.Utilities.Base64
 /// </summary>
 /// <param name="element"></param>
 /// <param name="value"></param>
 public void setSecure(Tuple <locatorType, string> element, string value)
 {
     TestReporter.log("<i>Secure setting the text of [ <b>@FindBy: "
                      + getElementLocatorInfo(element));
     //Grab the element
     we = findElement(element);
     //Decode the value and send the keys to the element
     we.SendKeys(Base64.Base64Decode(value));
 }
Ejemplo n.º 32
0
 public TestSuiteMock(TestReporter reporter)
     : base(reporter)
 {
 }