blob: 44e85830cbdc6e33d24a3a31c4f528a510619069 [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;
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030011 }
12}
13
14/*************************************************************************
15 isElementContainsAttr : check if element with id contains some attribute
16 *************************************************************************/
17function isElementContainsAttr(id : string, attr: string) : void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030018 cy.getElementByDataTestsId(id).should('have.attr', attr);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030019}
20
21/*********************************************************
22 isElementDisabled : check if element with id is disabled
23 *********************************************************/
24function isElementDisabled(id : string) : void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030025 cy.getElementByDataTestsId(id).should('be:disabled');
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030026}
27
28function isElementEnabled(id : string) : void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030029 cy.getElementByDataTestsId(id).should('be:enabled');
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030030}
31
32/****************************************************************
33 hasClass : check if element with id contains some class name
34 ****************************************************************/
35function hasClass(id : string, className : string) : void {
Ittay Stern6f900cc2018-08-29 17:01:32 +030036 cy.getElementByDataTestsId(id).should('have.class', className);
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030037}
38
39function getElementByDataTestsId(dataTestsId : string) : Chainable<JQuery<HTMLElement>> {
40 return cy.get( "[data-tests-id='" + dataTestsId +"']");
41}
42
Ittay Stern6f900cc2018-08-29 17:01:32 +030043/**************************************************
44 getTagElementContainsText : return tag with text
45 **************************************************/
46function getTagElementContainsText(tag : string, text : string) : Chainable<JQuery<HTMLElement>> {
47 return cy.contains(tag,text);
48}
49
Sonsino, Ofir (os0695)ff76b5e2018-07-10 15:57:37 +030050
51Cypress.Commands.add('isElementContainsAttr', isElementContainsAttr);
52Cypress.Commands.add('isElementDisabled', isElementDisabled);
53Cypress.Commands.add('isElementEnabled', isElementEnabled);
54Cypress.Commands.add('hasClass', hasClass);
55Cypress.Commands.add('getElementByDataTestsId', getElementByDataTestsId);
Ittay Stern6f900cc2018-08-29 17:01:32 +030056Cypress.Commands.add('getTagElementContainsText', getTagElementContainsText);