示例#1
0
        /// <summary>
        /// The learn more.
        /// </summary>
        /// <returns>
        /// Indication of success
        /// </returns>
        /// <summary>
        /// The login.
        /// </summary>
        /// <param name="userName">
        /// The user name.
        /// </param>
        /// <param name="password">
        /// The password.
        /// </param>
        public bool Login(string userName = null, string password = null)
        {
            // Handle defaults for username password
            userName = HandleDefault(userName, BtoWebConfiguration.UserName);
            password = HandleDefault(password, BtoWebConfiguration.Password);

            // CLick the login
            if (!WebAdapter.Click(By.XPath("//a[@href='/Account/Login']")))
            {
                StfLogger.LogError("Couldn't press login");
                return(false);
            }

            // fill in credentials
            WebAdapter.TextboxSetTextById("Email", userName);
            WebAdapter.TextboxSetTextById("password", password);

            // Click tab page Login
            WebAdapter.ButtonClickByXpath("//button[text()='Log in']");

            // Remember the last logged in user
            CurrentLoggedInUser = userName;

            return(true);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        /// The wrap info.
        /// </summary>
        /// <param name="info">
        /// The info.
        /// </param>
        /// <returns>
        /// The <see cref="ModelInfo"/>.
        /// </returns>
        private ModelInfo WrapInfoMapper(JObject info)
        {
            ModelInfo retVal;

            if (info == null)
            {
                return(null);
            }

            StfLogger.LogDebug($"ModelInfoMapper: Got info = [{info}]");

            try
            {
                var bent = new ModelInfo
                {
                    Name         = info["name"]?.ToString(),
                    Brand        = info["brand"]?.ToString(),
                    NumOfWraps   = GetInteger(info["numOfWraps"]?.ToString()),
                    NumOfReviews = GetInteger(info["numOfReviews"]?.ToString()),
                    PrimImagesId = info["primImagesId"]?.ToString(),
                    NumOfImages  = GetInteger(info["numOfImages"]?.ToString())
                };

                retVal = bent;
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"ModelInfoMapper: Got ex = [{ex}]");

                return(null);
            }

            return(retVal);
        }
        /// <summary>
        /// The handle check for errors on all pages.
        /// </summary>
        /// <exception cref="Exception">
        /// If a string is found the WebDriver is set to null, and an Exception is thrown
        /// </exception>
        private void HandleCheckForErrorsOnAllPages()
        {
            if (!Configuration.CheckForErrorsOnAllPages)
            {
                return;
            }

            StfLogger.LogHeader($"WebAdapter configured for checking errors on all pages matching [{Configuration.CheckForErrorsOnAllPagesText}]");

            var sourceText         = WebDriver.PageSource;
            var substringsInSource = CheckForSubstringsInSource(sourceText, Configuration.CheckForErrorsOnAllPagesText);

            if (!string.IsNullOrEmpty(substringsInSource))
            {
                var errorMsg = $"Found something matching [{Configuration.CheckForErrorsOnAllPagesText}] on page";

                StfLogger.LogError($"Found [{substringsInSource}] on page");
                StfLogger.LogHeader("****************************");
                StfLogger.LogHeader("*** FOUND ERRORS ON PAGE ***");
                StfLogger.LogHeader("****************************");
                StfLogger.LogScreenshot(StfLogLevel.Error, errorMsg);

                // Ensure/enforce errors from now on! - of the exception was caught somewhere
                WebDriver = null;

                throw new Exception(errorMsg);
            }

            StfLogger.LogDebug($"Looked for errors [{Configuration.CheckForErrorsOnAllPagesText}] on page - found none");
        }
