Skip to content

Commit

Permalink
add firefox profile settings to prevent saving dialog (for DevExpress…
Browse files Browse the repository at this point in the history
…/testcafe#4869) (#105)

* add firefox profile settings to prevent saving dialog

* reset defaultPreferences

* fix review remarks, Bump version (v1.13.0-alpha.1)
  • Loading branch information
AlexKamaev authored Mar 18, 2020
1 parent 5fb4584 commit 7e9228a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "testcafe-browser-provider-browserstack",
"version": "1.12.0",
"version": "1.13.0-alpha.1",
"description": "browserstack TestCafe browser provider plugin.",
"repository": "https://github.com/DevExpress/testcafe-browser-provider-browserstack",
"engines": {
Expand Down Expand Up @@ -34,8 +34,10 @@
"browserstack-local": "^1.3.6",
"dedent": "^0.7.0",
"desired-capabilities": "^0.1.0",
"firefox-profile": "^1.3.1",
"jimp": "^0.6.4",
"lodash": "^4.17.15",
"mime-db": "^1.43.0",
"os-family": "^1.0.0",
"pinkie": "^2.0.4",
"request": "^2.88.0",
Expand Down
50 changes: 48 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
import { parse as parseUrl } from 'url';
import Promise from 'pinkie';
import { promisify } from 'util';
import parseCapabilities from 'desired-capabilities';
import BrowserstackConnector from './connector';
import JSTestingBackend from './backends/js-testing';
import AutomateBackend from './backends/automate';
import BrowserProxy from './browser-proxy';
import isEnvVarTrue from './utils/is-env-var-true';
import db from 'mime-db';


const ANDROID_PROXY_RESPONSE_DELAY = 500;

const isAutomateEnabled = () => isEnvVarTrue('BROWSERSTACK_USE_AUTOMATE');
const isLocalEnabled = () => !!process.env.BROWSERSTACK_LOCAL_IDENTIFIER || !isEnvVarTrue('BROWSERSTACK_NO_LOCAL');

function getMimeTypes () {
const mimeTypes = Object.keys(db);

return mimeTypes.filter(mimeType => {
const { extensions } = db[mimeType];

return extensions && extensions.length;
}).join(',');
}

export default {
// Multiple browsers support
isMultiBrowser: true,
Expand Down Expand Up @@ -168,6 +180,37 @@ export default {
});
},

_prepareChromeCapabilities (capabilities) {
if (process.env['BROWSERSTACK_CHROME_ARGS'] && process.env['BROWSERSTACK_CHROME_ARGS'].length > 0)
capabilities.chromeOptions = { args: [process.env['BROWSERSTACK_CHROME_ARGS']] };
},

async _prepareFirefoxCapabilities (capabilities) {
if (!process.env['BROWSERSTACK_USE_AUTOMATE'])
return;

const FirefoxProfile = require('firefox-profile');
const profile = new FirefoxProfile();

profile.defaultPreferences = {};

profile.setPreference('browser.helperApps.neverAsk.saveToDisk', getMimeTypes());
profile.updatePreferences();

capabilities['firefox_profile'] = await promisify(profile.encoded).bind(profile)();
},

async _encodeFirefoxProfile (profile) {
return new Promise((resolve, reject) => {
profile.encoded(function (err, encodedProfile) {
if (err)
reject(err);
else
resolve(encodedProfile);
});
});
},

// Required - must be implemented
// Browser control
async openBrowser (id, pageUrl, browserName) {
Expand Down Expand Up @@ -197,8 +240,11 @@ export default {
if (!capabilities.name)
capabilities.name = `TestCafe test run ${id}`;

if (browserName.indexOf('chrome') !== -1 && process.env['BROWSERSTACK_CHROME_ARGS'] && process.env['BROWSERSTACK_CHROME_ARGS'].length > 0)
capabilities.chromeOptions = { args: [process.env['BROWSERSTACK_CHROME_ARGS']] };
if (browserName.includes('chrome'))
this._prepareChromeCapabilities(capabilities);

if (browserName.includes('firefox'))
await this._prepareFirefoxCapabilities(capabilities);

await this.backend.openBrowser(id, pageUrl, capabilities);

Expand Down

0 comments on commit 7e9228a

Please sign in to comment.