Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function withSelenium(test) {
const builder = new WD.Builder()
.forBrowser('firefox');
// on Travis CI we run headless; setting up Xvfb is
// just annoying and not very useful
if (process.env.TRAVIS) {
builder
.setFirefoxOptions(
new firefox.Options().headless()
)
.setChromeOptions(
new chrome.Options().headless()
);
}
const driver = builder.build();
try {
await test(driver);
} finally {
driver.quit();
}
}
function runSeleniumTests() {
const profile = new firefox.Profile(profileDir);
// Configure profile
Object.keys(autoConfig).forEach((pref) => {
console.log(`Set pref ${pref} to ${autoConfig[pref]}`);
// profile.setPreference(pref, autoConfig[pref]);
});
// Prepare chromium webdriver
const firefoxOptions = new firefox.Options()
.setProfile(profile)
.setBinary(firefoxBin);
// Enable verbose logging
const prefs = new logging.Preferences();
prefs.setLevel(logging.Type.BROWSER, logging.Level.INFO);
const caps = selenium.Capabilities.firefox();
caps.setLoggingPrefs(prefs);
// Create webdriver
const driver = new selenium.Builder()
.forBrowser('firefox')
.withCapabilities(caps)
.setFirefoxOptions(firefoxOptions)
.build();
before((done) => {
// Create driver
if (NEED_BROWSER_CHROME) {
const BROWSER_NAME = 'chrome';
driver = new webdriver.Builder().forBrowser(BROWSER_NAME).build();
}
// This is not working code!
// TODO: fix start firefox browser for tests
if (NEED_BROWSER_FIREFOX) {
const profile = new firefox.Profile();
profile.setAcceptUntrustedCerts(true);
profile.setAssumeUntrustedCertIssuer(false);
const opts = new firefox.Options();
opts.setProfile(profile);
// setup here reference to firefox executable on
// your local machine. This is very non-universal solution
// and should be fixed later (avoid absolute path)
opts.setBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe');
const builder = new Builder().forBrowser('firefox');
builder.setFirefoxOptions(opts);
driver = builder.build();
}
// Setup browser window size (as default window size is too small)
const W_TEST_BROWSER_SIZE = 1280;
const H_TEST_BROWSER_SIZE = 720;
driver.manage().window().setSize(W_TEST_BROWSER_SIZE, H_TEST_BROWSER_SIZE);
golden = new Golden();
const urlDecoded = URL_TEST_PAGE_APP;
constructor(release) {
let prettyName = 'Firefox';
const ffOptions = new firefoxOptions.Options();
// Required since v47
ffOptions.useMarionette(true);
if (release === 'stable') {
prettyName += ' Stable';
} else if (release === 'beta') {
prettyName += ' Beta';
} else if (release === 'unstable') {
prettyName += ' Nightly';
}
super(
prettyName,
release,
'firefox',
ffOptions
function buildDriver(browser) {
// Firefox options.
// http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_firefox.html
const profile = new firefox.Profile();
profile.setPreference('media.navigator.streams.fake', true);
const firefoxOptions = new firefox.Options()
.setProfile(profile);
// Chrome options.
// http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_chrome_class_Options.html#addArguments
const chromeOptions = new chrome.Options()
/*
.addArguments('enable-logging=1')
.addArguments('v=1')
.addArguments('vmodule=*libjingle/source/talk/*=4')
.addArguments('user-data-dir=/some/where')
*/
.addArguments('allow-file-access-from-files')
.addArguments('use-fake-device-for-media-stream')
.addArguments('use-fake-ui-for-media-stream');
// use-file-for-fake-audio-capture -- see https://code.google.com/p/chromium/issues/detail?id=421054
// we need it until Selenium NodeJS version supports setting geckodriver
// Selenium looks for geckodriver in the PATH.
const geckoPath = geckodriver.binPath().replace('geckodriver','');
if (process.env['PATH'].indexOf(geckoPath === -1)) {
process.env.PATH = process.env.PATH + ':' + geckoPath;
}
profile.setPreference('xpinstall.signatures.required', false);
profile.addExtension(path.resolve(__dirname, '..', '..', 'vendor', 'har_export_trigger-0.5.0-beta.7-fx.xpi'));
profile.setPreference('devtools.chrome.enabled', true);
const firefoxConfig = options.firefox || {};
let ffOptions = new firefox.Options();
const binary = new firefox.Binary(firefoxConfig.binaryPath);
binary.addArguments('-no-remote');
ffOptions.setBinary(binary);
ffOptions.setProfile(profile);
if (proxyConfig) {
ffOptions.setProxy(proxyConfig);
}
builder.setFirefoxOptions(ffOptions);
}
break;
default:
return Promise.reject(new Error('Unsupported browser: ' + browser));
}
describe('isVisible', () => {
const options = new firefox.Options();
options.headless();
const driver = new Builder()
.forBrowser('firefox')
.setFirefoxOptions(options)
.build();
async function checkElementVisibility(id, expected) {
await driver.wait(until.elementLocated(By.id(id)), WAIT_MS);
const isElementVisible = await driver.executeScript(`
${ancestors}
${isDomElement}
${toDomElement}
return ${isVisible}(document.getElementById('${id}'));
`);
assert.equal(
var firefox = require('selenium-webdriver/firefox');
var webdriver = require('selenium-webdriver');
var profile = new firefox.Profile();
profile.addExtension('../../build/firefox/shumway.xpi');
profile.setPreference('dom.always_stop_slow_scripts', true);
profile.setPreference('shumway.disabled', true);
profile.setPreference('shumway.environment', 'test');
profile.setPreference('shumway.whitelist', '*');
//var binary = new firefox.Binary('/Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin');
var binary = new firefox.Binary('/Applications/Firefox.app/Contents/MacOS/firefox-bin');
var options = new firefox.Options().setProfile(profile);
options.setBinary(binary);
var driver;
function escapeRegExp(string){
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
}
function main(info, cb) {
var i = 0;
var n = Math.min(info.parse_result.max_ticks, 100);
var errors = [];
function tick() {
if (i++ < n) {
setTimeout(tick);
} else {
function start(_url, _options = {}) {
if (_options.useWebSocket) {
useWebSocket = true;
connectionPort = _options.webSocketPort
? _options.webSocketPort
: connectionPort;
} else {
connectionPort = _options.tcpPort ? _options.tcpPort : connectionPort;
}
let options = new firefox.Options();
let nightlyChannel = new firefox.Channel(
"/Applications/Firefox Nightly.app/Contents/MacOS/firefox-bin",
"Firefox Nightly\\firefox.exe"
)
options.setProfile(firefoxProfile());
options.setBinary(nightlyChannel);
options.args_ = binaryArgs();
const driver = new webdriver.Builder()
.forBrowser("firefox")
.setFirefoxOptions(options)
.build();
let location = url.parse(_url);
]
};
const Browsers = {
chrome: 'chrome',
edge: 'MicrosoftEdge',
firefox: 'firefox',
ie: 'internet explorer',
safari: 'safari',
};
const seleniumWebdriverOptions = {
safari: new safari.Options(),
chromeHeadless: new chrome.Options().headless(),
chrome: new chrome.Options(),
firefoxHeadless: new firefox.Options().headless(),
firefox: new firefox.Options(),
ie: new ie.Options(),
edge: new edge.Options(),
};
class Query extends BaseQuery {
async getText(selector, options = {}) {
const [ text ] = await this.getTexts(selector, options) || [];
return text;
}
async getTexts(selector, options = {}) {
const elements = await this.$$(selector, options);
let innerTexts = [];
for(const ele of elements) {