Exemplo n.º 1
0
        /// <summary>
        /// The get wrap rest info.
        /// </summary>
        /// <param name="uri">
        /// The uri.
        /// </param>
        /// <returns>
        /// The <see cref="Task"/>.
        /// </returns>
        protected async Task <JObject> GetWrapRestInfo(string uri)
        {
            var     client = new HttpClient();
            JObject retVal;

            client.DefaultRequestHeaders.Add("Accept", "application/json");

            var fullUri  = $"{WtApiConfiguration.Url}/{uri}";
            var response = await client.GetStringAsync(fullUri);

            StfLogger.LogInfo($"GetWrapRestInfo: Called [{fullUri}]");
            StfLogger.LogInfo($"GetWrapRestInfo: Got response [{response}]");

            try
            {
                retVal = JObject.Parse(response);
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"GetWrapRestInfo: While parsing the repsonse something went wrong [{ex}]");
                retVal = default(JObject);
            }

            return(retVal);
        }
Exemplo n.º 2
0
        public void Tc024()
        {
            // Set up user context for actual test
            // Use default user
            WrapTrackShell.Login();

            var me = WrapTrackShell.Me();

            StfAssert.IsNotNull("WrapTrackShell", this.WrapTrackShell);
            StfAssert.IsInstanceOfType("me", me, typeof(IMeProfile));

            // Actual test

            // Create a new wrap
            var wrapCollection = me.GetCollection();

            StfAssert.IsNotNull("check if me.GetCollection null", wrapCollection);

            var newWrapWtId = wrapCollection.AddWrap();

            // Move to the new wrap
            var wrapToSendOnHoliday = this.WrapTrackShell.GetToWrap(newWrapWtId);
            var recipient           = this.GetAnotherUser();

            // Send warp away on holiday
            wrapToSendOnHoliday.SendAwayTemporarily(SendAwayReason.Holiday, recipient);

            // Validate the the wrap indeed is on holiday
            var wtApi    = this.Get <IWtApi>();
            var wrapInfo = wtApi.WrapInfoByTrackId(newWrapWtId);

            StfLogger.LogInfo("The recipient user name attempted is {0} and userid from wrapInfo API is {1}", recipient, wrapInfo.VisitingUserId);
            StfAssert.IsTrue("Wrap is on holiday", wrapInfo.OnHoliday);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns random wrap in collection.
        /// </summary>
        /// <param name="wtIdContraint">
        /// Constrain the randomness to NOT return this wrap
        /// </param>
        /// <returns>
        /// The <see cref="IWrap"/>.
        /// </returns>
        public IWrap GetRandomWrap(string wtIdContraint = null)
        {
            var wrapElements  = WebAdapter.FindElements(By.Id("lin_wrap"));
            var numberOfWraps = wrapElements.Count;
            var random        = new Random();
            var wrapToChoose  = random.Next(1, numberOfWraps + 1);
            var xpath         = $"(//a[@id='lin_wrap'])[{wrapToChoose}]";
            var element       = WebAdapter.FindElement(By.XPath(xpath));
            var linWrapText   = element.Text;

            if (!string.IsNullOrEmpty(wtIdContraint) &&
                numberOfWraps > 1 &&
                linWrapText.Equals(wtIdContraint, StringComparison.CurrentCultureIgnoreCase))
            {
                wrapToChoose = wrapToChoose == numberOfWraps ? 1 : wrapToChoose + 1;
                xpath        = $"(//a[@id='lin_wrap'])[{wrapToChoose}]";
                element      = WebAdapter.FindElement(By.XPath(xpath));
            }

            StfLogger.LogInfo($"We choose wrap number {wrapToChoose} (of {numberOfWraps}) - {linWrapText}");
            element.Click();

            var retVal = StfContainer.Get <IWrap>();

            return(retVal);
        }
Exemplo n.º 4
0
        public void Tc027()
        {
            const string ChapterText = "Some text to add from TC027";

            StfAssert.IsNotNull("wrapTrackShell", WrapTrackShell);
            WrapTrackShell.SignUp();

            var me = WrapTrackShell.Me();

            StfAssert.IsNotNull("me", me);

            var collection = me.GetCollection();

            StfAssert.IsNotNull("Got my collection", collection);

            var newWrap    = collection.AddWrap("Ali Dover", "Hygge", "blue");
            var wrap       = GetToWrap(newWrap);
            var addChapter = AddChapter(wrap, ChapterText);

            StfAssert.IsTrue("Added Chapter", addChapter);

            var doesNewsExist = DoesNewsExist(newWrap, ChapterText);

            StfAssert.IsTrue("Does news exist for the added Chapter", doesNewsExist);
            StfLogger.LogInfo("Hi Brian, here is the currently logged in user {0}", WrapTrackShell.CurrentLoggedInUser);
        }
Exemplo n.º 5
0
        /// <summary>
        /// The is news aboout wrap sent on holiday.
        /// </summary>
        /// <param name="wrapWtId">
        /// The new wrap wt id.
        /// </param>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="recipient">
        /// The recipient.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool IsNewsAboutWrapSentOnHoliday(string wrapWtId, string sender, string recipient)
        {
            // set the profile context so we can navigate to the news page afterwards
            // Not sure why, but if we dont have this call in here the buttonclickbyid below doesn't find the navigation item
            WrapTrackShell.Me();

            // navigate to the news page
            // Click tab page News
            WrapTrackShell.WebAdapter.ButtonClickById("nav_home");

            var newsElements = WrapTrackShell.WebAdapter.FindElements(By.Id("vikle_ferie"));

            if (newsElements.Count == 0)
            {
                StfLogger.LogInfo("Found no news elements at all - for wraps sent on holiday");
                return(false);
            }

            foreach (var newsElement in newsElements)
            {
                var newsHolidayText = newsElement.Text;

                if (newsHolidayText.Contains(recipient) &&
                    newsHolidayText.Contains(wrapWtId) &&
                    newsHolidayText.Contains(sender))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        public void DataDrivenOne()
        {
            var testdata = InitTestData <Bob>();

            StfLogger.LogInfo($"First = {testdata.First}");
            StfLogger.LogInfo($"Second = {testdata.Second}");
            StfLogger.LogInfo($"Third = {testdata.Third}");
            StfLogger.LogInfo($"Third = {testdata.DeleteWrapOption}");
        }
        /// <summary>
        /// The validate pass on.
        /// </summary>
        /// <param name="wrapToGo">
        /// The wrap to go.
        /// </param>
        /// <param name="anotherUsername">
        /// The another username.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        protected bool ValidatePassOn(string wrapToGo, string anotherUsername)
        {
            Wait(TimeSpan.FromSeconds(10));
            var validationTarget = Get <IWtApi>();
            var wrapInfo         = validationTarget.WrapInfoByTrackId(wrapToGo);
            var retVal           = string.Compare(wrapInfo.OwnerName, anotherUsername, StringComparison.InvariantCultureIgnoreCase) == 0;

            StfLogger.LogInfo($"ValidatePassOn: OwnerNow=[{wrapInfo.OwnerName}], anotherUser=[{anotherUsername}]");

            return(retVal);
        }
        public void TestSimpleTestDataManagement2()
        {
            var testCaseFileAndFolderUtils = new TestCaseFileAndFolderUtils(4002, @".\TestData\EndToEnd");
            var testDataValuesFilePath     = testCaseFileAndFolderUtils.GetTestCaseRootFilePath("TestDataValues.txt");
            var keyValuePairUtils          = new KeyValuePairUtils();
            var testData = keyValuePairUtils.ReadKeyValuePairsFromFile(testDataValuesFilePath);

            foreach (var testDataKey in testData.Keys)
            {
                var value = testData[testDataKey];

                StfLogger.LogInfo($"[{testDataKey}] has the value [{value}]");
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Form1"/> class.
        /// </summary>
        public Form1()
        {
            InitializeComponent();

            Mylogger = new StfLogger(LogfileName);
            MyAssert = new StfAssert(Mylogger)
            {
                EnableNegativeTesting = true
            };
            Mylogger.LogLevel = StfLogLevel.Trace;

            Mylogger.LogInfo("logFile opened from DemoApp constructor");
            TxtMessage.Text = @"Some test message";
        }
Exemplo n.º 10
0
        public void Tc005()
        {
            var pathToNewImage = GetNewImagePath();
            var me             = WrapTrackShell.Me();

            StfAssert.IsNotNull("Got a MeProfile", me);

            var oldImage = me.ActualImage();

            StfLogger.LogInfo($"Found image [{oldImage}] as actual Image");
            me.UploadProfileImage(pathToNewImage);

            var newImage = me.ActualImage();

            StfLogger.LogInfo($"After upload found image [{newImage}] as actual Image");
            StfAssert.StringNotEquals("Got a new actual image", oldImage, newImage);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Pass on the wrap to user 'username' (only possible for owner of wrap)
        /// </summary>
        /// <param name="username">
        /// The username.
        /// </param>
        /// <param name="ownershipStart">
        /// The ownership Start.
        /// If not set, default date is used
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool PassOn(string username, string ownershipStart = null)
        {
            // click the Pass On Button in the menu
            if (!WebAdapter.ButtonClickByXpath("//button[@id='but_passon']"))
            {
                StfLogger.LogDebug("Couldn't press PassOn button");
                return(false);
            }

            if (!WebAdapter.TextboxSetTextById("inputBrugerSoeg", username, true))
            {
                StfLogger.LogDebug("Couldn't set brugerSoeg text");
                return(false);
            }

            // click the select user button
            if (!WebAdapter.ButtonClickById("but_selUser"))
            {
                StfLogger.LogDebug("Couldn't press SelectUser button");
                return(false);
            }

            // Choose a date for ownership-start
            if (ownershipStart != null)
            {
                WebAdapter.WaitForComplete(TimeSpan.FromSeconds(1));

                if (!WebAdapter.TextboxSetTextById("inp_datePassOn", ownershipStart))
                {
                    StfLogger.LogInfo("Date for ownership not changed");
                    return(false);
                }
            }

            // answer the R U sure
            if (!WebAdapter.ButtonClickById("but_goPassOn"))
            {
                StfLogger.LogDebug("Couldn't press R-U-Sure button");
                return(false);
            }

            return(true);
        }
Exemplo n.º 12
0
        public void Tc024()
        {
            // Set up user context for actual test
            // Use default user
            WrapTrackShell.Login();

            var me = WrapTrackShell.Me();

            StfAssert.IsNotNull("WrapTrackShell", WrapTrackShell);
            StfAssert.IsInstanceOfType("me", me, typeof(IMeProfile));

            // Create a new wrap
            var wrapCollection = me.GetCollection();

            StfAssert.IsNotNull("check if me.GetCollection null", wrapCollection);

            var newWrapWtId    = wrapCollection.AddWrap();
            var wtApi          = Get <IWtApi>();
            var wrapInfoBefore = wtApi.WrapInfoByTrackId(newWrapWtId);
            var internalId     = wrapInfoBefore.InternalId;

            // Move to the new wrap
            var wraptoSendOnVisit = WrapTrackShell.GetToWrap(internalId);

            // StfAssert.IsNotNull("Check if wraptoSendOnVisit is null", wraptoSendOnVisit);

            // Move to the new wrap
            // var wraptoSendOnVisit = WrapTrackShell.GetToWrap(newWrapWtId);
            var recipient = GetAnotherUser();

            // Send wrap away on holiday
            wraptoSendOnVisit.SendAwayTemporarily(SendAwayReason.Holiday, recipient);

            // Validate the the wrap indeed is on holiday
            var wrapInfoAfter = wtApi.WrapInfoByTrackId(newWrapWtId);
            var userId        = wtApi.UserId(recipient);

            StfLogger.LogInfo("The recipient user name, user id attempted is {0},{1} and userid from wrapInfo API is {1}", recipient, userId, wrapInfoAfter.VisitingUserId);

            StfAssert.IsTrue("Wrap is on holiday", wrapInfoAfter.OnHoliday);
            StfAssert.AreEqual("recipient userid is same as VisitingUserId in wrap", userId, wrapInfoAfter.VisitingUserId);
        }
Exemplo n.º 13
0
        protected async Task <HttpResponseMessage> PutWrapRestInfo(string uri)
        {
            HttpResponseMessage retVal = null;
            var client = new HttpClient();
            //HttpContent httpContent = new StringContent(new_doc.ToString(), Encoding.UTF8, "application/xml");
            var fullUri = $"{WtApiConfiguration.Url}/{uri}";

            try
            {
                retVal = await client.PutAsync(fullUri, new StreamContent(Stream.Null));

                StfLogger.LogInfo($"PutWrapRestInfo: Called [{fullUri}]");
                StfLogger.LogInfo($"PutWrapRestInfo: Got response [{retVal}]");
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"PutWrapRestInfo: Got response exception[{ex}]");
            }

            return(retVal);
        }
Exemplo n.º 14
0
        public void Tc010()
        {
            var testdata = InitTestData <Params>();

            // Find a random wrap
            var ranWrap = Collection.GetRandomWrap();
            var wtId    = ranWrap.WtId;

            StfAssert.IsNotNull("Got a random wrap", ranWrap);

            // Status of wrap before
            var validationTarget = Get <IWtApi>();
            var wrapInfo         = validationTarget.WrapInfoByTrackId(wtId);
            var statusBefore     = wrapInfo.Status;

            // When created the status is zero (0)
            StfAssert.AreEqual("Status", statusBefore, "0");

            // Delete wrap
            StfLogger.LogInfo($"DeleteOption = {testdata.DeleteOption}");

            var deleted = ranWrap.Remove(testdata.DeleteOption);

            if (!deleted)
            {
                StfLogger.LogInfo("The Wrap was not deleted - this test iteration stops");
            }
            else
            {
                Wait(TimeSpan.FromSeconds(2));

                // Status of wrap after
                StfLogger.LogInfo($"StatusAfter expeted = {testdata.StatusAfter}");
                wrapInfo = validationTarget.WrapInfoByTrackId(wtId);
                StfAssert.AreEqual("Correct status after deleting", testdata.StatusAfter, wrapInfo.Status);
            }

            WrapTrackShell.Logout();
        }
Exemplo n.º 15
0
        public void BaseTestCleanup()
        {
            LogBaseClassMessage("StfTestScriptBase BaseTestCleanup");

            var testFailed = !StfIgnoreRow &&
                             TestContext.CurrentTestOutcome != UnitTestOutcome.Passed &&
                             TestContext.CurrentTestOutcome != UnitTestOutcome.Inconclusive;

            if (testFailed)
            {
                StfLogger.LogError("Test failed");
            }

            if (!TestDataDriven())
            {
                StfArchiver.AddFile(StfLogger.FileName);
                StfArchiver.AddFile(kernelLogFilePath);
                StfLogger.LogInfo(StfArchiver.Status());
                StfLogger.CloseLogFile();
                StfArchiver.PerformArchive();
            }
            else
            {
                StfIterationNo = DataRowIndex();

                StfLogger.CloseLogFile();

                if (StfIterationNo == TestContext.DataRow.Table.Rows.Count)
                {
                    var myStfSummaryLogger           = new StfSummaryLogger();
                    var summaryLogfileLogDirname     = Path.GetDirectoryName(StfLogger.FileName);
                    var myLoggerFileName             = Path.GetFileName(StfLogger.FileName) ?? string.Empty;
                    var summaryLogfileLogFilename    = Regex.Replace(myLoggerFileName, @"_[0-9]+\.html", ".html");
                    var summaryLogfilename           = $@"{summaryLogfileLogDirname}\SummaryLogfile_{summaryLogfileLogFilename}";
                    var summaryLogfileLogfilePattern = Regex.Replace(myLoggerFileName, @"_[0-9]+\.html", "_*");

                    myStfSummaryLogger.CreateSummaryLog(summaryLogfilename, summaryLogfileLogDirname, summaryLogfileLogfilePattern);

                    TestContext.AddResultFile(summaryLogfilename);
                    AddResultfiles();

                    StfArchiver.AddFile(summaryLogfilename);
                    StfArchiver.PerformArchive();
                }
            }

            if (StfIgnoreRow)
            {
                // DoCleanUpAndThrowInconclusive will do the throwing if needed
                return;
            }

            if (!testFailed && StfAssert.CurrentInconclusives > 0 && StfAssert.CurrentFailures <= 0)
            {
                var msg = $"Testmethod [{TestContext.TestName}] is inconclusive. Number of inconclusive results: [{StfAssert.CurrentInconclusives}]";

                throw new AssertInconclusiveException(msg);
            }

            if (!testFailed && StfAssert.CurrentFailures > 0)
            {
                var msg = $"Testmethod [{TestContext.TestName}] failed. Number of asserts that failed: [{StfAssert.CurrentFailures}]";

                throw new AssertFailedException(msg);
            }
        }
Exemplo n.º 16
0
        public void BaseTestInitialize()
        {
            StfLogger = Get <IStfLogger>();

            var kernelLogErrors = CheckForFailedKernelLog(StfLogger);

            // We're getting the instance of the logger and logging a link to the kernel logger
            kernelLogFilePath = StfLogger.FileName;

            StfLogger.Configuration.LogTitle = TestContext.TestName;
            StfIterationNo = DataRowIndex();

            var logFilePostfix  = string.Empty;
            var iterationStatus = "Not datadriven";

            if (StfIterationNo == 1)
            {
                testResultFiles = new List <string>();
            }

            if (StfIterationNo >= 1)
            {
                var numberOfIterations = TestContext.DataRow.Table.Rows.Count;

                logFilePostfix  = GetlogFilePostfix(numberOfIterations, StfIterationNo);
                iterationStatus = $"Iteration {StfIterationNo}";
            }

            var logdir = Path.Combine(StfLogDir, TestContext.TestName);

            if (!Directory.Exists(logdir))
            {
                Directory.CreateDirectory(logdir);
            }

            var logFilename = $"{Path.Combine(logdir, TestContext.TestName)}{logFilePostfix}.html";

            StfLogger.FileName = logFilename;
            StfAssert          = new StfAssert(StfLogger);

            if (!TestDataDriven())
            {
                TestContext.AddResultFile(StfLogger.FileName);
                TestContext.AddResultFile(kernelLogFilePath);
            }
            else
            {
                if (!testResultFiles.Contains(StfLogger.FileName))
                {
                    // When datadriven we're defer adding resultfiles to testcontext until the last iteration
                    // This prevents MsTest from adding duplicate result files
                    testResultFiles.Add(StfLogger.FileName);
                }

                if (!testResultFiles.Contains(kernelLogFilePath))
                {
                    testResultFiles.Add(kernelLogFilePath);
                }

                for (var index = 0; index < TestContext.DataRow.Table.Columns.Count; index++)
                {
                    var headerCaption = TestContext.DataRow.Table.Columns[index].Caption;

                    StfLogger.LogInfo($"Column[{headerCaption}]=[{TestContext.DataRow[headerCaption]}]");
                }
            }

            SetUpArchiver(TestContext.TestName);

            LogBaseClassMessage("StfTestScriptBase TestInitialize");
            LogKeyValues(kernelLogFilePath, iterationStatus);

            if (kernelLogErrors.Any())
            {
                foreach (var kernelLogError in kernelLogErrors)
                {
                    StfLogger.LogError(kernelLogError);
                }

                StfAssert.AreEqual("No Kernel log errors present", 0, kernelLogErrors.Count);
            }

            if (StfIgnoreRow)
            {
                DoCleanUpAndThrowInconclusive("Row ignored due to StfIgnore is percieved true");
            }
        }