Skip to content

Commit

Permalink
Report result to Saucelabs when using remote grid support
Browse files Browse the repository at this point in the history
This causes the run to show as Passed or Failed in the Saucelabs
dashboard. Previously, that only worked when using the deprecated
legacy Saucelabs support.
  • Loading branch information
sgravrock committed Jun 15, 2024
1 parent aa36b10 commit c63a59f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 12 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ module.exports = {
const server = new ServerClass(options);

const reporters = await createReporters(options, deps);
const useSauce = options.browser && options.browser.useSauce;
const useLegacySauce = options.browser && options.browser.useSauce;
const useRemote = options.browser && options.browser.useRemoteSeleniumGrid;
const useSauceCompletionReporting =
useLegacySauce ||
(useRemote &&
options.browser.remoteSeleniumGrid?.url?.includes('saucelabs.com'));
let portRequest;

if (options.port) {
portRequest = options.port;
} else if (useSauce || useRemote) {
} else if (useLegacySauce || useRemote) {
portRequest = 5555;
} else {
portRequest = 0;
Expand Down Expand Up @@ -122,7 +126,7 @@ module.exports = {

return details;
} finally {
if (useSauce) {
if (useSauceCompletionReporting) {
await webdriver.executeScript(
`sauce:job-result=${process.exitCode === 0}`
);
Expand Down
40 changes: 31 additions & 9 deletions spec/indexSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ describe('index', function() {
});

describe('Sending the result to Saucelabs', function() {
describe('When legacy Saucelabs support is used', function() {
function hasSaucelabsResultReporting(browserConfig) {
it('sets sauce:job-result to true when the run passes', async function() {
const webdriver = await runWithSauceWithOverallStatus('passed');
expect(webdriver.executeScript).toHaveBeenCalledWith(
Expand Down Expand Up @@ -471,11 +471,7 @@ describe('index', function() {
webdriver.close.and.returnValue(Promise.resolve());
webdriver.executeScript.and.returnValue(Promise.resolve());
await runSpecs(
{
browser: {
useSauce: true,
},
},
{ browser: browserConfig },
{
Server: function() {
return server;
Expand All @@ -489,9 +485,9 @@ describe('index', function() {

return webdriver;
}
});
}

describe('In all other cases', function() {
function doesNotHaveSaucelabsResultReporting(browserConfig) {
it('does not set sauce:job-result', async function() {
const server = buildSpyServer();
const runner = jasmine.createSpyObj('Runner', ['run']);
Expand All @@ -505,7 +501,7 @@ describe('index', function() {
webdriver.close.and.returnValue(Promise.resolve());
webdriver.executeScript.and.returnValue(Promise.resolve());
await runSpecs(
{},
{ browser: browserConfig },
{
Server: function() {
return server;
Expand All @@ -521,6 +517,32 @@ describe('index', function() {
jasmine.stringContaining('sauce:job-result')
);
});
}

describe('When legacy Saucelabs support is used', function() {
hasSaucelabsResultReporting({ useSauce: true });
});

describe('When the remote grid URL includes saucelabs.com', function() {
hasSaucelabsResultReporting({
useRemoteSeleniumGrid: true,
remoteSeleniumGrid: {
url: 'https://ondemand.saucelabs.com/wd/hub',
},
});
});

describe('When the remote grid URL does not include saucelabs.com', function() {
doesNotHaveSaucelabsResultReporting({
useRemoteSeleniumGrid: true,
remoteSeleniumGrid: {
url: 'https://some-other-grid.example.com/',
},
});
});

describe('In all other cases', function() {
doesNotHaveSaucelabsResultReporting({});
});
});

Expand Down

0 comments on commit c63a59f

Please sign in to comment.