示例#5
0
        /// <inheritdoc />
        public bool Add()
        {
            try
            {
                var addBtn = WebAdapter.ButtonClickById("butSaveReviewOneLang");

                WebAdapter.WaitForComplete(2);

                //toDo:  Button name, according to the test case it should be Add review in another.. now it is Add evaluation..
                var addBtnInAnotherLanguage = WebAdapter.FindElement(By.XPath(
                                                                         "//button[@id='butAddAnotherLang']/p/span/span[contains(text(),'Add evaluation in another language')]"));

                if (addBtnInAnotherLanguage == null)
                {
                    StfLogger.LogError("Couldn't find button Add review in another language");

                    return(false);
                }

                return(addBtn && addBtnInAnotherLanguage.Displayed);
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"Something went wrong when added review. Error message : [{ex.Message}]");
                throw;
            }
        }
        /// <summary>
        /// The check sign up validation messages.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool CheckSignUpValidationMessages()
        {
            var signUpValidationMessages = new List <string>
            {
                "Please read and approve the terms and conditions",
                "The username must be between four and 25 characters long. Only numbers, letters, and hyphen are accepted.",
                "The password must be at least five characters long.",
                "Please specify a valid e-mail address"
            };

            // we dont want to wait "long time" for each message, which we would if not initially wating 3 secs.. Now each can wait 1!
            WebAdapter.WaitForComplete(3);

            foreach (var signUpValidationMessage in signUpValidationMessages)
            {
                var xpath = $@"(//p[text()='{signUpValidationMessage}'])[1]";
                var validationMessageElement = WebAdapter.FindElement(By.XPath(xpath), 1);

                if (validationMessageElement == null)
                {
                    // found no error indication - All's well - so far...
                    continue;
                }

                StfLogger.LogError($"SignUp. There is validation error. Message : [{signUpValidationMessage}]");
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// The set review property value.
        /// </summary>
        /// <param name="modelReviewProperty">
        /// The model review property.
        /// </param>
        /// <param name="modelReviewValues">
        /// The review value.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool SetReviewPropertyValue(ModelReviewProperties modelReviewProperty, ModelReviewValues modelReviewValues)
        {
            var criteriaText    = modelReviewProperty.GetDisplayName();
            var evaluationvalue = (int)modelReviewValues;
            var xPath           = "(//p/span[text()='" +
                                  criteriaText +
                                  "']/../../following::div/anmeldelse_bedoemmelse_punkt[" +
                                  evaluationvalue +
                                  "])[1]";

            StfLogger.LogDebug("criteria text xpath ", xPath);

            var retVal = WrapTrackWebShell.WebAdapter.Click(By.XPath(xPath));

            if (!retVal)
            {
                StfLogger.LogError($"Couldn't find the criteria {modelReviewProperty}");
                return(false);
            }

            WebAdapter.WaitForComplete(1);
            retVal = WebAdapter.Click(By.Id("butSaveReviewOneLang"));

            return(retVal);
        }
示例#8
0
        /// <summary>
        /// Upload an profile image
        /// </summary>
        /// <param name="clientSideFilePath">
        /// The client Side File Path.
        /// </param>
        /// <returns>
        /// Inidcation of success
        /// </returns>
        public bool UploadProfileImage(string clientSideFilePath)
        {
            // Visit upload page
            WebAdapter.ButtonClickById("nav_upload_profile");

            // handle the File Upload Dialog
            WebAdapter.NativeDialogFileUpload(By.Name("userfile"), clientSideFilePath);

            var submitButton = WebAdapter.FindElement(By.Id("but_doupload"));

            if (submitButton == null)
            {
                StfLogger.LogError("Couldn't find the upload button");

                return(false);
            }

            submitButton.Click();

            // Back to me again
            var navBack = WebAdapter.FindElement(By.Id("but_back"));

            navBack.Click();

            return(true);
        }
示例#9
0
        /// <summary>
        /// The logout.
        /// </summary>
        /// <param name="doCareAboutErrors">
        /// Mostly used in close down scenarios - there we just want to close down - not really caring about success or not
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool Logout(bool doCareAboutErrors = true)
        {
            if (CurrentLoggedInUser == null)
            {
                return(true);
            }

            CurrentLoggedInUser = null;

            try
            {
                if (WebAdapter.Click(By.XPath("//img[@alt='avatar']")))
                {
                    if (WebAdapter.Click(By.XPath("//a[@href='/Account/LogOff']")))
                    {
                        return(true);
                    }
                }

                if (doCareAboutErrors)
                {
                    StfLogger.LogError("Got error while logging out");
                }
            }
            catch
            {
                // slurp
            }

            // if we cant click the logout button, then the return value is down to if we care or not:-)
            return(doCareAboutErrors);
        }
示例#10
0
        /// <summary>
        /// The user info mapper.
        /// </summary>
        /// <param name="info">
        /// The info.
        /// </param>
        /// <returns>
        /// The <see cref="UserInfo"/>.
        /// </returns>
        private UserInfo UserInfoMapper(JObject info)
        {
            if (info == null)
            {
                return(null);
            }

            UserInfo retVal;

            StfLogger.LogDebug($"UserInfoMapper: Got info = [{info}]");

            try
            {
                var bent = new UserInfo
                {
                    UserId   = info["user_id"]?.ToString(),
                    UserName = info["user_name"]?.ToString(),
                };

                retVal = bent;
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"UserInfoMapper: Got ex = [{ex}]");

                return(null);
            }

            return(retVal);
        }
示例#11
0
        /// <summary>
        /// Gets or sets the add brand.
        /// </summary>
        /// <returns>
        /// The <see cref="IAddBrand"/>.
        /// </returns>
        public IAddBrand AddBrand()
        {
            StfLogger.LogError("AddBrand is no longer supported by the WrapTrack UI");
            StfLogger.LogInconclusive("UnSUpported", "AddBrand is no longer supported by the WrapTrack UI");

            return(null);
        }
示例#12
0
        /// <summary>
        /// The get news entry carrier evaulation
        /// </summary>
        /// <param name="modelName">
        /// The model name
        /// </param>
        /// <param name="criteria">
        /// The criteria
        /// </param>
        /// <returns>
        /// The <see cref="INewsEntryCarrierEvaluation"/>.
        /// </returns>
        public INewsEntryCarrierEvaluation GetNewsEntryCarrierEvaluation(string modelName, string criteria)
        {
            var elements = WebAdapter.FindElements(By.Id("anmeldelse_bedoemmelse"));

            // TODO: Could be we should call the API so this becomes a bit more event driven:-)
            WebAdapter.WaitForComplete(30);
            StfLogger.LogDebug("no. carrier evaluations :" + elements.Count);

            if (elements.Count != 1)
            {
                StfLogger.LogError($"only support 1 carrier evaluation - found {elements.Count} elements");
                return(null);
            }

            var element = elements.First();

            if (element == null)
            {
                StfLogger.LogError("elements.first() returned a null element");
                return(null);
            }

            var newsEntryCarrierEvaluation = Get <INewsEntryCarrierEvaluation>();

            if (newsEntryCarrierEvaluation == null)
            {
                StfLogger.LogError("Could not get newsEntryCarrierEvaluation from Get<INewsEntryCarrierEvaluation>");
                return(null);
            }

            newsEntryCarrierEvaluation.Text = element.Text;

            if (!newsEntryCarrierEvaluation.HeaderText.Contains(WrapTrackWebShell.CurrentLoggedInUser))
            {
                StfLogger.LogDebug("Returning null as !newsEntryCarrierEvaluation.HeaderText.Contains(WrapTrackWebShell.CurrentLoggedInUser)");
                return(null);
            }

            if (!newsEntryCarrierEvaluation.WrapText.Contains(modelName))
            {
                StfLogger.LogDebug("Returning null as !newsEntryCarrierEvaluation.WrapText.Contains(modelId)");
                return(null);
            }

            if (!newsEntryCarrierEvaluation.CriteriaText.Equals(criteria))
            {
                StfLogger.LogDebug("Returning null as !newsEntryCarrierEvaluation.CriteriaText.Equals(criteria)");
                return(null);
            }

            return(newsEntryCarrierEvaluation);
        }
示例#13
0
        /// <summary>
        /// The get news entry carrier review.
        /// </summary>
        /// <param name="modelName">
        /// The model name
        /// </param>
        /// <param name="reviewText">
        /// The text for the review
        /// </param>
        /// <returns>
        /// The <see cref="INewsEntryCarrierReview"/>.
        /// </returns>
        public INewsEntryCarrierReview GetNewsEntryCarrierReview(string modelName, string reviewText)
        {
            var elements = WebAdapter.FindElements(By.Id("anmeldelse_vurdering"));

            WebAdapter.WaitForComplete(30);

            StfLogger.LogDebug("no. carrier review stories :" + elements.Count);
            if (elements.Count != 1)
            {
                StfLogger.LogError("only support 1 carrier review");
                return(null);
            }

            var element = elements.First();

            if (element == null)
            {
                StfLogger.LogError("elements.first() returned a null element");
                return(null);
            }

            var newsEntryCarrierReview = Get <INewsEntryCarrierReview>();

            if (newsEntryCarrierReview == null)
            {
                StfLogger.LogError("Could not get newsEntryCarrierReview from Get<INewsEntryCarrierReview>");
                return(null);
            }

            newsEntryCarrierReview.Text = element.Text;

            if (!newsEntryCarrierReview.HeaderText.Contains(WrapTrackWebShell.CurrentLoggedInUser))
            {
                StfLogger.LogDebug("Returning null as !newsEntryCarrierReview.HeaderText.Contains(WrapTrackWebShell.CurrentLoggedInUser)");
                return(null);
            }

            if (!newsEntryCarrierReview.WrapText.Contains(modelName))
            {
                StfLogger.LogDebug("Returning null as !newsEntryCarrierReview.WrapText.Contains(modelId)");
                return(null);
            }

            if (!newsEntryCarrierReview.ReviewText.Equals(reviewText))
            {
                StfLogger.LogDebug("Returning null as !newsEntryCarrierReview.ReviewText.Equals(reviewText)");
                return(null);
            }

            return(newsEntryCarrierReview);
        }
        /// <summary>
        /// The sign up and login.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool SignUpAndLogin()
        {
            try
            {
                const string Password      = "******";
                var          newUsername   = WtUtils.GetRandomUsername();
                var          signUpNewUser = SignUp(newUsername, Password);

                return(signUpNewUser);
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"Something went wrong when sign up and login. Message : [{ex.Message}]");
                throw;
            }
        }
        /// <summary>
        /// The get to wrap.
        /// </summary>
        /// <param name="wrapId">
        /// The wrap id.
        /// </param>
        /// <returns>
        /// The <see cref="IWrap"/>.
        /// </returns>
        public IWrap GetToWrap(string wrapId)
        {
            var baseUrl   = WtConfiguration.Url;
            var wrapIdUrl = $"{baseUrl}Collection/wrap/{wrapId}";
            var openUrl   = WebAdapter.OpenUrl(wrapIdUrl);

            if (!openUrl)
            {
                StfLogger.LogError($"Couldn't open the url [{wrapIdUrl}]");
                return(null);
            }

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

            return(retVal);
        }
        /// <summary>
        /// The textbox set text by.
        /// </summary>
        /// <param name="by">
        /// The by.
        /// </param>
        /// <param name="textToEnter">
        /// The text to enter.
        /// </param>
        /// <param name="handlePopup">
        /// Some text boxes have a search popup ... This switch is default false
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool TextboxSetTextBy(By by, string textToEnter, bool handlePopup = false)
        {
            StfLogger.LogDebug($"Textbox : Setting text [{textToEnter}] - by=[{by}]");
            WaitForComplete(2);

            var element = FindElement(by);

            if (element == null)
            {
                StfLogger.LogError($"Can't find textbox - by=[{by}]");

                return(false);
            }

            try
            {
                element.Clear();
                element.SendKeys(textToEnter);

                if (handlePopup)
                {
                    // handle the funky suggestion popup, by selecting the first in the list
                    var popupFirstElement = FindElement(By.XPath("//li[@class='ui-menu-item'][1]"));

                    if (popupFirstElement == null)
                    {
                        StfLogger.LogWarning("TextboxSetTextBy: Was instructed to handle popup - but no element was found");
                        return(false);
                    }

                    popupFirstElement.Click();
                }
                else
                {
                    element.SendKeys(Keys.Tab);
                }
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"Can't send text to textbox - ex=[{ex}]");

                return(false);
            }

            return(true);
        }
