Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Support for "latest version" of a vendor/OS combo #7

Merged
merged 5 commits into from
Aug 31, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
logs
*.log

.idea

# Runtime data
pids
*.pid
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ $ ./node_modules/.bin/guacamole --id=firefox_38_OS_X_10_9_Desktop
{ browserName: 'firefox', version: '38', platform: 'OS X 10.9' }
```

Fetch the latest version of a browser/OS combination with `--id` and `latest`:

```console
$ ./node_modules/.bin/guacamole --id=firefox_latest_OS_X_10_9_Desktop
{ browserName: 'firefox', version: '40', platform: 'OS X 10.9' }
```

Amend screenResolution with `--screenResolution`. If the API supports that screen resolution, you'll get a result:
```console
$ ./bin/guacamole --id=firefox_38_OS_X_10_9_Desktop --screenResolution=1024x768
Expand Down
32 changes: 28 additions & 4 deletions src/browsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var _ = require("lodash");
var request = require("request");
var syncRequest = require("sync-request");
var browsers = [];
var latest = {};
var fs = require("fs");
var path = require("path");

Expand Down Expand Up @@ -66,6 +67,8 @@ var SauceBrowsers = {
return browsers.filter(fn);
},

latest: latest,

// Return a list of browser desiredCapabilities objects if they exist in our browser list.
//
// Match by:
Expand All @@ -82,10 +85,23 @@ var SauceBrowsers = {
// with id, family, and a supported resolutions array (i.e. guacamole's raw internal representation)
//
get: function (specs, wrapped) {

if (specs.id && specs.id.indexOf("latest") > -1) {
var splitId = specs.id.split("latest");
if (splitId.length === 2) {
var browserId = splitId[0].replace("_", "");
var osId = splitId[1].replace("_", "");
if (latest[browserId] && latest[browserId][osId]) {
var latestVersion = latest[browserId][osId];
var newId = splitId[0] + latestVersion + splitId[1];
specs.id = newId;
}
}
}

return browsers.filter(function (browser) {
// Match specs. Ignore orientation, and special case screenResolution
var matching = true;

// Match by id (only if id has been specified)
if (specs.id && browser.id !== specs.id) {
var matchesTranslated = false;
Expand Down Expand Up @@ -296,12 +312,20 @@ var SauceBrowsers = {
+ "_" + cleanPlatformName(hostOSName)
)
} else {
var osKey = cleanPlatformName(osName) + "_" + cleanPlatformName(deviceName);
guacamoleId = (
cleanPlatformName(name)
+ "_" + cleanPlatformName(browser.short_version)
+ "_" + cleanPlatformName(osName)
+ "_" + cleanPlatformName(deviceName)
)
+ "_" + osKey
);

if (!latest[browser.api_name]) {
latest[browser.api_name] = {};
}

if(!latest[browser.api_name][osKey] || latest[browser.api_name][osKey] < browser.short_version) {
latest[browser.api_name][osKey] = parseInt(browser.short_version, 10);
}
}

var result = {
Expand Down
16 changes: 14 additions & 2 deletions test/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,20 @@ describe("normalizer", function () {
});
});

it("normalizes Chrome43 on Windows correctly", function () {
var id = "chrome_43_Windows_2012_R2_Desktop";
it("normalizes Chrome42 on Windows correctly", function () {
var id = "chrome_42_Windows_2012_R2_Desktop";
var result = Browsers.get({ id: id });
expect(result).to.have.length(1);

var chrome43 = result[0];
expect(chrome43).to.have.property("browserName", "chrome");
expect(chrome43).to.have.property("platform", "Windows 2012 R2");
expect(chrome43).to.have.property("version", "42");
expect(chrome43).to.have.property("browserName", "chrome");
});

it("normalizes latest Chrome version on Windows correctly", function () {
var id = "chrome_latest_Windows_2012_R2_Desktop";
var result = Browsers.get({ id: id });
expect(result).to.have.length(1);

Expand Down