1 | import {expectAssignable, expectError, expectType} from "tsd";
|
2 | import { Element, ElementAssertions, ElementValue, Elements, ScopedElement, ScopedElementRect, ValueAssertions } from "..";
|
3 | import { WebElement, WebElementPromise } from "selenium-webdriver";
|
4 |
|
5 | describe('new element() api', function () {
|
6 | test('test element()', async function () {
|
7 | const elem = browser.element('selector');
|
8 | expectType<ScopedElement>(elem);
|
9 | expectType<WebElement>(await elem);
|
10 |
|
11 |
|
12 | expectType<ScopedElement>(browser.element(await elem));
|
13 |
|
14 |
|
15 | expectType<ScopedElement>(browser.element(by.xpath('//tagname')));
|
16 |
|
17 |
|
18 | expectType<ScopedElement>(browser.element(locateWith(by.css('selector')).above(await elem)));
|
19 |
|
20 |
|
21 | expectType<ScopedElement>(browser.element({selector: 'selector', locateStrategy: 'css selector', abortOnFailure: false}));
|
22 |
|
23 |
|
24 | expectType<ScopedElement>(browser.element(elem));
|
25 |
|
26 |
|
27 | expectType<ScopedElement>(browser.element(elem.webElement));
|
28 |
|
29 |
|
30 | expectType<ScopedElement>(browser.element(Promise.resolve(await elem)));
|
31 |
|
32 |
|
33 | expectType<ScopedElement>(browser.element('css selector', 'selector', function (result) {
|
34 | expectType<never>(result);
|
35 | }));
|
36 | });
|
37 |
|
38 | test('test element.methodName()', async function () {
|
39 | const elementActive = browser.element.findActive();
|
40 | expectType<ScopedElement>(elementActive);
|
41 | expectType<WebElement>(await elementActive);
|
42 |
|
43 | const elementFind = browser.element.find('selector');
|
44 | expectType<ScopedElement>(elementFind);
|
45 | expectType<WebElement>(await elementFind);
|
46 |
|
47 | expectType<ScopedElement>(browser.element.get('selector'));
|
48 | expectType<ScopedElement>(browser.element.findElement('selector'));
|
49 |
|
50 | const elementFindByText = browser.element.findByText('some-text', {exact: true, abortOnFailure: false});
|
51 | expectType<ScopedElement>(elementFindByText);
|
52 |
|
53 | const elementFindByRole = browser.element.findByRole('heading', {level: 2, expanded: true, retryInterval: 100});
|
54 | expectType<ScopedElement>(elementFindByRole);
|
55 | browser.element.findByRole('button', {current: false, expanded: true, index: 2});
|
56 | expectError(browser.element.findByRole('button', {level: 2, expanded: true, retryInterval: 100}));
|
57 |
|
58 | const elementFindByPlaceholderText = browser.element.findByPlaceholderText('some-text', {exact: true, abortOnFailure: false});
|
59 | expectType<ScopedElement>(elementFindByPlaceholderText);
|
60 |
|
61 | const elementFindByLabelText = browser.element.findByLabelText('some-text', {exact: true, abortOnFailure: false});
|
62 | expectType<ScopedElement>(elementFindByLabelText);
|
63 |
|
64 | const elementFindByAltText = browser.element.findByAltText('some-text', {exact: false, abortOnFailure: false});
|
65 | expectType<ScopedElement>(elementFindByAltText);
|
66 |
|
67 |
|
68 | const elementFindAll = browser.element.findAll('selector');
|
69 | expectType<Elements>(elementFindAll);
|
70 | expectType<WebElement[]>(await elementFindAll);
|
71 |
|
72 | expectType<ScopedElement>(elementFindAll.nth(2));
|
73 | expectType<number>(await elementFindAll.count());
|
74 |
|
75 | expectType<Elements>(browser.element.getAll('selector'));
|
76 | expectType<Elements>(browser.element.findElements('selector'));
|
77 |
|
78 | const elementFindAllByText = browser.element.findAllByText('some-text', {exact: true, abortOnFailure: false});
|
79 | expectType<Elements>(elementFindAllByText);
|
80 |
|
81 | const elementFindAllByRole = browser.element.findAllByRole('heading', {level: 2, expanded: true, retryInterval: 100});
|
82 | expectType<Elements>(elementFindAllByRole);
|
83 | browser.element.findAllByRole('button', {current: false, expanded: true, index: 2});
|
84 | expectError(browser.element.findAllByRole('button', {level: 2, expanded: true, retryInterval: 100}));
|
85 |
|
86 | const elementFindAllByPlaceholderText = browser.element.findAllByPlaceholderText('some-text', {exact: true, abortOnFailure: false});
|
87 | expectType<Elements>(elementFindAllByPlaceholderText);
|
88 |
|
89 | const elementFindAllByAltText = browser.element.findAllByAltText('some-text', {exact: false, abortOnFailure: false});
|
90 | expectType<Elements>(elementFindAllByAltText);
|
91 | });
|
92 |
|
93 | test('test ScopedElement has Element class properties', async function () {
|
94 | const elem = browser.element('selector');
|
95 | expectType<ScopedElement>(elem);
|
96 | expectAssignable<Element>(elem);
|
97 | expectAssignable<WebElement>(await elem);
|
98 |
|
99 | expectType<string | undefined>(elem.selector);
|
100 | expectType<number>(elem.index);
|
101 | expectType<string | null>(elem.resolvedElement);
|
102 | });
|
103 |
|
104 | test('test properties/methods in ScopedElement', async function () {
|
105 | const elem = browser.element('selector');
|
106 | expectType<ScopedElement>(elem);
|
107 |
|
108 | expectType<WebElementPromise>(elem.webElement);
|
109 |
|
110 | expectType<ScopedElement>(elem.find('selector'));
|
111 | expectType<ScopedElement>(elem.get('selector'));
|
112 | expectType<ScopedElement>(elem.findElement('selector'));
|
113 |
|
114 | expectType<ScopedElement>(elem.findByText('some-text', {exact: true, abortOnFailure: false}));
|
115 |
|
116 | expectType<ScopedElement>(elem.findByRole('heading', {level: 2, expanded: true, retryInterval: 100}));
|
117 | expectType<ScopedElement>(elem.findByRole('button', {current: false, expanded: true, index: 2}));
|
118 | expectError(elem.findByRole('button', {level: 2, expanded: true, retryInterval: 100}));
|
119 |
|
120 | expectType<ScopedElement>(elem.findByPlaceholderText('some-text', {exact: true, abortOnFailure: false}));
|
121 | expectType<ScopedElement>(elem.findByLabelText('some-text', {exact: true, abortOnFailure: false}));
|
122 | expectType<ScopedElement>(elem.findByAltText('some-text', {exact: true, abortOnFailure: false}));
|
123 |
|
124 | expectType<Elements>(elem.findAll('selector'));
|
125 | expectType<Elements>(elem.findElements('selector'));
|
126 | expectType<Elements>(elem.getAll('selector'));
|
127 |
|
128 | expectType<Elements>(elem.findAllByText('some-text', {exact: true, abortOnFailure: false}));
|
129 |
|
130 | expectType<Elements>(elem.findAllByRole('heading', {level: 2, expanded: true, retryInterval: 100}));
|
131 | expectType<Elements>(elem.findAllByRole('button', {current: false, expanded: true, index: 2}));
|
132 | expectError(elem.findAllByRole('button', {level: 2, expanded: true, retryInterval: 100}));
|
133 |
|
134 | expectType<Elements>(elem.findAllByPlaceholderText('some-text', {exact: true, abortOnFailure: false}));
|
135 | expectType<Elements>(elem.findAllByAltText('some-text', {exact: true, abortOnFailure: false}));
|
136 |
|
137 | expectType<ScopedElement>(elem.getFirstElementChild());
|
138 | expectType<ScopedElement>(elem.getLastElementChild());
|
139 | expectType<ScopedElement>(elem.getNextElementSibling());
|
140 | expectType<ScopedElement>(elem.getPreviousElementSibling());
|
141 |
|
142 | expectType<Omit<ScopedElement, 'then'> & PromiseLike<ShadowRoot>>(elem.getShadowRoot());
|
143 | expectType<ShadowRoot>(await elem.getShadowRoot());
|
144 |
|
145 | expectType<ElementValue<string>>(elem.getId());
|
146 | expectType<ElementValue<string>>(elem.getTagName());
|
147 | expectType<ElementValue<string>>(elem.tagName());
|
148 | expectType<ElementValue<string>>(elem.getText());
|
149 | expectType<ElementValue<string>>(elem.text());
|
150 |
|
151 | expectType<ElementValue<string | null>>(elem.getProperty('property-name'));
|
152 | expectType<ElementValue<string | null>>(elem.prop('property-name'));
|
153 | expectType<ElementValue<string | null>>(elem.property('property-name'));
|
154 | expectType<ElementValue<string | null>>(elem.getAttribute('attrib-name'));
|
155 | expectType<ElementValue<string | null>>(elem.attr('attrib-name'));
|
156 | expectType<ElementValue<string | null>>(elem.attribute('attrib-name'));
|
157 | expectType<ElementValue<string | null>>(elem.getValue());
|
158 | expectType<ElementValue<boolean>>(elem.isEnabled());
|
159 | expectType<ElementValue<boolean>>(elem.isVisible());
|
160 | expectType<ElementValue<boolean>>(elem.isDisplayed());
|
161 |
|
162 | expectType<ElementValue<ScopedElementRect>>(elem.getRect());
|
163 | expectType<ElementValue<ScopedElementRect>>(elem.rect());
|
164 | expectType<ElementValue<ScopedElementRect>>(elem.getSize());
|
165 | expectType<ElementValue<ScopedElementRect>>(elem.getLocation());
|
166 |
|
167 | expectType<ElementValue<string>>(elem.getAccessibleName());
|
168 | expectType<ElementValue<string>>(elem.accessibleName());
|
169 | expectType<ElementValue<string>>(elem.getAriaRole());
|
170 | expectType<ElementValue<string>>(elem.ariaRole());
|
171 | expectType<ElementValue<string>>(elem.getCssProperty('height'));
|
172 | expectType<ElementValue<string>>(elem.css('height'));
|
173 | expectType<ElementValue<string>>(elem.getCssValue('height'));
|
174 | expectType<ElementValue<string>>(elem.takeScreenshot());
|
175 |
|
176 | expectType<Promise<WebElement>>(elem.click());
|
177 | expectType<Promise<WebElement>>(elem.clear());
|
178 | expectType<Promise<WebElement>>(elem.sendKeys('something', 1));
|
179 | expectType<Promise<WebElement>>(elem.update('something', 1));
|
180 | expectType<Promise<WebElement>>(elem.setValue('something', 1));
|
181 | expectType<Promise<WebElement>>(elem.submit());
|
182 | expectType<Promise<WebElement>>(elem.setProperty('type', 'text'));
|
183 | expectType<Promise<WebElement>>(elem.setAttribute('role', 'button'));
|
184 | expectType<Promise<WebElement>>(elem.dragAndDrop({xOffset: 150, yOffset: 500}));
|
185 | expectType<Promise<WebElement>>(elem.moveTo(100, 100));
|
186 | expectType<Promise<WebElement>>(elem.clickAndHold());
|
187 | expectType<Promise<WebElement>>(elem.doubleClick());
|
188 | expectType<Promise<WebElement>>(elem.rightClick());
|
189 | expectType<Promise<WebElement>>(elem.waitUntil('visible', {timeout: 5000}));
|
190 | expectType<ElementValue<boolean>>(elem.isSelected());
|
191 | });
|
192 |
|
193 | test('test element assertions', async function () {
|
194 | const elem = browser.element('selector');
|
195 | expectType<ScopedElement>(elem);
|
196 | expectType<ElementAssertions>(elem.assert)
|
197 | expectType<ElementAssertions>(elem.assert.not);
|
198 |
|
199 | expectType<Promise<WebElement>>(elem.assert.enabled('some message'));
|
200 | expectType<WebElement>(await elem.assert.not.enabled());
|
201 |
|
202 | expectType<Promise<WebElement>>(elem.assert.not.present());
|
203 | expectType<WebElement>(await elem.assert.selected('some message'));
|
204 |
|
205 | expectType<Promise<WebElement>>(elem.assert.not.selected('some message'));
|
206 | expectType<WebElement>(await elem.assert.selected());
|
207 |
|
208 | expectType<Promise<WebElement>>(elem.assert.visible());
|
209 | expectType<WebElement>(await elem.assert.not.visible('some message'));
|
210 |
|
211 | expectType<Promise<WebElement>>(elem.assert.not.hasClass('some-class'));
|
212 | expectType<WebElement>(await elem.assert.hasClass('some-class', 'some message'));
|
213 |
|
214 | expectType<Promise<WebElement>>(elem.assert.hasAttribute('some-attribute', 'some message'));
|
215 | expectType<WebElement>(await elem.assert.not.hasAttribute('some-attribute'));
|
216 |
|
217 | expectType<Promise<WebElement>>(elem.assert.hasDescendants());
|
218 | expectType<WebElement>(await elem.assert.not.hasDescendants('some message'));
|
219 | });
|
220 |
|
221 | test('test ElementValue methods/properties', async function () {
|
222 | const elem = browser.element('selector');
|
223 | expectType<ScopedElement>(elem);
|
224 |
|
225 | const elemId = elem.getId();
|
226 | expectType<ElementValue<string>>(elemId);
|
227 | expectType<string>(await elemId);
|
228 |
|
229 | expectType<Promise<string>>(elemId.value);
|
230 | expectType<string>(await elemId.value);
|
231 |
|
232 | expectType<ValueAssertions<string>>(elemId.assert);
|
233 | expectType<Promise<string>>(elemId.assert.equals('elem-id'));
|
234 | });
|
235 |
|
236 | test('test ValueAssertions methods/properties', async function () {
|
237 | const elem = browser.element('selector');
|
238 | expectType<ScopedElement>(elem);
|
239 |
|
240 | const elemId = elem.getId();
|
241 | expectType<ValueAssertions<string>>(elemId.assert);
|
242 | expectType<ValueAssertions<string>>(elemId.assert.not);
|
243 |
|
244 | expectType<Promise<string>>(elemId.assert.equals('some text'));
|
245 | expectType<string>(await elemId.assert.not.equals('some text', 'some message'));
|
246 |
|
247 | expectType<Promise<string>>(elemId.assert.not.contains('text', 'some message'));
|
248 | expectType<string>(await elemId.assert.contains('some'));
|
249 |
|
250 | expectType<Promise<string>>(elemId.assert.matches(/^some text/, 'some message'));
|
251 | expectType<string>(await elemId.assert.not.matches(/some t[a-z]{3}$/));
|
252 | });
|
253 | });
|