blob: 6d63e9fda8295c57b5073083acd787c13bae89cb [file] [log] [blame]
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +03001import Chainable = Cypress.Chainable;
2
3declare namespace Cypress {
4 interface Chainable {
5 isElementContainsAttr : typeof isElementContainsAttr;
6 isElementDisabled : typeof isElementDisabled;
7 isElementEnabled : typeof isElementEnabled;
8 hasClass : typeof hasClass;
9 getElementByDataTestsId : typeof getElementByDataTestsId;
Ittay Stern6f900cc2018-08-29 17:01:32 +030010 getTagElementContainsText : typeof getTagElementContainsText;
Ittay Sternf7926712019-07-07 19:23:03 +030011 isElementNotContainsAttr : typeof isElementNotContainsAttr;
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030012 }
13}
14
15/*************************************************************************
16 isElementContainsAttr : check if element with id contains some attribute
17 *************************************************************************/
18function isElementContainsAttr(id : string, attr: string) : void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030019 cy.getElementByDataTestsId(id).should('have.attr', attr);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030020}
21
Ittay Sternf7926712019-07-07 19:23:03 +030022/*************************************************************************
23 isElementContainsAttr : check if element with id not contains some attribute
24 *************************************************************************/
25function isElementNotContainsAttr(id : string, attr: string) : void {
26 cy.getElementByDataTestsId(id).should('not.have.attr', attr);
27}
28
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030029/*********************************************************
30 isElementDisabled : check if element with id is disabled
31 *********************************************************/
32function isElementDisabled(id : string) : void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030033 cy.getElementByDataTestsId(id).should('be:disabled');
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030034}
35
36function isElementEnabled(id : string) : void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030037 cy.getElementByDataTestsId(id).should('be:enabled');
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030038}
39
40/****************************************************************
41 hasClass : check if element with id contains some class name
42 ****************************************************************/
43function hasClass(id : string, className : string) : void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030044 cy.getElementByDataTestsId(id).should('have.class', className);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030045}
46
47function getElementByDataTestsId(dataTestsId : string) : Chainable<JQuery<HTMLElement>> {
48 return cy.get( "[data-tests-id='" + dataTestsId +"']");
49}
50
Ittay Stern6f900cc2018-08-29 17:01:32 +030051/**************************************************
52 getTagElementContainsText : return tag with text
53 **************************************************/
54function getTagElementContainsText(tag : string, text : string) : Chainable<JQuery<HTMLElement>> {
55 return cy.contains(tag,text);
56}
57
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030058
59Cypress.Commands.add('isElementContainsAttr', isElementContainsAttr);
60Cypress.Commands.add('isElementDisabled', isElementDisabled);
61Cypress.Commands.add('isElementEnabled', isElementEnabled);
62Cypress.Commands.add('hasClass', hasClass);
63Cypress.Commands.add('getElementByDataTestsId', getElementByDataTestsId);
Ittay Stern6f900cc2018-08-29 17:01:32 +030064Cypress.Commands.add('getTagElementContainsText', getTagElementContainsText);
Ittay Sternf7926712019-07-07 19:23:03 +030065Cypress.Commands.add('isElementNotContainsAttr', isElementNotContainsAttr);