示例#17
0
        /// <summary>
        /// The wrap info.
        /// </summary>
        /// <param name="info">
        /// The info.
        /// </param>
        /// <returns>
        /// The <see cref="WrapInfo"/>.
        /// </returns>
        private WrapInfo WrapInfoMapper(JObject info)
        {
            if (info == null)
            {
                return(null);
            }

            WrapInfo retVal;

            StfLogger.LogDebug($"WrapInfoMapper: Got info = [{info}]");

            try
            {
                var bent = new WrapInfo
                {
                    OwnerId         = info["ejerskab_nuv"]?.SelectToken("bruger_id")?.ToString(),
                    OwnerName       = info["ejerskab_nuv"]?.SelectToken("bruger_navn")?.ToString(),
                    InternalId      = info.SelectToken("id")?.ToString(),
                    Size            = info.SelectToken("id")?.ToString(),
                    OwnershipNumber = info["ejerskab_nuv"]?.SelectToken("nr")?.ToString(),
                    Status          = info.SelectToken("status")?.ToString(),
                    VisitingUserId  = info["besoeg_nuv"]?.SelectToken("besoeg_bruger_id")?.ToString()
                };

                retVal = bent;
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"WrapInfoMapper: Got ex = [{ex}]");

                return(null);
            }

            retVal.NumOfOwnershipPic = GetInteger(info["ejerskab_nuv"]?.SelectToken("private_billeder")?.ToString());

            // sometime we dont have this node - if not, then the value is zero:-)
            retVal.NumOfPictures = info["billeder"]?.Count() ?? 0;

            // get the holiday status
            var holidayStatus = info["besoeg_nuv"]?.SelectToken("type")?.ToString();

            retVal.OnHoliday = string.Equals(holidayStatus, "ferie", StringComparison.CurrentCultureIgnoreCase);

            return(retVal);
        }
