Skip to content

Commit

Permalink
Add .text() as alias for .getText() (#4180)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayush-Vish authored Apr 17, 2024
1 parent b7275e9 commit e159472
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
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'],
'getAriaRole': ['ariaRole'],
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

0 comments on commit e159472

Please sign in to comment.