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

elementHasChildrenCount ignores child_selector #31

Open
curiosity26 opened this issue Apr 10, 2020 · 1 comment
Open

elementHasChildrenCount ignores child_selector #31

curiosity26 opened this issue Apr 10, 2020 · 1 comment

Comments

@curiosity26
Copy link

When attempting to use elementHasChildrenCount with a child selector, the value of child_selector is undefined inside the execute() function.

Steps to recreate:

The issues comes when trying to select a deep child from a parent:

<div id="parent">
    <div>
        <div class="target_child">Child 1</div>
        <div class="target_child">Child 2</div>
    </div>
</div>

Then in your test, try the following:

{
 // ...

    "Child count should be valid": browser => {
          browser.assert.elementHasChildrenCount("#parent", 2, ".target_child");
         // FAILS with count of 1
    },

// ...
}
@curiosity26
Copy link
Author

curiosity26 commented Apr 10, 2020

I've written a workaround assertion for 0.9:

module.exports.assertion = function (selector, count, childSelector = null) {
  this.message = `The number of children is not ${count}`;

  this.expected = count;

  this.pass = (value) => value;

  this.value = (result) => result;

  this.command = (cb) => this.api.execute(`var element = document.querySelector("${selector}");
    var childSelector = "${childSelector}";
    
    if (childSelector) {
      return selector.querySelectorAll(childSelector).length;
    }
    
    return selector.children.length;
    `, [], ({ value }) => cb(value));
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant