Skip to content

Commit

Permalink
Merge pull request #14 from Exabyte-io/chore/SOF-7208
Browse files Browse the repository at this point in the history
SOF-7208: change input clean logic
  • Loading branch information
k0stik authored May 30, 2024
2 parents 896c704 + 79cb1df commit e6c33f5
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions src/js/cypress/Browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ export class Browser extends BaseBrowser {
return input.type(value.toString(), options);
}

setInputNumberValue(
selector: string,
value: string | number,
clear = true,
options: Partial<Cypress.TypeOptions> = {},
) {
const input = this.get(selector);

if (clear) {
return input.focus().type("{selectall}").type(value.toString(), options);
}

return input.type(value.toString(), options);
}

setInputValueByXpath(
selector: string,
value: string | number,
Expand Down Expand Up @@ -195,7 +210,7 @@ export class Browser extends BaseBrowser {
}

isVisible(selector: string) {
return this.get(selector).then(($el): boolean => $el.is(":visible"));
return this.get(selector).then(($el) => Cypress.dom.isVisible($el));
}

isSelected(selector: string) {
Expand Down Expand Up @@ -300,6 +315,22 @@ export class Browser extends BaseBrowser {
return this.xpath(selector).should("be.visible");
}

wait(timeout: number) {
return cy.wait(timeout);
}

back() {
cy.go("back");
}

reload(force = false) {
cy.reload(force);
}

replaceElementAttribute(selector: string, attribute: string, value: string) {
this.get(selector).invoke("attr", attribute, value);
}

// ======= Assertions ========

assertWithRetry(cb: () => Cypress.Chainable<boolean>, options?: RetryOptions) {
Expand Down Expand Up @@ -327,8 +358,12 @@ export class Browser extends BaseBrowser {
});
}

assertInputValueWithRetry(selector: string, text: string) {
this.get(selector).should("have.value", text);
assertInputValueWithRetry(
selector: string,
text: string,
comparison: "have" | "include" = "have",
) {
this.get(selector).should(`${comparison}.value`, text);
}

assertTextByRegExpWithRetry(selector: string, regExp: RegExp) {
Expand Down Expand Up @@ -361,6 +396,29 @@ export class Browser extends BaseBrowser {
this.get(selector).should("have.length", length);
}

assertElementHasClassWithRetry(selector: string, className: string) {
this.get(selector).should("have.class", className);
}

assertInputValueNotEmptyWithRetry(selector: string) {
this.getInputValue(selector).should("not.be.empty");
}

assertAttributeIncludeValueWithRetry(selector: string, attribute: string, value: string) {
this.get(selector).invoke("attr", attribute).should("contain", value);
}

assertAttributeMatchWithRetry(
selector: string,
attribute: string,
regexp: RegExp,
timeout: BrowserTimeout = "md",
) {
this.getWithTimeout(selector, timeout)
.invoke({ timeout: this.getTimeoutTime(timeout) }, "attr", attribute)
.should("match", regexp);
}

// ======= End assertions ========

// ======= Getters ========
Expand Down

0 comments on commit e6c33f5

Please sign in to comment.