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 .attr() and .attribute() as an alias for .getAttribute() command. #4172

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

Filter by extension

Filter by extension

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

it('test .element.find().attr()', async function() {
garg3133 marked this conversation as resolved.
Show resolved Hide resolved
MockServer.addMock({
url: '/session/13521-10219-202/execute/sync',
method: 'POST',
response: JSON.stringify({
value: 'text'
})
}, true);

const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').attr('type');
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, 'text');

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

it('test .element().find().attribute()', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/execute/sync',
method: 'POST',
response: JSON.stringify({
value: 'text'
})
}, true);

const resultPromise = this.client.api.element('#signupSection').find('#helpBtn').attribute('type');
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, 'text');

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

it('test .element().find().getAttribute()', async function() {
MockServer.addMock({
url: '/session/13521-10219-202/execute/sync',
Expand Down Expand Up @@ -109,5 +157,6 @@ describe('element().getAttribute() command', function () {
assert.strictEqual(await resultPromise.assert.not.equals('texxt'), 'text');
assert.strictEqual(await resultPromise.assert.not.contains('texx'), 'text');
assert.strictEqual(await resultPromise.assert.not.matches(/te[a-z]{2}x/), 'text');
});
});

garg3133 marked this conversation as resolved.
Show resolved Hide resolved
});
2 changes: 2 additions & 0 deletions types/tests/webElement.test-d.ts
Expand Up @@ -139,6 +139,8 @@ describe('new element() api', function () {

expectType<ElementValue<string | null>>(elem.getProperty('property-name'));
expectType<ElementValue<string | null>>(elem.getAttribute('attrib-name'));
expectType<ElementValue<string | null>>(elem.attr('attrib-name'));
expectType<ElementValue<string | null>>(elem.attribute('attrib-name'));
expectType<ElementValue<string | null>>(elem.getValue());
expectType<ElementValue<boolean>>(elem.isEnabled());
expectType<ElementValue<boolean>>(elem.isVisible());
Expand Down
2 changes: 2 additions & 0 deletions types/web-element.d.ts
Expand Up @@ -162,6 +162,8 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
setProperty(name: string, value: unknown): Promise<WebElement>;

getAttribute(name: string): ElementValue<string | null>;
attr(name: string): ElementValue<string | null>;
attribute(name: string): ElementValue<string | null>;

setAttribute(name: string, value: string | null): Promise<WebElement>;

Expand Down