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

TypeError: Cannot read property 'browser_version' of undefined #243

Closed
Krinkle opened this issue Apr 12, 2021 · 1 comment · Fixed by #244
Closed

TypeError: Cannot read property 'browser_version' of undefined #243

Krinkle opened this issue Apr 12, 2021 · 1 comment · Fixed by #244

Comments

@Krinkle
Copy link
Contributor

Krinkle commented Apr 12, 2021

Expected Behavior

Test against firefox_45, safari_9, safari_10, safari_11.

Actual Behavior

/browserstack-runner/bin/cli.js:401
            if (browser.browser_version === 'latest') {
                        ^

TypeError: Cannot read property 'browser_version' of undefined
    at /qunit/node_modules/browserstack-runner/bin/cli.js
    at Array.forEach (<anonymous>)
    at /qunit/node_modules/browserstack-runner/bin/cli.js
    at Timeout._onTimeout (/qunit/node_modules/browserstack-runner/lib/local.js)

browserstack.json

  "browsers": [
    "safari_9"
  ],

Platform details

  • browserstack-runner version: 0.9.4
  • node version: 10.x
@Krinkle
Copy link
Contributor Author

Krinkle commented Apr 12, 2021

After a long time debugging and narrowing down, I found that the following happens for safari_9:

  getBrowserObject: function(entry) {
    var browserObject = {};
    var version = null;
    var sliceStart = 1;
    if (typeof entry  === 'string') {
      // …
      if (browserData[lindex] && browserData[lindex].indexOf('+') === -1) {
        if (['current', 'previous', 'latest'].indexOf(browserData[lindex]) !== -1) {
          // …
        } else {
          version = browserData.slice(sliceStart, lindex + 1).join('.'); // <!-- assign "9"
        }
      } else {
        // …
      }
      if (browserObject.mobile) {
        // …
      } else {
        browserObject.browser_version = version; // <!-- assign "9"
      }
    } else {
      // …
    }
    browserObject = ConfigParser.populateOsAndOsVersion(browserObject); // <!-- assign undefined
    return browserObject;
  }
  populateOsAndOsVersion: function(browserObject) {
    if (!(browserObject.os && browserObject.os_version)) {
      if (browserObject.mobile) {
        // …
      } else {
        // …;
        var osxFiltered = ConfigParser.bsBrowsers.filter(function(currentValue) {
          return currentValue.os === 'OS X' && currentValue.browser === browserObject.browser && ((browserObject.browser_version && browserObject.browser_version.indexOf('latest')) > -1 || parseFloat(currentValue.browser_version).toPrecision(4) === parseFloat(browserObject.browser_version).toPrecision(4));
        });
        // ^ osxFiltered is []

        var filteredObject = osxFiltered[Math.floor(Math.random() * osxFiltered.length)];
        // ^ filteredObject ==> osxFiltered[0] ==> undefined
   
        browserObject = filteredObject;
      }
    }
    return browserObject;
  }

I thought that 9 means 9.x but it actually means 9.0 so the user has to make sure the version matches exactly with that of https://www.browserstack.com/list-of-browsers-and-platforms/js_testing. I'll leave aside whether that is the intend behaviour but at the least we should tell make sure browserstack-runner does not crash and gives the user a useful error message.

Krinkle added a commit to Krinkle/browserstack-runner that referenced this issue Apr 12, 2021
When no match is found, the process would just crash. Instead, recognise
this as a normal end-user scenario and point them to the list of
available workers.

In my experience the most common way to encounter this issue is when
additional decimal places are required by the API, e.g. "safari"
"9" results in a crash, because the available workers are described
as "9.1" instead. Given that most browers are described without a
decimal place, this is an easy mistake to make.

Another way to get this is when there is a misspelled browser name.

Before:

```
TypeError: Cannot read property 'browser_version' of undefined
    at browserstack-runner/bin/cli.js
```

After:

```
Error: No desktop match found for {"browser":"safari","browser_version":"9"}
Check https://www.browserstack.com/list-of-browsers-and-platforms/js_testing
    at populateOsAndOsVersion (browserstack-runner/lib/configParser.js)

```

Fixes browserstack#243.
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

Successfully merging a pull request may close this issue.

1 participant