This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 28146 - [WebDriver Spec]: Add RegExp as valid Javascript Command Parameter type
Summary: [WebDriver Spec]: Add RegExp as valid Javascript Command Parameter type
Status: RESOLVED WONTFIX
Alias: None
Product: Browser Test/Tools WG
Classification: Unclassified
Component: WebDriver (show other bugs)
Version: unspecified
Hardware: All All
: P2 enhancement
Target Milestone: ---
Assignee: Browser Testing and Tools WG
QA Contact: Browser Testing and Tools WG
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 20860
  Show dependency treegraph
 
Reported: 2015-03-05 17:00 UTC by David Pisoni
Modified: 2015-03-05 22:54 UTC (History)
3 users (show)

See Also:


Attachments

Description David Pisoni 2015-03-05 17:00:41 UTC
RegExps are not currently a supported type. When Selenium WebDriver encounters them in this context it will convert them to an empty object. I'm not certain if there are cross-platform issues with this, but AFAIK RegExp is broadly supported so should be a decent candidate for this.
Comment 1 David Burns :automatedtester 2015-03-05 21:15:12 UTC
While RegExp would be awesome unfortunately there is no way to serialize a Regexp to JSON. YOu can still create your own execute_script and pass it the string that has a regexp.
Comment 2 James Graham 2015-03-05 22:49:42 UTC
Well sure there is, if we wanted to support this:

{some-defined-uuid: string-that-compiles-as-regexp}

(I don't have an opinion on whether this should be supported, but it is certainly *possible* to do so).
Comment 3 David Pisoni 2015-03-05 22:54:05 UTC
Right, this is the sort of thing I have in my client code to work around this. Makes for some ugliness and repetition in the client code... like so:

      // test/driver side
      if (Object.prototype.toString.call(mockDef.url) == '[object RegExp]') {
        // Serialize RegExp with special prefix flag
        mockDef.url = REGEXFLAG + mockDef.url.source;
      }
/*/*/*/*/
      // browser side
      if (mockDef.url.indexOf(REGEXFLAG) === 0) {
        // Marshal RegExp from special string
        mockDef.url  = new RegExp(mockDef.url.substr(3));
      }

Ugly, and of course the REGEXFLAG constant needs to be defined on both sides as well.