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

Added isVisible Missing Command (Fixes #4037) #4065

Closed
Closed
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
30 changes: 30 additions & 0 deletions lib/api/web-element/commands/isVisible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Returns the visible text for the element.
*
* For more info on working with DOM elements in Nightwatch, refer to the <a href="https://nightwatchjs.org/guide/writing-tests/finding-interacting-with-dom-elements.html">Finding & interacting with DOM Elements</a> guide page.
*
* @example
* export default {
* demoTest(browser: NightwatchAPI): void {
* const result = browser.element('#main ul li a.first').isVisible();
* .assert.valueEquals('custom text');
* },
*
* async demoTestAsync(browser: NightwatchAPI): Promise<void> {
* const result = await browser.element('#main ul li a.first').isVisible();
* console.log('element text:', result);
* }
* }
Comment on lines +6 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're adding some example to JSDoc or anywhere else, it should be tested by you first by running them in one of the example test files. This example code won't work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alrighty ill take care of this in future

*
* @since 3.0.0
* @method isVisible
* @memberof ScopedWebElement
* @instance
* @syntax browser.element(selector).isVisible()
* @see https://www.w3.org/TR/webdriver#dfn-get-element-text
* @returns {ScopedValue<string>}
* @alias isDisplayed
Comment on lines +19 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be updated as well.

*/
module.exports.command = function() {
return this.runQueuedCommandScoped('isVisibleElement');
};
5 changes: 5 additions & 0 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,12 @@ module.exports = class MethodMappings {

return elementText;
},
async isVisibleElement(id) {
const element = await this.getWebElement(id);
const elementVisible = await element.isDisplayed();

return elementVisible;
},
Comment on lines +549 to +554
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to create this again, there's already a isElementDisplayed method which does the same.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh i didnt notice isElementDisplayed because i was taking reference from getText()

// the value param is compulsory
async getElementValue(webElementOrId, value) {
const element = this.getWebElement(webElementOrId);
Expand Down
2 changes: 2 additions & 0 deletions types/tests/webElement.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ describe('new element() api', function () {
expectType<ElementValue<string>>(elem.getTagName());
expectType<ElementValue<string>>(elem.getText());

expectType<ElementValue<boolean>>(elem.isVisible());

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

getText(): ElementValue<string>;

isVisible() : ElementValue<boolean>;

click(): Promise<WebElement>;

clear(): Promise<WebElement>;
Expand Down