Skip to content

Commit

Permalink
Add .tagname() as alias for .getTagName(). (#4176)
Browse files Browse the repository at this point in the history

Co-authored-by: Priyansh Garg <priyanshgarg30@gmail.com>
  • Loading branch information
Ayush-Vish and garg3133 committed Apr 18, 2024
1 parent 88ba6c6 commit 526fa26
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 @@ -25,6 +25,7 @@ class ScopedWebElement {
'getRect': ['getSize', 'getLocation', 'rect'],
'getProperty': ['property', 'prop'],
'getText': ['text'],
'getTagName': ['tagName'],
'getAccessibleName': ['accessibleName'],
'getCssProperty': ['css'],
'getAriaRole': ['ariaRole'],
Expand Down
25 changes: 25 additions & 0 deletions test/src/api/commands/web-element/testGetTagName.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ describe('element().getTagName() command', function () {
assert.strictEqual(resultValue, 'div');
});

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

const resultPromise = this.client.api.element('#signupSection').tagName();
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, 'div');

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

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

});
1 change: 1 addition & 0 deletions types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ describe('new element() api', function () {

expectType<ElementValue<string>>(elem.getId());
expectType<ElementValue<string>>(elem.getTagName());
expectType<ElementValue<string>>(elem.tagName());
expectType<ElementValue<string>>(elem.getText());
expectType<ElementValue<string>>(elem.text());

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> {
getLocation(): ElementValue<ScopedElementRect>;

getTagName(): ElementValue<string>;
tagName(): ElementValue<string>;

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

0 comments on commit 526fa26

Please sign in to comment.