Skip to content

Commit

Permalink
Allow to use any browser with BrowserStack and Appium. (#3634)
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 authored Mar 10, 2023
1 parent 499dba3 commit 24158bb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
11 changes: 8 additions & 3 deletions lib/transport/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ module.exports = class TransportFactory {

let {browserName} = settings.desiredCapabilities;

// Better support for app-testing, if the browserName is not present we can skip all further checks
// Allow to use any browserName with Appium and BrowserStack.
// Not supporting '--browserName' cli flag for both of these.
const usingAppium = TransportFactory.usingSeleniumServer(settings) && settings.selenium.use_appium;
const usingBrowserStack = TransportFactory.usingBrowserstack(settings);
if ((usingAppium || usingBrowserStack) && !browserName) {
if (usingAppium || usingBrowserStack) {
if (BrowsersLowerCase[browserName && browserName.toLowerCase()]) {
browserName = BrowsersLowerCase[browserName.toLowerCase()];
}

return browserName;
}

Expand Down Expand Up @@ -94,7 +99,7 @@ module.exports = class TransportFactory {
const didYouMean = require('didyoumean');
const browsersList = Object.values(Browser);
const resultMeant = didYouMean(browserName, browsersList);

throw new Error(`Unknown browser: "${browserName}"${resultMeant ? ('; did you mean "' + resultMeant + '"?') : ''}`);
}

Expand Down
2 changes: 0 additions & 2 deletions lib/transport/selenium-webdriver/selenium.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ module.exports = class SeleniumServer extends DefaultSeleniumDriver {

return super.setBuilderOptions({builder, options});
}


};


56 changes: 32 additions & 24 deletions test/src/core/testCreateSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -433,18 +433,32 @@ describe('test Request With Credentials', function () {
});
});

it('Test create session with use_appium property - Appium support', async function () {
it('Test create session with use_appium property and random browser - Appium support', async function () {
nock('http://somewhere:9999')
.post('/wd/hub/session')
.reply(201, {
value: {
.reply(201, function (uri, requestBody) {
assert.deepEqual(requestBody, {
capabilities: {
platformName: 'android',
platformVersion: '12.0',
name: 'sample test goes here'
},
sessionId: '1352110219202'
}
firstMatch: [{}],
alwaysMatch: {
browserName: 'acmeBrowser',
platformName: 'android',
'appium:platformVersion': '12.0'
}
}
});

return {
value: {
capabilities: {
browserName: 'acmeBrowser',
platformName: 'android',
platformVersion: '12.0',
name: 'sample test goes here'
},
sessionId: '1352110219202'
}
};
});

const client = Nightwatch.createClient({
Expand All @@ -458,15 +472,16 @@ describe('test Request With Credentials', function () {
port: 9999
},
desiredCapabilities: {
browserName: '',
browserName: 'acmeBrowser',
platformName: 'android',
platformVersion: '12.0'
'appium:platformVersion': '12.0'
}
});

const result = await client.createSession();
assert.deepStrictEqual(result, {
capabilities: {
browserName: 'acmeBrowser',
platformName: 'android',
platformVersion: '12.0',
name: 'sample test goes here'
Expand Down Expand Up @@ -929,16 +944,15 @@ describe('test Request With Credentials', function () {
});
});

it('Test create session with browserstack and update buildName', async function () {
it('Test create session with browserstack with random browser and update buildName', async function () {
nock('https://hub.browserstack.com')
.post('/wd/hub/session')
.reply(201, function (uri, requestBody) {

assert.deepEqual(requestBody, {
capabilities: {
firstMatch: [{}],
alwaysMatch: {
browserName: 'chrome',
browserName: 'acmeBrowser',
'bstack:options': {
local: 'false',
sessionName: 'Try 1',
Expand All @@ -947,8 +961,7 @@ describe('test Request With Credentials', function () {
os: 'OS X',
osVersion: 'Monterey',
buildName: 'Nightwatch Programmatic Api Demo'
},
'goog:chromeOptions': {w3c: false}
}
}
}
});
Expand Down Expand Up @@ -1000,12 +1013,8 @@ describe('test Request With Credentials', function () {
os: 'OS X',
osVersion: 'Monterey'
},
browserName: 'chrome',
chromeOptions: {
w3c: false
}
browserName: 'acmeBrowser'
},

parallel: false
});

Expand All @@ -1020,7 +1029,7 @@ describe('test Request With Credentials', function () {
capabilities: {
firstMatch: [{}],
alwaysMatch: {
browserName: 'chrome',
browserName: 'acmeBrowser',
'bstack:options': {
local: 'false',
sessionName: 'Try 1',
Expand All @@ -1029,8 +1038,7 @@ describe('test Request With Credentials', function () {
os: 'OS X',
osVersion: 'Monterey',
buildName: 'Nightwatch Programmatic Api Demo'
},
'goog:chromeOptions': {w3c: false}
}
}
}
});
Expand Down

0 comments on commit 24158bb

Please sign in to comment.