示例#18
0
        /// <summary>
        /// The remove number of pictures from colleciton.
        /// </summary>
        /// <param name="wrap">
        /// The wrap.
        /// </param>
        /// <param name="numberOfPictures">
        /// The number of pictures.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        // ReSharper disable once UnusedMethodReturnValue.Local
        // - Okay - might make it as a general utils, and then we want it to return int
        private int RemovePicturesFromWrap(
            IWrap wrap,
            int numberOfPictures)
        {
            for (var i = 0; i < numberOfPictures; i++)
            {
                var allsWell = wrap.RemoveWrapImage();

                if (!allsWell)
                {
                    // Something went wrong - return the number of images removed so far
                    StfLogger.LogError($"Couldn't delete all images - failed at image number {i + 1}");

                    return(i);
                }
            }

            return(numberOfPictures);
        }
示例#19
0
        /// <summary>
        /// The get news entry carrier story that contains the chapter text for the wrap.
        /// </summary>
        /// <param name="wrapId">
        /// The wrap id.
        /// </param>
        /// <param name="chapterText">
        /// The chapter text.
        /// </param>
        /// <returns>
        /// The <see cref="INewsEntryCarrierStory"/>.
        /// </returns>
        public INewsEntryCarrierStory GetNewsEntryCarrierStory(string wrapId, string chapterText)
        {
            var elements = WebAdapter.FindElements(By.Id("baereredskab_fortaelling"));

            if (elements.Count != 1)
            {
                StfLogger.LogError("only support 1 carrier story");
                return(null);
            }

            var element = elements.First();

            if (element == null)
            {
                StfLogger.LogError("elements.first() returned a null element");
                return(null);
            }

            var newsEntryCarrierStory = Get <INewsEntryCarrierStory>();

            if (newsEntryCarrierStory == null)
            {
                StfLogger.LogError("Could not newsEntryCarrierStory from Get<INewsEntryCarrierStory>");
                return(null);
            }

            newsEntryCarrierStory.Text = element.Text;

            // :TODO test also for currentloggedinser at start of header text. Waiting for issue #33. See next comment line
            // if (!newsEntryCarrierStory.HeaderText.Contains(WrapTrackWebShell.CurrentLoggedInUser)
            var baseHeaderTextForNewsStory = "has written a new chapter in the story";

            if (!newsEntryCarrierStory.HeaderText.Contains(baseHeaderTextForNewsStory)
                ||
                !newsEntryCarrierStory.WrapText.Contains(wrapId)
                ||
                !newsEntryCarrierStory.ChapterText.Equals(chapterText))
            {
                return(null);
            }

            return(newsEntryCarrierStory);
        }
