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

driver.findContent(...) is broken in the repl #22

Open
cpind opened this issue Aug 2, 2019 · 0 comments
Open

driver.findContent(...) is broken in the repl #22

cpind opened this issue Aug 2, 2019 · 0 comments

Comments

@cpind
Copy link
Contributor

cpind commented Aug 2, 2019

Running node> driver.findContent('.foo', /BAR/); in the repl is broken. The culprit is in mocha-webdriver in lib/webdriver-plus.ts:

const contentRE = content instanceof RegExp ?
   content :
   new RegExp(content.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'));

This fails when making a call from the repl as node> driver.find('.foo', /Bar/);, it fails to recognize /Bar/ as being an instance of RegExp, so it treats it as a string and fails for not having a .replace function. The problem could be that the repl uses it's own RegExp constructor, making content instanceof RegExp inoperant in this context. One solution (tested on devs machine) is to change to

const contentRE = typeof content  === 'string' ?
   new RegExp(content.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')) :
   content;

.
I've thought of other solutions, such as passing the RegExp constructor to the repl context. It does solves the issues when using driver.findContent('.foo', new RegExp('BAR')); but not when using /BAR/. Maybe there could be a solution by customizing further the repl eval function maybe parsing argument, but lack of documentation makes it hard.

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