import {expectAssignable, expectError, expectType} from "tsd"; import { Element, ElementAssertions, ElementValue, Elements, ScopedElement, ScopedElementRect, ValueAssertions } from ".."; import { WebElement, WebElementPromise } from "selenium-webdriver"; describe('new element() api', function () { test('test element()', async function () { const elem = browser.element('selector'); expectType(elem); expectType(await elem); // accepts WebElement expectType(browser.element(await elem)); // accepts By selector expectType(browser.element(by.xpath('//tagname'))); // accepts RelativeBy selector expectType(browser.element(locateWith(by.css('selector')).above(await elem))); // accepts ElementProperties expectType(browser.element({selector: 'selector', locateStrategy: 'css selector', abortOnFailure: false})); // accepts ElementProperties with Appium-specific locate strategies expectType(browser.element({selector: 'selector', locateStrategy: '-android uiautomator', abortOnFailure: false})); // accepts Element (ScopedElement is also assignable to Element) expectType(browser.element(elem)); // accepts WebElementPromise expectType(browser.element(elem.webElement)); // accepts Promise expectType(browser.element(Promise.resolve(await elem))); // backward compatibility expectType(browser.element('css selector', 'selector', function (result) { expectType(result); })); }); test('test element.methodName()', async function () { const elementActive = browser.element.findActive(); expectType(elementActive); expectType(await elementActive); const elementFind = browser.element.find('selector'); expectType(elementFind); expectType(await elementFind); expectType(browser.element.get('selector')); expectType(browser.element.findElement('selector')); const elementFindByText = browser.element.findByText('some-text', {exact: true, abortOnFailure: false}); expectType(elementFindByText); const elementFindByRole = browser.element.findByRole('heading', {level: 2, expanded: true, retryInterval: 100}); expectType(elementFindByRole); browser.element.findByRole('button', {current: false, expanded: true, index: 2}); expectError(browser.element.findByRole('button', {level: 2, expanded: true, retryInterval: 100})); const elementFindByPlaceholderText = browser.element.findByPlaceholderText('some-text', {exact: true, abortOnFailure: false}); expectType(elementFindByPlaceholderText); const elementFindByLabelText = browser.element.findByLabelText('some-text', {exact: true, abortOnFailure: false}); expectType(elementFindByLabelText); const elementFindByAltText = browser.element.findByAltText('some-text', {exact: false, abortOnFailure: false}); expectType(elementFindByAltText); // findAll const elementFindAll = browser.element.findAll('selector'); expectType(elementFindAll); expectType(await elementFindAll); expectType(elementFindAll.nth(2)); expectType(await elementFindAll.count()); expectType(browser.element.getAll('selector')); expectType(browser.element.findElements('selector')); const elementFindAllByText = browser.element.findAllByText('some-text', {exact: true, abortOnFailure: false}); expectType(elementFindAllByText); const elementFindAllByRole = browser.element.findAllByRole('heading', {level: 2, expanded: true, retryInterval: 100}); expectType(elementFindAllByRole); browser.element.findAllByRole('button', {current: false, expanded: true, index: 2}); expectError(browser.element.findAllByRole('button', {level: 2, expanded: true, retryInterval: 100})); const elementFindAllByPlaceholderText = browser.element.findAllByPlaceholderText('some-text', {exact: true, abortOnFailure: false}); expectType(elementFindAllByPlaceholderText); const elementFindAllByAltText = browser.element.findAllByAltText('some-text', {exact: false, abortOnFailure: false}); expectType(elementFindAllByAltText); }); test('test ScopedElement has Element class properties', async function () { const elem = browser.element('selector'); expectType(elem); expectAssignable(elem); expectAssignable(await elem); expectType(elem.selector); expectType(elem.index); expectType(elem.resolvedElement); }); test('test properties/methods in ScopedElement', async function () { const elem = browser.element('selector'); expectType(elem); expectType(elem.webElement); expectType(elem.find('selector')); expectType(elem.get('selector')); expectType(elem.findElement('selector')); expectType(elem.findByText('some-text', {exact: true, abortOnFailure: false})); expectType(elem.findByRole('heading', {level: 2, expanded: true, retryInterval: 100})); expectType(elem.findByRole('button', {current: false, expanded: true, index: 2})); expectError(elem.findByRole('button', {level: 2, expanded: true, retryInterval: 100})); expectType(elem.findByPlaceholderText('some-text', {exact: true, abortOnFailure: false})); expectType(elem.findByLabelText('some-text', {exact: true, abortOnFailure: false})); expectType(elem.findByAltText('some-text', {exact: true, abortOnFailure: false})); expectType(elem.findAll('selector')); expectType(elem.findElements('selector')); expectType(elem.getAll('selector')); expectType(elem.findAllByText('some-text', {exact: true, abortOnFailure: false})); expectType(elem.findAllByRole('heading', {level: 2, expanded: true, retryInterval: 100})); expectType(elem.findAllByRole('button', {current: false, expanded: true, index: 2})); expectError(elem.findAllByRole('button', {level: 2, expanded: true, retryInterval: 100})); expectType(elem.findAllByPlaceholderText('some-text', {exact: true, abortOnFailure: false})); expectType(elem.findAllByAltText('some-text', {exact: true, abortOnFailure: false})); expectType(elem.getFirstElementChild()); expectType(elem.getLastElementChild()); expectType(elem.getNextElementSibling()); expectType(elem.getPreviousElementSibling()); expectType & PromiseLike>(elem.getShadowRoot()); expectType(await elem.getShadowRoot()); expectType>(elem.getId()); expectType>(elem.getTagName()); expectType>(elem.tagName()); expectType>(elem.getText()); expectType>(elem.text()); expectType>(elem.getProperty('property-name')); expectType>(elem.prop('property-name')); expectType>(elem.property('property-name')); expectType>(elem.getAttribute('attrib-name')); expectType>(elem.attr('attrib-name')); expectType>(elem.attribute('attrib-name')); expectType>(elem.getValue()); expectType>(elem.isEnabled()); expectType>(elem.isPresent()); expectType>(elem.isSelected()); expectType>(elem.isVisible()); expectType>(elem.isDisplayed()); expectType>(elem.isActive()); expectType>(elem.getRect()); expectType>(elem.rect()); expectType>(elem.getSize()); expectType>(elem.getLocation()); expectType>(elem.getAccessibleName()); expectType>(elem.accessibleName()); expectType>(elem.getComputedLabel()); expectType>(elem.getAriaRole()); expectType>(elem.ariaRole()); expectType>(elem.getComputedRole()); expectType>(elem.getCssProperty('height')); expectType>(elem.css('height')); expectType>(elem.getCssValue('height')); expectType>(elem.takeScreenshot()); expectType>(elem.click()); expectType>(elem.clear()); expectType>(elem.check()); expectType>(elem.uncheck()); expectType>(elem.sendKeys('something', 1)); expectType>(elem.update('something', 1)); expectType>(elem.setValue('something', 1)); expectType>(elem.submit()); expectType>(elem.setProperty('type', 'text')); expectType>(elem.setAttribute('role', 'button')); expectType>(elem.dragAndDrop({x: 150, y: 500})); expectType>(elem.dragAndDrop(elem.webElement)); expectType>(elem.moveTo(100, 100)); expectType>(elem.clickAndHold()); expectType>(elem.doubleClick()); expectType>(elem.rightClick()); expectType>(elem.waitUntil('visible', {timeout: 5000})); }); test('test element assertions', async function () { const elem = browser.element('selector'); expectType(elem); expectType(elem.assert) expectType(elem.assert.not); expectType>(elem.assert.enabled('some message')); expectType(await elem.assert.not.enabled()); expectType>(elem.assert.not.present()); expectType(await elem.assert.selected('some message')); expectType>(elem.assert.not.selected('some message')); expectType(await elem.assert.selected()); expectType>(elem.assert.visible()); expectType(await elem.assert.not.visible('some message')); expectType>(elem.assert.not.hasClass('some-class')); expectType(await elem.assert.hasClass('some-class', 'some message')); expectType>(elem.assert.hasAttribute('some-attribute', 'some message')); expectType(await elem.assert.not.hasAttribute('some-attribute')); expectType>(elem.assert.hasDescendants()); expectType(await elem.assert.not.hasDescendants('some message')); }); test('test ElementValue methods/properties', async function () { const elem = browser.element('selector'); expectType(elem); const elemId = elem.getId(); expectType>(elemId); expectType(await elemId); expectType>(elemId.value); expectType(await elemId.value); expectType>(elemId.assert); expectType>(elemId.assert.equals('elem-id')); }); test('test ValueAssertions methods/properties', async function () { const elem = browser.element('selector'); expectType(elem); const elemId = elem.getId(); expectType>(elemId.assert); expectType>(elemId.assert.not); expectType>(elemId.assert.equals('some text')); expectType(await elemId.assert.not.equals('some text', 'some message')); expectType>(elemId.assert.not.contains('text', 'some message')); expectType(await elemId.assert.contains('some')); expectType>(elemId.assert.matches(/^some text/, 'some message')); expectType(await elemId.assert.not.matches(/some t[a-z]{3}$/)); }); });