public static Dictionary <string, string> ParseAsString(this string objString)
 {
     return(ExceptionUtils.ActionWithException(() =>
     {
         if (objString == null)
         {
             return null;
         }
         var result = new Dictionary <string, string>();
         var values = new List <string>();
         var i = 1;
         var str = objString;
         while (objString.IndexOf("#(#") > 0)
         {
             values.Add(objString.Substring(objString.IndexOf("#(#") + 3, objString.IndexOf("#)#")));
             str = objString.Replace("#\\(#.*#\\)#", "#VAL" + i++);
         }
         var fields = str.Split("#;#");
         fields.ForEach(field =>
         {
             var splitField = field.Split("#:#");
             if (splitField.Count == 2)
             {
                 result.Add(splitField[0], ProcessValue(splitField[1], values));
             }
         });
         return result;
     }, ex => $"Can't parse string '{objString}' to Object"));
 }
Esempio n. 2
0
 public TResult DoJActionResult <TResult>(string actionName, Func <WebBaseElement, TResult> action,
                                          Func <TResult, string> logResult = null, LogLevels level = LogLevels.Info)
 {
     return(ExceptionUtils.ActionWithException(() =>
     {
         ProcessDemoMode();
         return ActionScenrios.SetElement(_element).ResultScenario(actionName, action, logResult, level);
     }, ex => $"Failed to do '{actionName}' action. Reason: {ex}"));
 }
Esempio n. 3
0
 public void IsOpened()
 {
     ExceptionUtils.ActionWithException(() =>
     {
         Logger.Info($"Page {Name} is opened");
         if (GetUrl().Equals(Url))
         {
             return;
         }
         Open();
     }, ex => $"Can't open page {Name}. Reason: {ex}");
 }
Esempio n. 4
0
        public static By FillByTemplate(this By by, params object[] args)
        {
            var byLocator = by.GetByLocator();

            if (!byLocator.Contains("{0}"))
            {
                throw new Exception(GetBadLocatorMsg(byLocator, args));
            }
            byLocator = ExceptionUtils.ActionWithException(
                () => Format(byLocator, args),
                ex => GetBadLocatorMsg(byLocator, args));
            return(by.GetByFunc().Invoke(byLocator));
        }
Esempio n. 5
0
        public TResult ResultScenario <TResult>(string actionName, Func <TResult> action, Func <TResult, string> logResult, LogLevels level)
        {
            _element.LogAction(actionName);
            var timer  = new Timer();
            var result =
                ExceptionUtils.ActionWithException(() => new Timer(JDISettings.Timeouts.CurrentTimeoutSec)
                                                   .GetResultByCondition(action.Invoke, res => true),
                                                   ex => $"Do action {actionName} failed. Can't got result. Reason: {ex}");

            if (result == null)
            {
                throw JDISettings.Exception("Do action %s failed. Can't got result", actionName);
            }
            var stringResult = logResult == null
                    ? result.ToString()
                    : logResult.Invoke(result);

            var timePassed = timer.TimePassed.TotalMilliseconds;

            PerformanceStatistic.AddStatistic(timer.TimePassed.TotalMilliseconds);
            JDISettings.ToLog($"Get result '{stringResult}' in {(timePassed / 1000).ToString("F")} seconds", level);
            return(result);
        }