示例#1
0
        /// <summary>
        /// The initialize web driver internet explorer.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool InitializeWebDriverInternetExplorer()
        {
            var retVal        = true;
            var driverOptions = GetInternetExplorerOptions();

            try
            {
                var driverService = InternetExplorerDriverService.CreateDefaultService(Configuration.DriverServerPath);

                driverService.LogFile      = DriverLogFile;
                driverService.LoggingLevel = GetDriverLoggingLevel();

                WebDriver = new InternetExplorerDriver(
                    driverService,
                    driverOptions,
                    TimeSpan.FromSeconds(Configuration.BrowserTimeout));
                WebDriver.Manage().Window.Maximize();
                ResetImplicitlyWait();
            }
            catch (Exception ex)
            {
                StfLogger.LogInternal($"Couldn't Initialize WebAdapter - got error [{ex.Message}]");
                retVal = false;
            }

            StfLogger.LogDebug("Done initializing {0}. Successful: {1}", GetType().Name, retVal.ToString());

            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");
        }
示例#3
0
        /// <summary>
        /// The get user info.
        /// </summary>
        /// <param name="userName">
        /// The user name.
        /// </param>
        /// <returns>
        /// The <see cref="User"/>.
        /// </returns>
        protected User GetUserInfo(string userName)
        {
            if (string.IsNullOrEmpty(userName))
            {
                return(default(User));
            }

            var    queryFormat = "Users.{0}.{1}";
            var    userNameKey = string.Format(queryFormat, userName, "Username");
            var    passwordKey = string.Format(queryFormat, userName, "Password");
            string user;
            string password;

            try
            {
                user     = StfConfiguration.GetConfigValue(userNameKey);
                password = StfConfiguration.GetConfigValue(passwordKey);
            }
            catch (Exception exception)
            {
                StfLogger.LogDebug(string.Format("Did not find a user for {0}. Errormessage: {1}", userNameKey, exception.Message));
                throw;
            }

            return(new User {
                UserName = user, Password = password
            });
        }
示例#4
0
        /// <summary>
        /// The init.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool Init()
        {
            var retVal = true;

            StfLogger.LogDebug("Starting to initialize [{0}]", GetType().Name);
            Configuration = GetConfiguration();
            DriverLogFile = GetDriverLogFilePath();

            if (Configuration.KillAllSeleniumBeforeInit)
            {
                if (!KillProcesses())
                {
                    return(false);
                }
            }

            switch (Configuration.BrowserName.ToLower())
            {
            case "chrome":
                retVal = InitializeWebDriverChrome();
                break;

            case "internetexplorer":
                retVal = InitializeWebDriverInternetExplorer();
                break;
            }

            StfLogger.LogDebug("Done initializing {0}. Successful: {1}", GetType().Name, retVal.ToString());

            return(retVal);
        }
示例#5
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);
        }
示例#6
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 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>
        /// 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);
        }
        /// <summary>
        /// The get driver logging level.
        /// </summary>
        /// <returns>
        /// The <see cref="InternetExplorerDriverLogLevel"/>.
        /// </returns>
        private InternetExplorerDriverLogLevel GetDriverLoggingLevel()
        {
            InternetExplorerDriverLogLevel logLevel;

            if (Enum.TryParse(Configuration.DriverLogLevel, true, out logLevel))
            {
                return(logLevel);
            }

            StfLogger.LogDebug("Unable to parse loglevel for IE driver. Tried parsing: [{0}]", Configuration.DriverLogLevel);

            return(InternetExplorerDriverLogLevel.Trace);
        }
        /// <summary>
        /// The check box.
        /// </summary>
        /// <param name="by">
        /// The by.
        /// </param>
        /// <returns>
        /// The <see cref="IWebElement"/>.
        /// </returns>
        public IWebElement CheckBox(By by)
        {
            var elem = FindElement(by);

            if (elem == null)
            {
                StfLogger.LogDebug("Couldn't find CheckBox");

                return(null);
            }

            return(elem);
        }
示例#11
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 get driver log file path.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        private string GetDriverLogFilePath()
        {
            if (!CheckPath(DefaultLogPath))
            {
                return(string.Empty);
            }

            var retVal = string.Format(@"{0}\Ie_{1}.log", DefaultLogPath, DateTime.Now.ToString("ddMMyyyy_hhmmssff"));

            if (File.Exists(retVal))
            {
                StfLogger.LogDebug("IE log file already exists! File path: [{0}]", retVal);
            }

            return(retVal);
        }
示例#13
0
        /// <summary>
        /// Ask for the wrap (only possible for not-owner of wrap)
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool AskFor()
        {
            if (!WebAdapter.ButtonClickById("but_please"))
            {
                StfLogger.LogDebug("Couldn't press 'Request wrap'");
                return(false);
            }

            if (!WebAdapter.ButtonClickById("but-ReqWrapOK"))
            {
                StfLogger.LogDebug("Couldn't press 'Request wrap sec time'");
                return(false);
            }

            return(true);
        }
        /// <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);
        }
示例#15
0
        /// <summary>
        /// The find elements.
        /// </summary>
        /// <param name="by">
        /// The by.
        /// </param>
        /// <returns>
        /// The collection of elements that matches the search term.
        /// </returns>
        public IReadOnlyCollection <IWebElement> FindElements(By by)
        {
            IReadOnlyCollection <IWebElement> retVal;

            try
            {
                retVal = WebDriver.FindElements(by);
            }
            catch (Exception ex)
            {
                // this might not be an error - if we are looking for something to become rendered in a loop....
                StfLogger.LogDebug(string.Format("Couldn't find one or more elements matching [{0}] - got error [{1}]", by, ex.Message));
                retVal = null;
            }

            return(retVal);
        }
示例#16
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);
        }
示例#17
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);
        }
        /// <summary>
        /// The find element.
        /// </summary>
        /// <param name="by">
        /// The by.
        /// </param>
        /// <returns>
        /// The <see cref="IWebElement"/>.
        /// </returns>
        public IWebElement FindElement(By by)
        {
            IWebElement retVal;

            HandleCheckForErrorsOnAllPages();

            try
            {
                StfLogger.LogDebug($"Looking for FindElement [{by}]");
                retVal = WebDriver.FindElement(by);
            }
            catch (Exception ex)
            {
                // this might not be an error - if we are looking for something to become rendered in a loop....
                StfLogger.LogDebug($"Couldn't find element [{by}] - got error [{ex.Message}]");
                retVal = null;
            }

            return(retVal);
        }
示例#19
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);
        }
        /// <summary>
        /// The double click element.
        /// </summary>
        /// <param name="element">
        /// The element.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool DoubleClickElement(IWebElement element)
        {
            var retVal = false;

            if (element == null)
            {
                return(false);
            }

            try
            {
                var actions = new Actions(WebDriver);

                actions.DoubleClick(element).Build().Perform();

                retVal = true;
            }
            catch (Exception ex)
            {
                StfLogger.LogDebug("Caught error double clicking at element. Error: [{0}]", ex.Message);
            }

            return(retVal);
        }