示例#20
0
        /// <summary>
        /// The set up archiver if necessary.
        /// </summary>
        /// <param name="testName">
        /// The test name.
        /// </param>
        private void SetUpArchiver(string testName)
        {
            var stfConfiguration      = Get <StfConfiguration>();
            var archiverConfiguration = new StfArchiverConfiguration();

            try
            {
                stfConfiguration.LoadUserConfiguration(archiverConfiguration);
            }
            catch (Exception exception)
            {
                var msg = $"Something went wrong while loading user configuration for archiver: {exception.Message}";
                StfLogger.LogError(msg);
            }

            archiverConfiguration.ArchiveTopDir      = StfTextUtils.ExpandVariables(archiverConfiguration.ArchiveTopDir);
            archiverConfiguration.ArchiveDestination = StfTextUtils.ExpandVariables(archiverConfiguration.ArchiveDestination);
            archiverConfiguration.TempDirectory      = StfTextUtils.ExpandVariables(archiverConfiguration.TempDirectory);
            StfArchiver = new StfArchiver(archiverConfiguration, testName);
        }
示例#21
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);
        }
        /// <summary>
        /// The logout.
        /// </summary>
        /// <param name="doCareAboutErrors">
        /// Mostly used in close down scenarios - there we just want to close down - not really caring about success or not
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool Logout(bool doCareAboutErrors = true)
        {
            try
            {
                if (WebAdapter.Click(By.Id("nav_logout")))
                {
                    return(true);
                }

                if (doCareAboutErrors)
                {
                    StfLogger.LogError("Got error while logging out");
                }
            }
            catch
            {
                // slurp
            }

            // if we cant click the logout button, then the return value is down to if we care or not:-)
            return(doCareAboutErrors);
        }
