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