Behaviors

Change the way how particular actions are executed.

There are different action behavior types that can be replaced with Atata predefined attributes or custom ones. Shortly, you can customize how to execute actions like click, hover, focus, set value, get value, etc. The default behaviors are fine for majority of cases, but sometimes we can face specific components on web sites, and need to apply different approaches (behaviors) to perform certain actions.

In order to apply a needed behavior to a certain control, just apply an appropriate attribute as any other Atata multi-cast attribute.

[ClicksUsingScript]
public Button<_> Save { get; private set; }

Custom Behavior

In order to create a custom implementation of a specific behavior, create a new class inherited for behavior’s base class and write a behavior implementation inside an overriden Execute method.

public class ClicksUsingCustomWayAttribute : ClickBehaviorAttribute
{
    public override void Execute<TOwner>(IUIComponent<TOwner> component)
    {
        // TODO: Write an implementation.
    }
}

ClickBehaviorAttribute - the base behavior class for control click implementation. Responsible for the Control<TOwner>.Click() method action.

Implementations

  • default ClicksUsingClickMethodAttribute - the behavior for control clicking by IWebElement.Click() method.
  • ClicksUsingActionsAttribute - the behavior for control clicking by using a set of actions: Actions.MoveToElement(IWebElement) or Actions.MoveToElement(IWebElement, int, int) and Actions.Click().
  • ClicksUsingScriptAttribute - the behavior for control clicking by executing HTMLElement.click() JavaScript method.
  • ClicksOnCellByIndexAttribute - the behavior for control clicking by actually clicking the nth <td> cell. There is a sense to apply this behavior to classes inherited from TableRow<TOwner>.

DoubleClickBehaviorAttribute - the base behavior class for control double-click implementation. Responsible for the Control<TOwner>.DoubleClick() method action.

Implementations

  • default DoubleClicksUsingActionsAttribute - the behavior for control double-clicking by using a set of actions: Actions.MoveToElement(IWebElement) or Actions.MoveToElement(IWebElement, int, int) and Actions.DoubleClick().
  • DoubleClicksUsingScriptAttribute - the behavior for control double-clicking by executing HTMLElement.dispatchEvent(new Event('dblclick')) JavaScript.

RightClickBehaviorAttribute - the base behavior class for control right-click implementation. Responsible for the Control<TOwner>.RightClick() method action.

Implementations

  • default RightClicksUsingActionsAttribute - the behavior for control right-clicking by using a set of actions: Actions.MoveToElement(IWebElement) or Actions.MoveToElement(IWebElement, int, int) and then Actions.ContextClick().
  • RightClicksUsingScriptAttribute - the behavior for control right-clicking by executing HTMLElement.dispatchEvent(new Event('contextmenu')) JavaScript.

HoverBehaviorAttribute - the base behavior class for control hover implementation. Responsible for the method action.

Implementations

  • default HoversUsingActionsAttribute - the behavior for control hovering by using one of actions: Actions.MoveToElement(IWebElement) or Actions.MoveToElement(IWebElement, int, int).

FocusBehaviorAttribute - the base behavior class for control focus implementation. Responsible for the Control<TOwner>.Focus method action.

Implementations

  • default FocusesUsingScriptAttribute - the behavior for control focusing by executing HTMLElement.focus() JavaScript.

BlurBehaviorAttribute - the base behavior class for control blur (removing focus) implementation. Responsible for the Control<TOwner>.Hover() method action.

Implementations

  • default BlursUsingScriptAttribute - the behavior for control blurring by executing HTMLElement.blur() JavaScript.

ScrollBehaviorAttribute - the base behavior class for scrolling to control. Responsible for the Control<TOwner>.ScrollTo() method action.

Implementations

  • default ScrollsUsingScrollToElementActionAttribute - the behavior for scrolling to control using WebDriver’s Actions.ScrollToElement(IWebElement) action.
  • ScrollsUsingMoveToElementActionAttribute - the behavior for scrolling to control using WebDriver’s Actions.MoveToElement(IWebElement) action.
  • ScrollsUsingScriptAttribute - the behavior for scrolling to control using JavaScript. Performs element.scrollIntoView() function.

DragAndDropBehaviorAttribute - Represents the base behavior class for control drag and drop implementation Responsible for the Control<TOwner>.DragAndDropTo(Control<TOwner>) and Control<TOwner>.DragAndDropTo(Func<TOwner, Control<TOwner>>) methods action.

Implementations

  • default DragsAndDropsUsingActionsAttribute - the behavior for drag and drop using WebDriver’s Actions. Performs Actions.DragAndDrop(IWebElement, IWebElement) action.
  • DragsAndDropsUsingDomEventsAttribute - the behavior for drag and drop using JavaScript. The script simulates drag and drop by dispatching DOM events: ‘dragstart’, ‘dragenter’, ‘dragover’, ‘drop’ and ‘dragend’.

DragAndDropToOffsetBehaviorAttribute - the base behavior class for control drag and drop to offset implementation. Responsible for the Control<TOwner>.DragAndDropToOffset(int, int) method action.

