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

[🐛 Bug]: <console log > #8280

Closed
3 tasks done
vijaychowthri opened this issue Apr 27, 2022 · 3 comments
Closed
3 tasks done

[🐛 Bug]: <console log > #8280

vijaychowthri opened this issue Apr 27, 2022 · 3 comments
Labels
Bug 🐛 Needs Triaging ⏳ No one has looked into the issue yet

Comments

@vijaychowthri
Copy link

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

latest

Node.js Version

12.18.3

Mode

Standalone Mode

Which capabilities are you using?

No response

What happened?

we have custom global functions that make sure the element status of all kinds such as ( isDisplayed, isClickable, isEnabled ) and then we are performing click and set text actions on browser.

this makes the console unreadable, too much javascript running on the console. is it possible to limit the console logs?

What is your expected behavior?

simple elegant console log

How to reproduce the bug.

run the re-usable functions

Relevant log output

C:\Program Files\nodejs\ecp_ui_automation\AUT-7436\ecp_ui_automation>npm run xyz

[0-0] 2022-04-27T18:52:41.439Z INFO webdriver: DATA {
[0-0]   script: 'return (function isElementDisplayed(element) {\n' +
[0-0]     '    function nodeIsElement(node) {\n' +
[0-0]     '        if (!node) {\n' +
[0-0]     '            return false;\n' +
[0-0]     '        }\n' +
[0-0]     '        switch (node.nodeType) {\n' +
[0-0]     '            case Node.ELEMENT_NODE:\n' +
[0-0]     '            case Node.DOCUMENT_NODE:\n' +
[0-0]     '            case Node.DOCUMENT_FRAGMENT_NODE:\n' +
[0-0]     '                return true;\n' +
[0-0]     '            default:\n' +
[0-0]     '                return false;\n' +
[0-0]     '        }\n' +
[0-0]     '    }\n' +
[0-0]     '    function parentElementForElement(element) {\n' +
[0-0]     '        if (!element) {\n' +
[0-0]     '            return null;\n' +
[0-0]     '        }\n' +
[0-0]     '        return enclosingNodeOrSelfMatchingPredicate(element.parentNode, nodeIsElement);\n' +
[0-0]     '    }\n' +
[0-0]     '    function enclosingNodeOrSelfMatchingPredicate(targetNode, predicate) {\n' +
[0-0]     '        for (let node = targetNode; node && node !== targetNode.ownerDocument; node = node.parentNode)\n' +
[0-0]     '            if (predicate(node)) {\n' +
[0-0]     '                return node;\n' +
[0-0]     '            }\n' +
[0-0]     '        return null;\n' +
[0-0]     '    }\n' +
[0-0]     '    function enclosingElementOrSelfMatchingPredicate(targetElement, predicate) {\n' +
[0-0]     '        for (let element = targetElement; element && element !== targetElement.ownerDocument; element = parentElementForElement(element))\n' +
[0-0]     '            if (predicate(element)) {\n' +
[0-0]     '                return element;\n' +
[0-0]     '            }\n' +
[0-0]     '        return null;\n' +
[0-0]     '    }\n' +
[0-0]     '    function cascadedStylePropertyForElement(element, property) {\n' +
[0-0]     '        if (!element || !property) {\n' +
[0-0]     '            return null;\n' +
[0-0]     '        }\n' +
[0-0]     '        // if document-fragment, skip it and use element.host instead. This happens\n' +
[0-0]     '        // when the element is inside a shadow root.\n' +
[0-0]     '        // window.getComputedStyle errors on document-fragment.\n' +
[0-0]     '        if (element instanceof DocumentFragment) {\n' +
[0-0]     '            element = element.host;\n' +
[0-0]     '        }\n' +
[0-0]     '        let computedStyle = window.getComputedStyle(element);\n' +
[0-0]     '        let computedStyleProperty = computedStyle.getPropertyValue(property);\n' +
[0-0]     "        if (computedStyleProperty && computedStyleProperty !== 'inherit') {\n" +
[0-0]     '            return computedStyleProperty;\n' +
[0-0]     '        }\n' +
[0-0]     "        // Ideally getPropertyValue would return the 'used' or 'actual' value, but\n" +
[0-0]     "        // it doesn't for legacy reasons. So we need to do our own poor man's cascade.\n" +
[0-0]     "        // Fall back to the first non-'inherit' value found in an ancestor.\n" +
[0-0]     "        // In any case, getPropertyValue will not return 'initial'.\n" +
[0-0]     '        // FIXME: will this incorrectly inherit non-inheritable CSS properties?\n' +
[0-0]     '        // I think all important non-inheritable properties (width, height, etc.)\n' +
[0-0]     '        // for our purposes here are specially resolved, so this may not be an issue.\n' +
[0-0]     '        // Specification is here: https://drafts.csswg.org/cssom/#resolved-values\n' +
[0-0]     '        let parentElement = parentElementForElement(element);\n' +
[0-0]     '        return cascadedStylePropertyForElement(parentElement, property);\n' +
[0-0]     '    }\n' +
[0-0]     '    function elementSubtreeHasNonZeroDimensions(element) {\n' +
[0-0]     '        let boundingBox = element.getBoundingClientRect();\n' +
[0-0]     '        if (boundingBox.width > 0 && boundingBox.height > 0) {\n' +
[0-0]     '            return true;\n' +
[0-0]     '        }\n' +
[0-0]     '        // Paths can have a zero width or height. Treat them as shown if the stroke width is positive.\n' +
[0-0]     "        if (element.tagName.toUpperCase() === 'PATH' && boundingBox.width + boundingBox.height > 0) {\n" +
[0-0]     "            let strokeWidth = cascadedStylePropertyForElement(element, 'stroke-width');\n" +
[0-0]     '            return !!strokeWidth && (parseInt(strokeWidth, 10) > 0);\n' +
[0-0]     '        }\n' +
[0-0]     "        let cascadedOverflow = cascadedStylePropertyForElement(element, 'overflow');\n" +
[0-0]     "        if (cascadedOverflow === 'hidden') {\n" +
[0-0]     '            return false;\n' +
[0-0]     '        }\n' +
[0-0]     "        // If the container's overflow is not hidden and it has zero size, consider the\n" +
[0-0]     '        // container to have non-zero dimensions if a child node has non-zero dimensions.\n' +
[0-0]     '        return Array.from(element.childNodes).some((childNode) => {\n' +
[0-0]     '            if (childNode.nodeType === Node.TEXT_NODE) {\n' +
[0-0]     '                return true;\n' +
[0-0]     '            }\n' +
[0-0]     '            if (nodeIsElement(childNode)) {\n' +
[0-0]     '                return elementSubtreeHasNonZeroDimensions(childNode);\n' +
[0-0]     '            }\n' +
[0-0]     '            return false;\n' +
[0-0]     '        });\n' +
[0-0]     '    }\n' +
[0-0]     '    function elementOverflowsContainer(element) {\n' +
[0-0]     "        let cascadedOverflow = cascadedStylePropertyForElement(element, 'overflow');\n" +
[0-0]     "        if (cascadedOverflow !== 'hidden') {\n" +
[0-0]     '            return false;\n' +
[0-0]     '        }\n' +
[0-0]     '        // FIXME: this needs to take into account the scroll position of the element,\n' +
[0-0]     '        // the display modes of it and its ancestors, and the container it overflows.\n' +
[0-0]     "        // See Selenium's bot.dom.getOverflowState atom for an exhaustive list of edge cases.\n" +
[0-0]     '        return true;\n' +
[0-0]     '    }\n' +
[0-0]     '    function isElementSubtreeHiddenByOverflow(element) {\n' +
[0-0]     '        if (!element) {\n' +
[0-0]     '            return false;\n' +
[0-0]     '        }\n' +
[0-0]     '        if (!elementOverflowsContainer(element)) {\n' +
[0-0]     '            return false;\n' +
[0-0]     '        }\n' +
[0-0]     '        if (!element.childNodes.length) {\n' +
[0-0]     '            return false;\n' +
[0-0]     '        }\n' +
[0-0]     "        // This element's subtree is hidden by overflow if all child subtrees are as well.\n" +
[0-0]     '        return Array.from(element.childNodes).every((childNode) => {\n' +
[0-0]     '            // Returns true if the child node is overflowed or otherwise hidden.\n' +
[0-0]     "            // Base case: not an element, has zero size, scrolled out, or doesn't overflow container.\n" +
[0-0]     '            // Visibility of text nodes is controlled by parent\n' +
[0-0]     '            if (childNode.nodeType === Node.TEXT_NODE) {\n' +
[0-0]     '                return false;\n' +
[0-0]     '            }\n' +
[0-0]     '            if (!nodeIsElement(childNode)) {\n' +
[0-0]     '                return true;\n' +
[0-0]     '            }\n' +
[0-0]     '            if (!elementSubtreeHasNonZeroDimensions(childNode)) {\n' +
[0-0]     '                return true;\n' +
[0-0]     '            }\n' +
[0-0]     '            // Recurse.\n' +
[0-0]     '            return isElementSubtreeHiddenByOverflow(childNode);\n' +
[0-0]     '        });\n' +
[0-0]     '    }\n' +
[0-0]     '    // walk up the tree testing for a shadow root\n' +
[0-0]     '    function isElementInsideShadowRoot(element) {\n' +
[0-0]     '        if (!element) {\n' +
[0-0]     '            return false;\n' +
[0-0]     '        }\n' +
[0-0]     '        if (element.parentNode && element.parentNode.host) {\n' +
[0-0]     '            return true;\n' +
[0-0]     '        }\n' +
[0-0]     '        return isElementInsideShadowRoot(element.parentNode);\n' +
[0-0]     '    }\n' +
[0-0]     `    // This is a partial reimplementation of Selenium's "element is displayed" algorithm.\n` +
[0-0]     "    // When the W3C specification's algorithm stabilizes, we should implement that.\n" +
[0-0]     '    // If this command is misdirected to the wrong document (and is NOT inside a shadow root), treat it as not shown.\n' +
[0-0]     '    if (!isElementInsideShadowRoot(element) && !document.contains(element)) {\n' +
[0-0]     '        return false;\n' +
[0-0]     '    }\n' +
[0-0]     '    // Special cases for specific tag names.\n' +
[0-0]     '    switch (element.tagName.toUpperCase()) {\n' +

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues
@vijaychowthri vijaychowthri added Bug 🐛 Needs Triaging ⏳ No one has looked into the issue yet labels Apr 27, 2022
@vijaychowthri
Copy link
Author

try {

            if (oElement.isDisplayed()) {
                return oElement.waitForDisplayed({ timeout: MAXWAITTIME }).then(async function (displayed) {
                    logger.info("PASS", message + "...is displayed " +displayed );
                    return displayed;
                },async function (error) {
                    logger.info("FAIL", message + "...is not displayed"  + error)
                    return false;
                })

            }
            else if (oElement.isClickable()) {
                return oElement.waitForClickable({ timeout: MAXWAITTIME }).then(async function (clickable) {
                    logger.info("PASS", message + "...is clickable " + clickable);
                    return clickable;
                },async function (error) {
                    logger.info("FAIL", message + "...is not clickable "  + error)
                    return false;
                })
            }
            else if (oElement.isEnabled()) {

                return oElement.waitForEnabled({ timeout: MAXWAITTIME }).then(async function (enabled) {
                    logger.info("PASS", message + "...is enabled " + enabled);
                    return enabled;
                },async function (error) {
                    logger.info("FAIL", message + "...is not enabled" +   error)
                    return false;
                })

            }
            else {
                return oElement.waitUntil(async function () {
                    await expect(oElement).toExist().then(async function (ele) {
                        logger.info("PASS", message + "...is available " + ele);
                        return ele;
                    }, async function (error) {
                        logger.info("FAIL", message + "...is not available" + error)
                        return false;
                    })
                })

            }

@christian-bromann
Copy link
Member

@vijaychowthri I have pushed some improvements around this in #8165, can you try with latest version?

@vijaychowthri
Copy link
Author

This can be Closed.

//Options: trace | debug | info | warn | error | silent
logLevel: 'silent',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Needs Triaging ⏳ No one has looked into the issue yet
Projects
None yet
Development

No branches or pull requests

2 participants