Exemple #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);
        }
        public void Tc031()
        {
            var testdata = InitTestData <TestDataAddWrapConversion>();

            WrapTrackShell = Get <IWrapTrackWebShell>();

            // Use default user
            WrapTrackShell.Login();

            var testCaseUtil = new TestCaseUtils(StfAssert);
            var addCarrier   = testCaseUtil.GetAddCarrier(WrapTrackShell, testdata.CarrierType);

            StfAssert.IsTrue("HandleHomeMade", testCaseUtil.HandleHomeMade(addCarrier, testdata.HomeMade));

            testCaseUtil.HandleBrandCarriertypenicknameCarriermodel(
                addCarrier,
                testdata.Brand,
                testdata.CarrierTypeNickName,
                testdata.CarrierModel);

            StfAssert.IsTrue("Save", addCarrier.Save());

            // Log where we got redirected to - Page Safe is fine - Control is better:-)
            StfLogger.LogScreenshot(StfLogLevel.SubHeader, "After Pressed Save");
        }
        /// <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 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);
        }
        /// <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);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }
        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);
        }
Exemple #9
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
            });
        }
Exemple #10
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 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");
        }
Exemple #12
0
        /// <summary>
        /// The initialize web driver chrome.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool InitializeWebDriverChrome()
        {
            var retVal        = true;
            var driverOptions = GetChromeOptionsOptions();

            try
            {
                if (Configuration.KillAllSeleniumBeforeInit)
                {
                    if (!KillProcesses("chromedriver.exe"))
                    {
                        return(false);
                    }
                }

                var driverService = ChromeDriverService.CreateDefaultService(Configuration.DriverServerPath);

                driverService.LogPath = DriverLogFile;
                driverService.EnableVerboseLogging = true; //TODO get this right

                WebDriver = new ChromeDriver(
                    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;
            }

            return(retVal);
        }
Exemple #13
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);
        }
 /// <summary>
 /// The log unsafe driver settings.
 /// </summary>
 /// <param name="driverOptions">
 /// The driver options.
 /// </param>
 private void LogUnsafeDriverSettings(InternetExplorerOptions driverOptions)
 {
     if (driverOptions.IntroduceInstabilityByIgnoringProtectedModeSettings)
     {
         StfLogger.LogWarning("Driver is configured to ignore protected mode settings. This could cause instabillity!");
     }
 }
Exemple #15
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);
        }
Exemple #16
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 click.
        /// </summary>
        /// <param name="by">
        /// The by.
        /// </param>
        /// <param name="depth">
        /// Only used internally to stir out of endless recursion
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool Click(By by, int depth = 0)
        {
            var  button = FindElement(by);
            bool retVal;

            if (button == null || depth >= 5)
            {
                StfLogger.LogInternal($"Can't find button - by=[{by}]");

                return(false);
            }

            try
            {
                if (!button.Enabled)
                {
                    WaitForComplete(1);
                }

                button.Click();
                retVal = true;
            }
            catch (Exception ex)
            {
                StfLogger.LogInternal("Click failed - Have to reclick - got exception [{0}]", ex.Message);

                // if we cant get to click the button, then the UI has changed (like we did press search, but the page wasn't rendered fully yet)
                retVal = Click(by, depth + 1);
            }

            return(retVal);
        }
Exemple #18
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);
        }
Exemple #19
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);
        }
        /// <summary>
        /// The helper test file paths all steps.
        /// </summary>
        /// <param name="testCaseName">
        /// The test case name.
        /// </param>
        /// <param name="testCaseId">
        /// The test case id.
        /// </param>
        /// <param name="fileNameFilters">
        /// The file name filters.
        /// </param>
        /// <param name="numSteps">
        /// The num steps.
        /// </param>
        /// <param name="expectedFilePaths">
        /// The expected file paths.
        /// </param>
        private void HelperTestFilePathsAllSteps(
            string testCaseName,
            int testCaseId,
            string[] fileNameFilters,
            int numSteps,
            string[,] expectedFilePaths)
        {
            StfLogger.LogHeader(testCaseName);
            var testCaseFileAndFolderUtils = new TestCaseFileAndFolderUtils(testCaseId, UnitTestTestDataRoot);
            var testCaseStepFilePathUtils  = new TestCaseStepFilePathUtils(
                testCaseFileAndFolderUtils.TestCaseDirectory,
                fileNameFilters,
                true);

            for (int stepNum = 1; stepNum <= numSteps; stepNum++)
            {
                StfLogger.LogSubHeader($"Step {stepNum}");
                for (var fileNameFilterNo = 0; fileNameFilterNo < fileNameFilters.Length; fileNameFilterNo++)
                {
                    var actual = testCaseStepFilePathUtils.GetFileNameForStep(fileNameFilters[fileNameFilterNo], stepNum);
                    StfAssert.AreEqual(
                        "FileNames for step are equal",
                        expectedFilePaths[stepNum - 1, fileNameFilterNo],
                        actual);
                }
            }
        }
 public void TestFilePathsThreeFileFilters()
 {
     StfLogger.LogHeader("One Template, One Config, One Tdv");
     HelperThreeFileFilters("One, One, one", 43111, "Template.txt", 1, "Template.txt");
     HelperThreeFileFilters("One, One, one", 43111, "Config.txt", 1, "Config.txt");
     HelperThreeFileFilters("One, One, one", 43111, "TestDataValues.txt", 1, "TestDataValues.txt");
 }
        /// <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);
        }
