Esempio n. 1
0
        /// <summary>
        /// Expects the specified selector and conditions match a specified number of fields.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void Of(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name = "ExpectCount",
                    Arguments = new Dictionary<string, dynamic>()
                    {
                        { "selector", fieldSelector },
                        { "matchConditions", conditions.ToString() },
                        { "value", _count }
                    }
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var elements = Provider.GetElements(fieldSelector, conditions);

                    if (elements.Count() != _count)
                    {
                        Provider.TakeAssertExceptionScreenshot();
                        throw new AssertException("Count assertion failed. Expected there to be [{0}] elements matching [{1}]. Actual count is [{2}]", _count, fieldSelector, elements.Count());
                    }
                });
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Expects the specified selector and conditions match a specified number of fields.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void Of(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name      = "ExpectCount",
                    Arguments = new Dictionary <string, dynamic>()
                    {
                        { "selector", fieldSelector },
                        { "matchConditions", conditions.ToString() },
                        { "value", _count }
                    }
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var elements = Provider.GetElements(fieldSelector, conditions);

                    if (elements.Count() != _count)
                    {
                        Provider.TakeAssertExceptionScreenshot();
                        throw new AssertException("Count assertion failed. Expected there to be [{0}] elements matching [{1}]. Actual count is [{2}]", _count, fieldSelector, elements.Count());
                    }
                });
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Sets the value in the specified field.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void In(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name      = "Enter",
                    Arguments = new Dictionary <string, dynamic>()
                    {
                        { "selector", fieldSelector },
                        { "matchConditions", conditions.ToString() },
                        { "value", _value }
                    }
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var field = Provider.GetTextElement(fieldSelector, conditions);

                    if (_quickEntry)
                    {
                        field.SetValueQuickly(_value);
                    }
                    else
                    {
                        field.SetValue(_value);
                    }
                });
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Expects the specified field has a specific class.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void On(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name = "ExpectClass",
                    Arguments = new Dictionary<string, dynamic>()
                    {
                        { "selector", fieldSelector },
                        { "value", _value },
                        { "matchConditions", conditions.ToString() }
                    }
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var element = Provider.GetElement(fieldSelector, conditions);
                    string className = _value.Replace(".", "").Trim();
                    string elementClassName = element.GetAttributeValue("class").Trim();

                    if (elementClassName.Contains(' '))
                    {
                        string[] classes = elementClassName.Split(' ');
                        bool hasMatches = false;
                        foreach (var cssClass in classes)
                        {
                            var cssClassString = cssClass.Trim();
                            if (!string.IsNullOrEmpty(cssClassString))
                            {
                                if (cssClassString.Equals(className))
                                {
                                    hasMatches = true;
                                }
                            }
                        }

                        if (!hasMatches)
                        {
                            Provider.TakeAssertExceptionScreenshot();
                            throw new AssertException("Class name assertion failed. Expected element [{0}] to include a CSS class of [{1}].", fieldSelector, className);
                        }
                    }
                    else
                    {
                        if (!elementClassName.Equals(className))
                        {
                            Provider.TakeAssertExceptionScreenshot();
                            throw new AssertException("Class name assertion failed. Expected element [{0}] to include a CSS class of [{1}] but current CSS class is [{2}].", fieldSelector, className, elementClassName.PrettifyErrorValue());
                        }
                    }
                });
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Expects the specified field has a specific class.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void On(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name      = "ExpectClass",
                    Arguments = new Dictionary <string, dynamic>()
                    {
                        { "selector", fieldSelector },
                        { "value", _value },
                        { "matchConditions", conditions.ToString() }
                    }
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var element             = Provider.GetElement(fieldSelector, conditions);
                    string className        = _value.Replace(".", "").Trim();
                    string elementClassName = element.GetAttributeValue("class").Trim();

                    if (elementClassName.Contains(' '))
                    {
                        string[] classes = elementClassName.Split(' ');
                        bool hasMatches  = false;
                        foreach (var cssClass in classes)
                        {
                            var cssClassString = cssClass.Trim();
                            if (!string.IsNullOrEmpty(cssClassString))
                            {
                                if (cssClassString.Equals(className))
                                {
                                    hasMatches = true;
                                }
                            }
                        }

                        if (!hasMatches)
                        {
                            Provider.TakeAssertExceptionScreenshot();
                            throw new AssertException("Class name assertion failed. Expected element [{0}] to include a CSS class of [{1}].", fieldSelector, className);
                        }
                    }
                    else
                    {
                        if (!elementClassName.Equals(className))
                        {
                            Provider.TakeAssertExceptionScreenshot();
                            throw new AssertException("Class name assertion failed. Expected element [{0}] to include a CSS class of [{1}] but current CSS class is [{2}].", fieldSelector, className, elementClassName.PrettifyErrorValue());
                        }
                    }
                });
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Hovers over the specified element selector that matches the conditions.
 /// </summary>
 /// <param name="elementSelector">The element selector.</param>
 /// <param name="conditions">The conditions.</param>
 public void Hover(string elementSelector, MatchConditions conditions)
 {
     if (this.EnableRemoteExecution)
     {
         this.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
         {
             Name      = "Hover",
             Arguments = new Dictionary <string, dynamic>()
             {
                 { "selector", elementSelector },
                 { "matchConditions", conditions.ToString() }
             }
         });
     }
     else
     {
         CurrentActionBucket.Add(() =>
         {
             var field = Provider.GetElement(elementSelector, conditions);
             field.Hover();
         });
     }
 }
