Skip to content

Button

The BaseButton class simplifies button interactions in Cypress tests, offering clicking, assertion, and scrolling functionalities. These methods improve test maintainability and execution efficiency, ensuring a robust test framework

Class: Button

Click Actions

import { spartiUI } from "@spartify.io/spartify-engine";
spartiUI.button(this.btn_element).click();');

Methods & Usage

click(): void
Simulates a click action on the button.

@return void

SpartiUI.button(this.btn_element).click();

forceClick(): void
Forces a click action on the button, bypassing any potential blockers.

@return void

SpartiUI.button(this.btn_element).forceClick();

doubleClick(): void
Simulates a double-click action on the button.

@return void

SpartiUI.button(this.btn_element).doubleClick();

rightClick(): void
Simulates a right-click action on the button.

@return void

SpartiUI.button(this.btn_element).rightClick();

clickAt(x: number, y: number): void
Simulates a click action at the specified coordinates relative to the button.

@param x - The x-coordinate.
@param y - The y-coordinate.
@return void

SpartiUI.button(this.btn_element).clickAt(50, 30);

clickCenter(): void
Simulates a click action at the center of the button.

@return void

SpartiUI.button(this.btn_element).clickCenter();

clickAll(): void
Simulates a click action on all instances of the button.

@return void

SpartiUI.button(this.btn_elements).clickAll();

clickFirst(): void
Simulates a click action on the first instance of the button.

@return void

SpartiUI.button(this.btn_elements).clickFirst();

clickLast(): void
Simulates a click action on the last instance of the button.

@return void

SpartiUI.button(this.btn_elements).clickLast();

clickAndHold(): void
Simulates a click-and-hold action on the button.

@return void

SpartiUI.button(this.btn_element).clickAndHold();

clickByText(text: string): void
Simulates a click action on the button identified by the specified text.

@param text - the text to identify the button.
@return void

SpartiUI.button(this.btn_elements).clickByText('Save');

clickByIndex(index: number): void
Simulates a click action on the button identified by the specified index.

@param index - The index to identify the button.
@return void

SpartiUI.button(this.btn_elements).clickByIndex(2);

clickWithOffset(x: number, y: number): void
Simulates a click action on the button with an offset from its top-left corner.

@param x - The x-coordinate offset.
@param y - The y-coordinate offset.
@return void

SpartiUI.button(this.btn_element).clickWithOffset(10, 5);

focusAndClick(): void
Focuses on the button and then simulates a click action at the specified coordinates.

@param x - the x-coordinate.
@param y - the y-coordinate.
@return void

SpartiUI.button(this.btn_element).focusAndClick();

Assertions

assertText(text: string): void
Asserts that the button contains the specified text.

@param text - the expected text content of the button.
@return void

SpartiUI.button(this.btn_element).focusAndClick();

assertColor(color: string): void
Asserts that the button has the expected color.

@param color - the expected color of the button.
@return void

SpartiUI.button(this.btn_element).assertColor('rgb(0, 123, 255)');

assertCssProperty(property: string, value: string): void
Asserts that the button has the specified CSS property with the given value.

@param property - the CSS property to check.
@param value - the expected value of the CSS property.
@return void

SpartiUI.button(this.btn_element).assertCssProperty('font-size', '16px');

Scrolling Actions

scrollToElement(): void
Scrolls to the button element.

@return void

SpartiUI.button(this.btn_element.scrollToElement();