Implementations

  • default DragsAndDropsToOffsetUsingActionsAttribute - the behavior for control dragging and dropping to offset using WebDriver’s Actions. Performs Actions.DragAndDropToOffset(IWebElement, int, int) action.

ContentGetBehaviorAttribute - the base behavior class for getting the component’s content. Responsible for the UIComponent<TOwner>.Content property value getting.

Implementations

  • default GetsContentFromSourceAttribute - the behavior for component content getting from the specified source of ContentSource enumeration type. By default, ContentSource.Text is used.
  • GetsContentFromAttributeAttribute - the behavior for component content getting from HTML attribute by attribute name.

ValueGetBehaviorAttribute - the base behavior class for an implementation of the EditableTextField<TValue, TOwner> value getting.

Implementations

  • default GetsValueFromValueAttribute - the behavior for control value getting from value attribute.
  • GetsValueFromContentAttribute - the behavior for control value getting from IUIComponent<TOwner>.Content property.

ValueSetBehaviorAttribute - the base behavior class for an implementation of the EditableTextField<TValue, TOwner> value set.

Implementations

  • default SetsValueUsingClearAndTypeBehaviorsAttribute - the behavior for control value set by executing ValueClearBehaviorAttribute behavior first; then, if value to set is not null or empty, executes TextTypeBehaviorAttribute behavior.
  • SetsValueUsingScriptAttribute - the behavior for control value set by executing HTMLElement.value = '{value}'; HTMLElement.dispatchEvent(new Event('change')); JavaScript.
  • SetsValueUsingSendKeysAttribute - the behavior for control value set by IWebElement.SendKeys(string) method. IWebElement.SendKeys(string) method is invoked only when the value is not null or empty.
  • SetsValueUsingClearAndSendKeysAttribute - the behavior for control value set by invoking IWebElement.Clear() and IWebElement.SendKeys(string) methods. IWebElement.SendKeys(string) method is invoked only when the value is not null or empty.
  • SetsValueUsingCharByCharTypingAttribute - the behavior for control value set by clicking on the control element and then typing the text character by character with interval defined in TypingIntervalInSeconds property.

ValueClearBehaviorAttribute - the base behavior class for an implementation of control value clearing. Responsible for the EditableTextField<TValue, TOwner>.Clear() method action.

Implementations

  • default ClearsValueUsingClearMethodAttribute - the behavior for control value clearing by IWebElement.Clear() method.
  • ClearsValueUsingClearMethodOrScriptAttribute - the behavior for control value clearing by trying to executeIWebElement.Clear() method. If InvalidElementStateException occurs, then clears the value by executing HTMLElement.value = ''; HTMLElement.dispatchEvent(new Event('change')); JavaScript.
  • ClearsValueUsingScriptAttribute - the behavior for control value clearing by executing HTMLElement.value = ''; HTMLElement.dispatchEvent(new Event('change')); JavaScript.
  • ClearsValueUsingCtrlADeleteKeysAttribute - the behavior for control value clearing by performing “Ctrl+A, Delete” keyboard shortcut.
  • ClearsValueUsingHomeShiftEndDeleteKeysAttribute - the behavior for control value clearing by performing “Home, Shift+End, Delete” keyboard shortcut.
  • ClearsValueUsingShiftHomeDeleteKeysAttribute - the behavior for control value clearing by performing “Shift+Home, Delete” keyboard shortcut. Note that “End” key is not pressed in the beginning of the shortcut, as the caret on element by default goes to the end.

TextTypeBehaviorAttribute - the base behavior class for an implementation of control text typing. Responsible for the EditableTextField<TValue, TOwner>.Type(string) method action.

Implementations

  • default TypesTextUsingSendKeysAttribute - the behavior for control text typing by IWebElement.SendKeys(string) method. IWebElement.SendKeys(string) method is invoked only when the value is not null or empty.
  • TypesTextUsingSendKeysCharByCharAttribute - the behavior for control text typing by invoking IWebElement.SendKeys(string) method for character by character with interval defined in TypingIntervalInSeconds property.
  • TypesTextUsingFocusBehaviorAndSendKeysAttribute - the behavior for control text typing by executing FocusBehaviorAttribute behavior and then invoking IWebElement.SendKeys(string) method.
  • TypesTextUsingFocusBehaviorAndSendKeysCharByCharAttribute - the behavior for control text typing by executing FocusBehaviorAttribute behavior and then invoking IWebElement.SendKeys(string) method for character by character with interval defined in TypingIntervalInSeconds property.
  • TypesTextUsingScriptAttribute - the behavior for control text typing by executing HTMLElement.value += '{value}'; HTMLElement.dispatchEvent(new Event('change')); JavaScript.

SelectOptionBehaviorAttribute - the base behavior class for option selection of Select<TValue, TOwner> control.

Implementations

  • default SelectsOptionByTextAttribute - the behavior for option selection of Select<TValue, TOwner> control using option text.
  • SelectsOptionByValueAttribute - the behavior for option selection of Select<TValue, TOwner> control using option value attribute.
  • SelectsOptionByLabelAttributeAttribute - the behavior for option selection of Select<TValue, TOwner> control using option label attribute.
  • SelectsOptionByAttributeAttribute - the behavior for option selection of Select<TValue, TOwner> control using specified option attribute.