Esempio n. 7
0
 /// <summary>
 /// Uploads the specified file name.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="fieldSelector">The field selector.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="conditions">The conditions.</param>
 protected void Upload(string fileName, string fieldSelector, API.Point offset, MatchConditions conditions)
 {
     if (this.EnableRemoteExecution)
     {
         this.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
         {
             Name      = "Upload",
             Arguments = new Dictionary <string, dynamic>()
             {
                 { "selector", fieldSelector },
                 { "fileName", fileName },
                 { "offset", string.Format("{0},{1}", offset.X, offset.Y) },
                 { "matchConditions", conditions.ToString() }
             }
         });
     }
     else
     {
         CurrentActionBucket.Add(() =>
         {
             Provider.Upload(fileName, fieldSelector, offset, conditions);
         });
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Expects that the specified field's text matches.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void In(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                // args
                var arguments = new Dictionary<string, dynamic>();
                arguments.Add("selector", fieldSelector);
                arguments.Add("value", _expectedText);
                arguments.Add("matchConditions", conditions.ToString());
                if (_expectedTextExpression != null) arguments.Add("valueExpression", _expectedTextExpression.ToExpressionString());

                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name = "ExpectText",
                    Arguments = arguments
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var element = Provider.GetElement(fieldSelector, conditions);
                    var elementText = element.GetText() ?? string.Empty;

                    if (element != null)
                    {
                        if (element.IsSelect())
                        {
                            var selectElement = Provider.GetSelectElement(fieldSelector, conditions);
                            if (_expectType == ExpectType.Single)
                            {
                                if (selectElement.IsMultiple)
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Single value assertion cannot be used on a SelectList that potentially has multiple values. Use Any or All instead.");
                                }

                                if (_expectedTextFunc != null)
                                {
                                    if (!_expectedTextFunc(selectElement.GetSelectedOptionText()))
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement text assertion failed. Expected element [{0}] to match expression [{1}]. Actual text is [{2}].", fieldSelector, _expectedTextExpression.ToExpressionString(), selectElement.GetSelectedOptionText().PrettifyErrorValue());
                                    }
                                }
                                else
                                {
                                    if (!selectElement.GetSelectedOptionText().Equals(_expectedText, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement text assertion failed. Expected element [{0}] to have selected text of [{1}] but actual selected text is [{2}].", fieldSelector, _expectedText.PrettifyErrorValue(), selectElement.GetSelectedOptionText().PrettifyErrorValue());
                                    }
                                }
                            }
                            else
                            {
                                int textMatching = 0;
                                string[] selectedText = selectElement.GetSelectedOptionsText();

                                if (selectedText.Length > 0)
                                {
                                    foreach (string text in _expectedStrings)
                                    {
                                        bool isMatch = selectedText.Any(s => s.Equals(text, StringComparison.InvariantCultureIgnoreCase));
                                        if (isMatch) textMatching++;
                                    }

                                    if (_expectType == ExpectType.Any)
                                    {
                                        if (textMatching == 0)
                                        {
                                            Provider.TakeAssertExceptionScreenshot();
                                            throw new AssertException("SelectElement text assertion failed. Expected element [{0}] to have at least one option with text matching the following options: [{1}]", fieldSelector, string.Join(", ", _expectedStrings));
                                        }
                                    }
                                    else if (_expectType == ExpectType.All)
                                    {
                                        if (textMatching != _expectedStrings.Count())
                                        {
                                            Provider.TakeAssertExceptionScreenshot();
                                            throw new AssertException("SelectElement text assertion failed. Expected element [{0}] to include option text matching all the following options: [{1}]", fieldSelector, string.Join(", ", _expectedStrings));
                                        }
                                    }
                                }
                            }
                        }
                        else if (element.IsText())
                        {
                            var textElement = Provider.GetTextElement(fieldSelector, conditions);
                            var textElementText = textElement.GetText() ?? string.Empty;

                            if (_expectedTextFunc != null)
                            {
                                if (!_expectedTextFunc(textElementText))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("TextElement text assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _expectedTextExpression.ToExpressionString(), textElementText.PrettifyErrorValue());
                                }
                            }
                            else
                            {
                                if (!textElementText.Equals(_expectedText ?? string.Empty, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("TextElement text assertion failed. Expected element [{0}] to have a value of [{1}] but actual value is [{2}].", fieldSelector, _expectedText.PrettifyErrorValue(), textElementText.PrettifyErrorValue());
                                }
                            }
                        }
                        else
                        {
                            if (_expectedTextFunc != null)
                            {
                                if (!_expectedTextFunc(elementText))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Value assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _expectedTextExpression.ToExpressionString(), elementText.PrettifyErrorValue());
                                }
                            }
                            else
                            {
                                if (!elementText.Equals(_expectedText ?? string.Empty))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Value assertion failed. Expected element [{0}] to have a value of [{1}] but actual value is [{2}].", fieldSelector, _expectedText.PrettifyErrorValue(), elementText.PrettifyErrorValue());
                                }
                            }
                        }
                    }
                });
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Expects that the specified field's value matches.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void In(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                // args
                var arguments = new Dictionary<string, dynamic>();
                arguments.Add("selector", fieldSelector);
                arguments.Add("value", _value);
                arguments.Add("matchConditions", conditions.ToString());
                if (_valueExpression != null) arguments.Add("valueExpression", _valueExpression.ToExpressionString());

                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name = "ExpectText",
                    Arguments = arguments
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var element = Provider.GetElement(fieldSelector, conditions);
                    var elementValue = element.GetValue() ?? string.Empty;

                    if (element != null)
                    {
                        if (_value == null && element.GetText() != null && elementValue != string.Empty)
                        {
                            Provider.TakeAssertExceptionScreenshot();
                            throw new AssertException("Null value assertion failed. Element [{0}] has a value of [{1}].", fieldSelector, element.GetText().PrettifyErrorValue());
                        }

                        if (!element.IsSelect() && (_expectType == ExpectType.Any || _expectType == ExpectType.All))
                        {
                            Provider.TakeAssertExceptionScreenshot();
                            throw new AssertException("Value assertion of types Any and All can only be used on SelectList elements.");
                        }
                        else if (element.IsSelect())
                        {
                            var selectElement = Provider.GetSelectElement(fieldSelector, conditions);
                            if (_expectType == ExpectType.Single)
                            {
                                if (selectElement.IsMultiple)
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Single value assertion cannot be used on a SelectList that potentially has multiple values. Use Any or All instead.");
                                }

                                if (_valueFunc != null)
                                {
                                    if (!_valueFunc(selectElement.GetValue()))
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement value assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _valueExpression.ToExpressionString(), selectElement.GetValue().PrettifyErrorValue());
                                    }
                                }
                                else
                                {
                                    if (!selectElement.GetValue().Equals(_value, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement value assertion failed. Expected element [{0}] to have a selected value of [{1}] but actual selected value is [{2}].", fieldSelector, _value.PrettifyErrorValue(), selectElement.GetValue().PrettifyErrorValue());
                                    }
                                }
                            }
                            else
                            {
                                int valuesMatching = 0;
                                string[] selectedValues = selectElement.GetValues();

                                if (selectedValues.Length > 0)
                                {
                                    foreach (var selectedValue in selectedValues)
                                    {
                                        foreach (var value in _values)
                                        {
                                            if ((_valueFunc != null && !_valueFunc(selectedValue)) ||
                                                (selectedValue.Equals(value, StringComparison.InvariantCultureIgnoreCase)))
                                            {
                                                valuesMatching++;
                                            }
                                        }
                                    }
                                }

                                if (_expectType == ExpectType.Any)
                                {
                                    if (valuesMatching == 0)
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement value assertion failed. Expected element [{0}] to have at least one of the following values: [{1}]", fieldSelector, string.Join(", ", _values));
                                    }
                                }
                                else if (_expectType == ExpectType.All)
                                {
                                    if (valuesMatching < _values.Count())
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement value assertion failed. Expected element [{0}] to include all of the following values: [{1}]", fieldSelector, string.Join(", ", _values));
                                    }
                                }
                            }
                        }
                        else if (element.IsText())
                        {
                            var textElement = Provider.GetTextElement(fieldSelector, conditions);
                            var textElementValue = textElement.GetValue() ?? string.Empty;
                            if (_valueFunc != null)
                            {
                                if (!_valueFunc(textElementValue))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("TextElement value assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _valueExpression.ToExpressionString(), textElementValue.PrettifyErrorValue());
                                }
                            }
                            else
                            {
                                if (!textElementValue.Equals(_value ?? string.Empty, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("TextElement value assertion failed. Expected element [{0}] to have a value of [{1}] but actual value is [{2}].", fieldSelector, _value.PrettifyErrorValue(), textElementValue.PrettifyErrorValue());
                                }
                            }
                        }
                        else
                        {
                            if (_valueFunc != null)
                            {
                                if (!_valueFunc(elementValue))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Value assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _valueExpression.ToExpressionString(), elementValue.PrettifyErrorValue());
                                }
                            }
                            else
                            {
                                if (!elementValue.Equals(_value ?? string.Empty))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Value assertion failed. Expected element [{0}] to have a value of [{1}] but actual value is [{2}].", fieldSelector, _value.PrettifyErrorValue(), elementValue.PrettifyErrorValue());
                                }
                            }
                        }
                    }
                });
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Expects that the specified field's value matches.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void In(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                // args
                var arguments = new Dictionary <string, dynamic>();
                arguments.Add("selector", fieldSelector);
                arguments.Add("value", _value);
                arguments.Add("matchConditions", conditions.ToString());
                if (_valueExpression != null)
                {
                    arguments.Add("valueExpression", _valueExpression.ToExpressionString());
                }

                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name      = "ExpectText",
                    Arguments = arguments
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var element      = Provider.GetElement(fieldSelector, conditions);
                    var elementValue = element.GetValue() ?? string.Empty;

                    if (element != null)
                    {
                        if (_value == null && element.GetText() != null && elementValue != string.Empty)
                        {
                            Provider.TakeAssertExceptionScreenshot();
                            throw new AssertException("Null value assertion failed. Element [{0}] has a value of [{1}].", fieldSelector, element.GetText().PrettifyErrorValue());
                        }

                        if (!element.IsSelect() && (_expectType == ExpectType.Any || _expectType == ExpectType.All))
                        {
                            Provider.TakeAssertExceptionScreenshot();
                            throw new AssertException("Value assertion of types Any and All can only be used on SelectList elements.");
                        }
                        else if (element.IsSelect())
                        {
                            var selectElement = Provider.GetSelectElement(fieldSelector, conditions);
                            if (_expectType == ExpectType.Single)
                            {
                                if (selectElement.IsMultiple)
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Single value assertion cannot be used on a SelectList that potentially has multiple values. Use Any or All instead.");
                                }

                                if (_valueFunc != null)
                                {
                                    if (!_valueFunc(selectElement.GetValue()))
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement value assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _valueExpression.ToExpressionString(), selectElement.GetValue().PrettifyErrorValue());
                                    }
                                }
                                else
                                {
                                    if (!selectElement.GetValue().Equals(_value, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement value assertion failed. Expected element [{0}] to have a selected value of [{1}] but actual selected value is [{2}].", fieldSelector, _value.PrettifyErrorValue(), selectElement.GetValue().PrettifyErrorValue());
                                    }
                                }
                            }
                            else
                            {
                                int valuesMatching      = 0;
                                string[] selectedValues = selectElement.GetValues();

                                if (selectedValues.Length > 0)
                                {
                                    foreach (var selectedValue in selectedValues)
                                    {
                                        foreach (var value in _values)
                                        {
                                            if ((_valueFunc != null && !_valueFunc(selectedValue)) ||
                                                (selectedValue.Equals(value, StringComparison.InvariantCultureIgnoreCase)))
                                            {
                                                valuesMatching++;
                                            }
                                        }
                                    }
                                }

                                if (_expectType == ExpectType.Any)
                                {
                                    if (valuesMatching == 0)
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement value assertion failed. Expected element [{0}] to have at least one of the following values: [{1}]", fieldSelector, string.Join(", ", _values));
                                    }
                                }
                                else if (_expectType == ExpectType.All)
                                {
                                    if (valuesMatching < _values.Count())
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement value assertion failed. Expected element [{0}] to include all of the following values: [{1}]", fieldSelector, string.Join(", ", _values));
                                    }
                                }
                            }
                        }
                        else if (element.IsText())
                        {
                            var textElement      = Provider.GetTextElement(fieldSelector, conditions);
                            var textElementValue = textElement.GetValue() ?? string.Empty;
                            if (_valueFunc != null)
                            {
                                if (!_valueFunc(textElementValue))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("TextElement value assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _valueExpression.ToExpressionString(), textElementValue.PrettifyErrorValue());
                                }
                            }
                            else
                            {
                                if (!textElementValue.Equals(_value ?? string.Empty, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("TextElement value assertion failed. Expected element [{0}] to have a value of [{1}] but actual value is [{2}].", fieldSelector, _value.PrettifyErrorValue(), textElementValue.PrettifyErrorValue());
                                }
                            }
                        }
                        else
                        {
                            if (_valueFunc != null)
                            {
                                if (!_valueFunc(elementValue))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Value assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _valueExpression.ToExpressionString(), elementValue.PrettifyErrorValue());
                                }
                            }
                            else
                            {
                                if (!elementValue.Equals(_value ?? string.Empty))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Value assertion failed. Expected element [{0}] to have a value of [{1}] but actual value is [{2}].", fieldSelector, _value.PrettifyErrorValue(), elementValue.PrettifyErrorValue());
                                }
                            }
                        }
                    }
                });
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Expects that the specified field's text matches.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void In(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                // args
                var arguments = new Dictionary <string, dynamic>();
                arguments.Add("selector", fieldSelector);
                arguments.Add("value", _expectedText);
                arguments.Add("matchConditions", conditions.ToString());
                if (_expectedTextExpression != null)
                {
                    arguments.Add("valueExpression", _expectedTextExpression.ToExpressionString());
                }

                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name      = "ExpectText",
                    Arguments = arguments
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var element     = Provider.GetElement(fieldSelector, conditions);
                    var elementText = element.GetText() ?? string.Empty;

                    if (element != null)
                    {
                        if (element.IsSelect())
                        {
                            var selectElement = Provider.GetSelectElement(fieldSelector, conditions);
                            if (_expectType == ExpectType.Single)
                            {
                                if (selectElement.IsMultiple)
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Single value assertion cannot be used on a SelectList that potentially has multiple values. Use Any or All instead.");
                                }

                                if (_expectedTextFunc != null)
                                {
                                    if (!_expectedTextFunc(selectElement.GetSelectedOptionText()))
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement text assertion failed. Expected element [{0}] to match expression [{1}]. Actual text is [{2}].", fieldSelector, _expectedTextExpression.ToExpressionString(), selectElement.GetSelectedOptionText().PrettifyErrorValue());
                                    }
                                }
                                else
                                {
                                    if (!selectElement.GetSelectedOptionText().Equals(_expectedText, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        Provider.TakeAssertExceptionScreenshot();
                                        throw new AssertException("SelectElement text assertion failed. Expected element [{0}] to have selected text of [{1}] but actual selected text is [{2}].", fieldSelector, _expectedText.PrettifyErrorValue(), selectElement.GetSelectedOptionText().PrettifyErrorValue());
                                    }
                                }
                            }
                            else
                            {
                                int textMatching      = 0;
                                string[] selectedText = selectElement.GetSelectedOptionsText();

                                if (selectedText.Length > 0)
                                {
                                    foreach (string text in _expectedStrings)
                                    {
                                        bool isMatch = selectedText.Any(s => s.Equals(text, StringComparison.InvariantCultureIgnoreCase));
                                        if (isMatch)
                                        {
                                            textMatching++;
                                        }
                                    }

                                    if (_expectType == ExpectType.Any)
                                    {
                                        if (textMatching == 0)
                                        {
                                            Provider.TakeAssertExceptionScreenshot();
                                            throw new AssertException("SelectElement text assertion failed. Expected element [{0}] to have at least one option with text matching the following options: [{1}]", fieldSelector, string.Join(", ", _expectedStrings));
                                        }
                                    }
                                    else if (_expectType == ExpectType.All)
                                    {
                                        if (textMatching != _expectedStrings.Count())
                                        {
                                            Provider.TakeAssertExceptionScreenshot();
                                            throw new AssertException("SelectElement text assertion failed. Expected element [{0}] to include option text matching all the following options: [{1}]", fieldSelector, string.Join(", ", _expectedStrings));
                                        }
                                    }
                                }
                            }
                        }
                        else if (element.IsText())
                        {
                            var textElement     = Provider.GetTextElement(fieldSelector, conditions);
                            var textElementText = textElement.GetText() ?? string.Empty;

                            if (_expectedTextFunc != null)
                            {
                                if (!_expectedTextFunc(textElementText))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("TextElement text assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _expectedTextExpression.ToExpressionString(), textElementText.PrettifyErrorValue());
                                }
                            }
                            else
                            {
                                if (!textElementText.Equals(_expectedText ?? string.Empty, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("TextElement text assertion failed. Expected element [{0}] to have a value of [{1}] but actual value is [{2}].", fieldSelector, _expectedText.PrettifyErrorValue(), textElementText.PrettifyErrorValue());
                                }
                            }
                        }
                        else
                        {
                            if (_expectedTextFunc != null)
                            {
                                if (!_expectedTextFunc(elementText))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Value assertion failed. Expected element [{0}] to match expression [{1}]. Actual value is [{2}].", fieldSelector, _expectedTextExpression.ToExpressionString(), elementText.PrettifyErrorValue());
                                }
                            }
                            else
                            {
                                if (!elementText.Equals(_expectedText ?? string.Empty))
                                {
                                    Provider.TakeAssertExceptionScreenshot();
                                    throw new AssertException("Value assertion failed. Expected element [{0}] to have a value of [{1}] but actual value is [{2}].", fieldSelector, _expectedText.PrettifyErrorValue(), elementText.PrettifyErrorValue());
                                }
                            }
                        }
                    }
                });
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Selects values/text/indices from the specified field selector.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void From(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                // args
                var arguments = new Dictionary<string, dynamic>();
                arguments.Add("selector", fieldSelector);
                arguments.Add("selectMode", _selectMode.ToString());
                arguments.Add("matchConditions", conditions.ToString());
                if (_values != null) arguments.Add("values", _values);
                if (_optionMatchingFunc != null) arguments.Add("valueExpression", _optionMatchingFunc.ToExpressionString());
                if (_selectedIndices != null) arguments.Add("indices", _selectedIndices);

                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name = "Select",
                    Arguments = arguments
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var field = Provider.GetSelectElement(fieldSelector, conditions);
                    field.ClearSelectedItems();

                    if (_selectMode == SelectMode.Value || _selectMode == SelectMode.Text)
                    {
                        if (_optionMatchingFunc == null)
                        {
                            if (_values.Length == 1)
                            {
                                field.SetValue(_values.First(), _selectMode);
                            }
                            else if (_values.Length > 1)
                            {
                                field.SetValues(_values, _selectMode);
                            }
                        }
                        else
                        {
                            field.SetValues(_optionMatchingFunc, _selectMode);
                        }
                    }
                    else if (_selectMode == SelectMode.Index)
                    {
                        if (_selectedIndices.Length == 1)
                        {
                            field.SetSelectedIndex(_selectedIndices.First());
                        }
                        else if (_selectedIndices.Length > 1)
                        {
                            field.SetSelectedIndices(_selectedIndices);
                        }
                    }
                });
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Uploads the specified file name.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="fieldSelector">The field selector.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="conditions">The conditions.</param>
 protected void Upload(string fileName, string fieldSelector, API.Point offset, MatchConditions conditions)
 {
     if (this.EnableRemoteExecution)
     {
         this.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
         {
             Name = "Upload",
             Arguments = new Dictionary<string, dynamic>()
             {
                 { "selector", fieldSelector },
                 { "fileName", fileName },
                 { "offset", string.Format("{0},{1}", offset.X, offset.Y) },
                 { "matchConditions", conditions.ToString() }
             }
         });
     }
     else
     {
         CurrentActionBucket.Add(() =>
         {
             Provider.Upload(fileName, fieldSelector, offset, conditions);
         });
     }
 }