Exemple #23
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>
        /// 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);
        }
        public void Tc001()
        {
            // Use default user
            BookTidOnlineShell.Login();

            StfAssert.IsNotNull("BookTidOnlineShell", BookTidOnlineShell);
            StfLogger.LogScreenshot(StfLogLevel.Info, "Logged in");
        }
        /// <summary>
        /// Make sure LogLevel is set to internal and set it back again
        /// </summary>
        /// <param name="message">
        /// The message.
        /// </param>
        private void LogBaseClassMessage(string message)
        {
            var oldLoglevel = StfLogger.LogLevel;

            StfLogger.LogLevel = StfLogLevel.Internal;
            StfLogger.LogInternal(message);
            StfLogger.LogLevel = oldLoglevel;
        }
        /// <summary>
        /// The init test data.
        /// </summary>
        /// <param name="testdataObject">
        /// The testdata object.
        /// </param>
        /// <typeparam name="T">
        /// The testdata object that should be filled with the values from the current row in the TestContext
        /// </typeparam>
        /// <returns>
        /// The <see cref="T"/>.
        /// </returns>
        protected T InitTestData <T>(T testdataObject = default(T)) where T : IStfTestData, new()
        {
            if (!TestDataDriven())
            {
                if (testdataObject != null)
                {
                    testdataObject.StfIteration = -1;
                }

                return(testdataObject);
            }

            var retVal               = new T();
            var properties           = typeof(T).GetProperties();
            var attributedProperties = properties.Where(prop => prop.IsDefined(typeof(StfTestDataAttribute), false)).ToList();
            var dataRow              = TestContext.DataRow;

            retVal.StfIteration = DataRowIndex();

            foreach (var columnName in dataRow.Table.Columns)
            {
                var propertyName = columnName.ToString();
                var property     = properties.FirstOrDefault(pp => pp.Name == propertyName);

                // did we find the correspondig property in the testdata class?
                if (property == null && attributedProperties.Any())
                {
                    // hmm, lets see if there is a map for this column...
                    property = attributedProperties.FirstOrDefault(pp => pp.GetCustomAttribute <StfTestDataAttribute>().ColumnName == propertyName);
                }

                if (property == null)
                {
                    continue;
                }

                var propertyType = property.PropertyType;
                try
                {
                    var val = TypeDescriptor.GetConverter(propertyType).ConvertFromString(dataRow[propertyName].ToString());

                    property.SetValue(retVal, val);
                }
                catch (Exception ex)
                {
                    StfLogger.LogInternal(
                        "Caught error setting value for property [{0}] in testdata object [{1}]. Error: [{2}]",
                        property.Name,
                        typeof(T).Name,
                        ex.Message);
                }
            }

            // we might later alter stuff, so StfIgnoreRow also is triggered by StfIgnore
            retVal.StfIgnoreRow = StfIgnoreRow;

            return(retVal);
        }
Exemple #28
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);
        }
        /// <summary>
        /// The log key values.
        /// </summary>
        /// <param name="kernelLogfilePath">
        /// The kernel logfile path.
        /// </param>
        /// <param name="iterationStatus">
        /// The iteration status.
        /// </param>
        private void LogKeyValues(string kernelLogfilePath, string iterationStatus)
        {
            StfLogger.LogKeyValue("Test Iteration", iterationStatus, iterationStatus);
            StfLogger.LogKeyValue("Kernel Logger", kernelLogfilePath, "Kernel Logger");
            StfLogger.LogKeyValue("Test Name", TestContext.TestName, "Name of test");
            StfLogger.LogKeyValue("Stf Root", StfRoot, "The Stf Root directory");

            var configuration = Get <StfConfiguration>();

            StfLogger.LogKeyValue("Environment", configuration.Environment, "Configuration.EnvironmentName");
        }