-
Notifications
You must be signed in to change notification settings - Fork 593
/
selectors.ts
87 lines (75 loc) · 2.91 KB
/
selectors.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* eslint-disable @typescript-eslint/no-use-before-define */
import Loggable = Cypress.Loggable;
import Timeoutable = Cypress.Timeoutable;
import Withinable = Cypress.Withinable;
import Shadow = Cypress.Shadow;
export {};
declare global {
namespace Cypress {
interface Chainable {
byTestID(
selector: string,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<Element>;
byTestActionID(selector: string): Chainable<JQuery<HTMLElement>>;
byLegacyTestID(
selector: string,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
byButtonText(selector: string): Chainable<JQuery<HTMLElement>>;
byDataID(selector: string): Chainable<JQuery<HTMLElement>>;
byTestSelector(
selector: string,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
byTestDropDownMenu(selector: string): Chainable<JQuery<HTMLElement>>;
byTestOperatorRow(
selector: string,
options?: Partial<Loggable & Timeoutable & Withinable & Shadow>,
): Chainable<JQuery<HTMLElement>>;
byTestSectionHeading(selector: string): Chainable<JQuery<HTMLElement>>;
byTestOperandLink(selector: string): Chainable<JQuery<HTMLElement>>;
}
}
}
// any command added below, must be added to global Cypress interface above
Cypress.Commands.add(
'byTestID',
(selector: string, options?: Partial<Loggable & Timeoutable & Withinable & Shadow>) => {
cy.get(`[data-test="${selector}"]`, options);
},
);
Cypress.Commands.add('byTestActionID', (selector: string) =>
cy.get(`[data-test-action="${selector}"]:not([disabled])`),
);
// deprecated! new IDs should use 'data-test', ie. `cy.byTestID(...)`
Cypress.Commands.add(
'byLegacyTestID',
(selector: string, options?: Partial<Loggable & Timeoutable & Withinable & Shadow>) => {
cy.get(`[data-test-id="${selector}"]`, options);
},
);
Cypress.Commands.add('byButtonText', (selector: string) => {
cy.get('button[type="button"]').contains(`${selector}`);
});
Cypress.Commands.add('byDataID', (selector: string) => {
cy.get(`[data-id="${selector}"]`);
});
Cypress.Commands.add(
'byTestSelector',
(selector: string, options?: Partial<Loggable & Timeoutable & Withinable & Shadow>) => {
cy.get(`[data-test-selector="${selector}"]`, options);
},
);
Cypress.Commands.add('byTestDropDownMenu', (selector: string) => {
cy.get(`[data-test-dropdown-menu="${selector}"]`);
});
Cypress.Commands.add('byTestOperatorRow', (selector: string, options?: object) => {
cy.get(`[data-test-operator-row="${selector}"]`, options);
});
Cypress.Commands.add('byTestSectionHeading', (selector: string) => {
cy.get(`[data-test-section-heading="${selector}"]`);
});
Cypress.Commands.add('byTestOperandLink', (selector: string) => {
cy.get(`[data-test-operand-link="${selector}"]`);
});