Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 1 | import Chainable = Cypress.Chainable; |
| 2 | |
| 3 | declare 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 Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 10 | getTagElementContainsText : typeof getTagElementContainsText; |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 11 | isElementNotContainsAttr : typeof isElementNotContainsAttr; |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 12 | } |
| 13 | } |
| 14 | |
| 15 | /************************************************************************* |
| 16 | isElementContainsAttr : check if element with id contains some attribute |
| 17 | *************************************************************************/ |
| 18 | function isElementContainsAttr(id : string, attr: string) : void { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 19 | cy.getElementByDataTestsId(id).should('have.attr', attr); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 20 | } |
| 21 | |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 22 | /************************************************************************* |
| 23 | isElementContainsAttr : check if element with id not contains some attribute |
| 24 | *************************************************************************/ |
| 25 | function isElementNotContainsAttr(id : string, attr: string) : void { |
| 26 | cy.getElementByDataTestsId(id).should('not.have.attr', attr); |
| 27 | } |
| 28 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 29 | /********************************************************* |
| 30 | isElementDisabled : check if element with id is disabled |
| 31 | *********************************************************/ |
| 32 | function isElementDisabled(id : string) : void { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 33 | cy.getElementByDataTestsId(id).should('be:disabled'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | function isElementEnabled(id : string) : void { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 37 | cy.getElementByDataTestsId(id).should('be:enabled'); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /**************************************************************** |
| 41 | hasClass : check if element with id contains some class name |
| 42 | ****************************************************************/ |
| 43 | function hasClass(id : string, className : string) : void { |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 44 | cy.getElementByDataTestsId(id).should('have.class', className); |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | function getElementByDataTestsId(dataTestsId : string) : Chainable<JQuery<HTMLElement>> { |
| 48 | return cy.get( "[data-tests-id='" + dataTestsId +"']"); |
| 49 | } |
| 50 | |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 51 | /************************************************** |
| 52 | getTagElementContainsText : return tag with text |
| 53 | **************************************************/ |
| 54 | function getTagElementContainsText(tag : string, text : string) : Chainable<JQuery<HTMLElement>> { |
| 55 | return cy.contains(tag,text); |
| 56 | } |
| 57 | |
Sonsino, Ofir (os0695) | ff76b5e | 2018-07-10 15:57:37 +0300 | [diff] [blame] | 58 | |
| 59 | Cypress.Commands.add('isElementContainsAttr', isElementContainsAttr); |
| 60 | Cypress.Commands.add('isElementDisabled', isElementDisabled); |
| 61 | Cypress.Commands.add('isElementEnabled', isElementEnabled); |
| 62 | Cypress.Commands.add('hasClass', hasClass); |
| 63 | Cypress.Commands.add('getElementByDataTestsId', getElementByDataTestsId); |
Ittay Stern | 6f900cc | 2018-08-29 17:01:32 +0300 | [diff] [blame] | 64 | Cypress.Commands.add('getTagElementContainsText', getTagElementContainsText); |
Ittay Stern | f792671 | 2019-07-07 19:23:03 +0300 | [diff] [blame] | 65 | Cypress.Commands.add('isElementNotContainsAttr', isElementNotContainsAttr); |