Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Added text as an alias for getText #4180

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class ScopedWebElement {
'findAllByPlaceholderText': ['getAllByPlaceholderText'],
'findAllByAltText': ['getAllByAltText'],
'getRect': ['getSize', 'getLocation', 'rect'],
'getText': ['text'],
'getProperty': ['property'],
'getCssProperty': ['css'],
'isVisible': ['isDisplayed']
Expand Down
25 changes: 25 additions & 0 deletions test/src/api/commands/web-element/testGetText.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ describe('element().getText() command', function () {
assert.strictEqual(resultValue, 'Signup');
});

it('test .element().text() alias', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/0/text',
method: 'GET',
response: JSON.stringify({
value: 'Signup'
})
}, true);

const resultPromise = this.client.api.element('#signupSection').text();
assert.strictEqual(resultPromise instanceof Element, false);
assert.strictEqual(typeof resultPromise.find, 'undefined');

assert.strictEqual(resultPromise instanceof Promise, false);
assert.strictEqual(typeof resultPromise.then, 'function');

const result = await resultPromise;
assert.strictEqual(result instanceof WebElement, false);
assert.strictEqual(result, 'Signup');

const resultValue = await resultPromise.value;
assert.strictEqual(resultValue, 'Signup');
});

it('test .element().find().getText()', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/element/1/text',
Expand Down Expand Up @@ -110,4 +134,5 @@ describe('element().getText() command', function () {
assert.strictEqual(await resultPromise.assert.not.contains('Signupx'), 'Signup');
assert.strictEqual(await resultPromise.assert.not.matches(/Si[a-z]{2}upx/), 'Signup');
});

});
1 change: 1 addition & 0 deletions types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ describe('new element() api', function () {
expectType<ElementValue<string>>(elem.getId());
expectType<ElementValue<string>>(elem.getTagName());
expectType<ElementValue<string>>(elem.getText());
expectType<ElementValue<string>>(elem.text());

expectType<ElementValue<string | null>>(elem.getProperty('property-name'));
expectType<ElementValue<string | null>>(elem.getAttribute('attrib-name'));
Expand Down
1 change: 1 addition & 0 deletions types/web-element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
getTagName(): ElementValue<string>;

getText(): ElementValue<string>;
text(): ElementValue<string>;

click(): Promise<WebElement>;

Expand Down
Loading