示例#23
0
        /// <summary>
        /// The get news entry carrier for sale.
        /// </summary>
        /// <param name="wrapId">
        /// The wrap id.
        /// </param>
        /// <param name="typeOfSale">
        /// The type Of Sale.
        /// </param>
        /// <returns>
        /// The <see cref="INewsEntryCarrierForSale"/>.
        /// </returns>
        public INewsEntryCarrierForSale GetNewsEntryCarrierForSale(string wrapId, string typeOfSale)
        {
            var elements = WebAdapter.FindElements(By.Id("baereredskab_paamarkedet"));

            if (elements.Count != 1)
            {
                StfLogger.LogError("only support 1 carrier story");
                return(null);
            }

            var element = elements.First();

            if (element == null)
            {
                StfLogger.LogError("elements.first() returned a null element");
                return(null);
            }

            var newsEntryCarrierForSale = Get <INewsEntryCarrierForSale>();

            if (newsEntryCarrierForSale == null)
            {
                StfLogger.LogError("Could not get newsEntryCarrierForSale from Get<INewsEntryCarrierForSale>");
                return(null);
            }

            newsEntryCarrierForSale.Text = element.Text;

            if (!newsEntryCarrierForSale.HeaderText.Contains(WrapTrackWebShell.CurrentLoggedInUser)
                ||
                !newsEntryCarrierForSale.WrapText.Contains(wrapId)
                ||
                !newsEntryCarrierForSale.StatusText.Equals(typeOfSale))
            {
                return(null);
            }

            return(newsEntryCarrierForSale);
        }
示例#24
0
        /// <summary>
        /// The review.
        /// </summary>
        /// <returns>
        /// The <see cref="IReview"/>.
        /// </returns>
        public IReview Review()
        {
            try
            {
                var buttonClick = WebAdapter.ButtonClickByXpath("(//button//span[text()='Review'])[2]");

                // var buttonClick = WebAdapter.ButtonClickById("butAddReview");
                if (!buttonClick)
                {
                    return(null);
                }

                var reviewDetails = Get <IReview>();

                return(reviewDetails);
            }
            catch (Exception ex)
            {
                StfLogger.LogError($"Something went wrong when opening Review. Message : [{ex.Message}]");
                throw;
            }
        }
示例#25
0
        /// <summary>
        /// The kill process.
        /// </summary>
        /// <param name="processName">
        /// The process name.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool KillProcesses(string processName)
        {
            StfLogger.LogDebug("Starting to kill all processes with name [{0}]", processName);

            var seleniumDriverProcesses = Process.GetProcesses().Where(pr => pr.ProcessName == processName);
            var retVal = true;

            foreach (var process in seleniumDriverProcesses)
            {
                try
                {
                    StfLogger.LogDebug("Killing process with ID [{0}]", process.Id);
                    process.Kill();
                }
                catch (Exception ex)
                {
                    StfLogger.LogWarning("Challenges killing one process [{0}]", ex.Message);
                    retVal = false;
                }
            }

            // Process does not leave the process list immediately, stays in there as hasexited = true
            Thread.Sleep(Configuration.WaitTimeForProcessExit);

            // note if we did indeed kill all the processes...
            seleniumDriverProcesses = Process.GetProcesses().Where(pr => pr.ProcessName == processName);
            var allProcessKilled = !seleniumDriverProcesses.Any();

            retVal = retVal && allProcessKilled;

            if (!retVal)
            {
                StfLogger.LogError("Challenges killing processes{0}", !allProcessKilled ? " - Still some processes left to kill" : string.Empty);
            }

            return(retVal);
        }
示例#26
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);
            }
        }
示例#27
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");
            }
        }