Skip to content

Commit

Permalink
Added isDisplayed() as alias to isVisible() (#4107)
Browse files Browse the repository at this point in the history
  • Loading branch information
uditrajput03 committed Mar 13, 2024
1 parent efeaa2e commit e97a90c
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class ScopedWebElement {
'findAllByAltText': ['getAllByAltText'],
'getRect': ['getSize', 'getLocation'],
'getProperty': ['property'],
'getCssProperty': ['css']
'getCssProperty': ['css'],
'isVisible': ['isDisplayed']
};
}

Expand Down
54 changes: 54 additions & 0 deletions test/src/api/commands/web-element/testIsVisible.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,33 @@ describe('element().isVisible() command', function() {
assert.strictEqual(elementId, '0');
});

it('test .element().isDisplayed() displayed', async function() {
let elementId;

MockServer.addMock({
url: '/session/13521-10219-202/execute/sync',
method: 'POST',
response: JSON.stringify({
value: true
}),
onRequest(_, requestData) {
elementId = requestData.args[0]['element-6066-11e4-a52e-4f735466cecf'];
}
}, true);

const resultPromise = this.client.api.element('#signupSection').isDisplayed();
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, true);
assert.strictEqual(elementId, '0');
});

it('test .element().isVisible() not displayed', async function() {
let elementId;

Expand Down Expand Up @@ -68,6 +95,33 @@ describe('element().isVisible() command', function() {
assert.strictEqual(elementId, '0');
});

it('test .element().isDisplayed() not displayed', async function() {
let elementId;

MockServer.addMock({
url: '/session/13521-10219-202/execute/sync',
method: 'POST',
response: JSON.stringify({
value: false
}),
onRequest(_, requestData) {
elementId = requestData.args[0]['element-6066-11e4-a52e-4f735466cecf'];
}
}, true);

const resultPromise = this.client.api.element('#signupSection').isDisplayed();
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, false);
assert.strictEqual(elementId, '0');
});

it('test .element().find().isVisible()', async function() {
let elementId;

Expand Down
1 change: 1 addition & 0 deletions types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ describe('new element() api', function () {
expectType<ElementValue<string | null>>(elem.getValue());
expectType<ElementValue<boolean>>(elem.isEnabled());
expectType<ElementValue<boolean>>(elem.isVisible());
expectType<ElementValue<boolean>>(elem.isDisplayed());

expectType<ElementValue<ScopedElementRect>>(elem.getRect());
expectType<ElementValue<ScopedElementRect>>(elem.getSize());
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 @@ -194,6 +194,7 @@ export interface ScopedElement extends Element, PromiseLike<WebElement> {
isEnabled(): ElementValue<boolean>;

isVisible(): ElementValue<boolean>;
isDisplayed(): ElementValue<boolean>;
}

type WaitUntilOptions = {
Expand Down

0 comments on commit e97a90c

Please sign in to comment.