Esempio n. 14
0
 /// <summary>
 /// Hovers over the specified element selector that matches the conditions.
 /// </summary>
 /// <param name="elementSelector">The element selector.</param>
 /// <param name="conditions">The conditions.</param>
 public void Hover(string elementSelector, MatchConditions conditions)
 {
     if (this.EnableRemoteExecution)
     {
         this.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
         {
             Name = "Hover",
             Arguments = new Dictionary<string, dynamic>()
             {
                 { "selector", elementSelector },
                 { "matchConditions", conditions.ToString() }
             }
         });
     }
     else
     {
         CurrentActionBucket.Add(() =>
         {
             var field = Provider.GetElement(elementSelector, conditions);
             field.Hover();
         });
     }
 }
Esempio n. 15
0
        /// <summary>
        /// Selects values/text/indices from the specified field selector.
        /// </summary>
        /// <param name="fieldSelector">The field selector.</param>
        /// <param name="conditions">The conditions.</param>
        public void From(string fieldSelector, MatchConditions conditions)
        {
            if (CommandManager.EnableRemoteExecution)
            {
                // args
                var arguments = new Dictionary <string, dynamic>();
                arguments.Add("selector", fieldSelector);
                arguments.Add("selectMode", _selectMode.ToString());
                arguments.Add("matchConditions", conditions.ToString());
                if (_values != null)
                {
                    arguments.Add("values", _values);
                }
                if (_optionMatchingFunc != null)
                {
                    arguments.Add("valueExpression", _optionMatchingFunc.ToExpressionString());
                }
                if (_selectedIndices != null)
                {
                    arguments.Add("indices", _selectedIndices);
                }

                CommandManager.RemoteCommands.Add(new RemoteCommands.RemoteCommandDetails()
                {
                    Name      = "Select",
                    Arguments = arguments
                });
            }
            else
            {
                CommandManager.CurrentActionBucket.Add(() =>
                {
                    var field = Provider.GetSelectElement(fieldSelector, conditions);
                    field.ClearSelectedItems();

                    if (_selectMode == SelectMode.Value || _selectMode == SelectMode.Text)
                    {
                        if (_optionMatchingFunc == null)
                        {
                            if (_values.Length == 1)
                            {
                                field.SetValue(_values.First(), _selectMode);
                            }
                            else if (_values.Length > 1)
                            {
                                field.SetValues(_values, _selectMode);
                            }
                        }
                        else
                        {
                            field.SetValues(_optionMatchingFunc, _selectMode);
                        }
                    }
                    else if (_selectMode == SelectMode.Index)
                    {
                        if (_selectedIndices.Length == 1)
                        {
                            field.SetSelectedIndex(_selectedIndices.First());
                        }
                        else if (_selectedIndices.Length > 1)
                        {
                            field.SetSelectedIndices(_selectedIndices);
                        }
                    }
                });
            }
        }