Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
BASE_URL = process.env.BASE_URL;
} else {
throw "Set BASE_URL to be the root of the compiler directory";
}
let refreshPagePerTest;
if (process.env.BROWSER_TEST_REFRESH) {
refreshPagePerTest = process.env.BROWSER_TEST_REFRESH;
} else {
refreshPagePerTest = false;
console.log("Browser tests occur in the same page instance. To refresh the page between tests, set 'BROWSER_TEST_REFRESH' to 'true'");
}
let leave_open = process.env.LEAVE_OPEN === "true" || false;
var chromeOptions = new seleniumChrome
.Options();
if (process.env.SHOW_BROWSER === "false") {
chromeOptions = chromeOptions.headless();
console.log("Running headless (may not work with Firefox). You can set SHOW_BROWSER=true to see what's going on");
}
let args = [];
const ffCapabilities = webdriver.Capabilities.firefox();
ffCapabilities.set('moz:firefoxOptions', {
binary: PATH_TO_BROWSER,
'args': args
});
// Working from https://developers.google.com/web/updates/2017/04/headless-chrome#drivers
const chromeCapabilities = webdriver.Capabilities.chrome();
// Ensure the browser webdriver binaries are added to env path
require('chromedriver');
require('geckodriver');
if (process.platform === 'darwin') {
browsers.push('safari');
} else if (process.platform === 'win32') {
browsers.push('edge');
}
// Disable Chrome's protocol handler for `blockstack:` in case the native browser is installed on this machine
// https://stackoverflow.com/a/41299296/794962
// Note: This ability has since been disabled by Chrome, there is no way to hide the prompt.
// https://github.com/chromium/chromium/blob/5f0fb8c9021d25d1fadc1ae3706b4790dbcded5a/chrome/browser/external_protocol/external_protocol_handler.cc#L194
const chromeOpts = new chromeOptions()
.setUserPreferences({protocol_handler: { excluded_schemes: { 'blockstack': true } } });
// Disable Firefox's protocol handler for `blockstack:` in case the native browser is installed on this machine
// https://stackoverflow.com/a/53154527/794962
const firefoxOpts = (() => {
const handlers = '{"defaultHandlersVersion":{"en-US":4},"schemes":{"blockstack":{"action":2,"handlers":[{"name":"None","uriTemplate":"#"}]}}}';
const tempDir = path.resolve(os.tmpdir(), helpers.getRandomString());
fs.mkdirSync(tempDir);
fs.writeFileSync(path.resolve(tempDir, 'handlers.json'), handlers);
return new firefoxOptions().setProfile(tempDir);
})();
const caps = new Capabilities().setLoggingPrefs(getLoggingPrefs());
// Increase the `driver.executeAsyncScript(...)` timeout from zero to something usable.
// https://stackoverflow.com/a/31121340/794962
4: four
*/
// process.argv.forEach((val, index, array) => {
var path = require('chromedriver').path;
var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);
// if (index === 2) { // corresponds to the medicine name
// var medicines = val;
var medicines = 'Rebamipide'
// keep the below block of code in the last part the else if block
var options = new chrome.Options();
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-gpu");
options.addArguments("--headless");
var driver = new webdriver.Builder()
.setChromeOptions(options)
.forBrowser('chrome')
.build();
const BASEURL = ' https://www.medindia.net/drugs/medical-condition/',
ENDWARE = '.htm';
driver.get(BASEURL + medicines + ENDWARE).then(() => {
driver.findElements(By.className('drug-content')).then(loop => {
var count = -1;
var data='';
loop.forEach((itr, i) => {
// Currently the FF webdriver extension is not signed and FF 41 no longer
// allows unsigned extensions by default.
// TODO: Remove this once FF no longer allow turning this off and the
// selenium team starts making a signed FF webdriver extension.
// https://github.com/SeleniumHQ/selenium/issues/901.
profile.setPreference('xpinstall.signatures.required', false);
var firefoxOptions = new firefox.Options()
.setProfile(profile);
if (os.platform() === 'linux') {
firefoxOptions.setBinary('node_modules/.bin/start-firefox');
}
// Chrome options.
// http://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_chrome_class_Options.html#addArguments
var chromeOptions = new chrome.Options()
.addArguments('allow-file-access-from-files')
.addArguments('use-fake-device-for-media-stream')
.addArguments('use-fake-ui-for-media-stream');
if (os.platform() === 'linux') {
chromeOptions.setChromeBinaryPath('node_modules/.bin/start-chrome');
}
if (process.env.BROWSER === 'chrome') {
let browserVersion = getBrowserVersion();
if (browserVersion >= 49 && process.env.CHROMEEXPERIMENT !== 'false') {
chromeOptions.addArguments('--enable-experimental-web-platform-features');
}
if (browserVersion >= 59) {
chromeOptions.addArguments('headless');
chromeOptions.addArguments('disable-gpu');
}
process.argv.forEach((val, index, array) => {
var path = require('chromedriver').path;
var service = new chrome.ServiceBuilder(path).build();
chrome.setDefaultService(service);
if (index === 2) { // corresponds to the search method
method = val;
} else if(index == 3) { // corresponds to search url
url = val;
// keep the below block of code in the last part the else if block
var options = new chrome.Options();
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-gpu");
options.addArguments("--headless");
var driver = new webdriver.Builder()
.setChromeOptions(options)
.forBrowser('chrome')
.build();
driver.get(url).then(() => {
driver.findElement(By.tagName('body')).then(cc => {
cc.getAttribute('innerHTML').then(result => {
console.log("result::: ", result);
driver.quit();
});
async function _init () {
if (INITIALIZED) return;
WD = await new Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options().addArguments("load-extension=" + process.cwd()))
.build();
log(chalk.green.bold(`Requesting: ${EXTENSIONS_URL}`));
await WD.get(EXTENSIONS_URL);
let optionsLink = await WD.wait(until.elementLocated(By.linkText('Options')), 4000);
let href = await optionsLink.getAttribute('href');
EXT_ID = href.replace('chrome-extension://', '').replace('/html/options.html', '');
log(chalk.green(`Found Extension ID: ${EXT_ID}`));
TEST_URL = `chrome-extension://${EXT_ID}/test/html/screenshots.html`
INITIALIZED = true;
};
function buildDriver() {
let logPref = new logging.Preferences();
logPref.setLevel(logging.Type.PERFORMANCE, logging.Level.ALL);
logPref.setLevel(logging.Type.BROWSER, logging.Level.ALL);
let options = new chrome.Options();
if (config.HEADLESS) {
options = options.addArguments('--headless');
}
options = options.addArguments('--no-sandbox');
options = options.addArguments('--js-flags=--expose-gc');
options = options.addArguments('--disable-infobars');
options = options.addArguments('--disable-background-networking');
options = options.addArguments('--disable-cache');
options = options.addArguments('--disable-extensions');
options = options.addArguments('--window-size=1200,800');
options = options.setLoggingPrefs(logPref);
options = options.setPerfLoggingPrefs({
enableNetwork: false,
enablePage: false,
exports.get = function () {
const caps = defaults();
const options = new chrome.Options();
options.addExtensions(`${__dirname}/../../dist/autotester-dev.crx`);
options.addExtensions(`${__dirname}/../../dist/autotester.crx`);
const tasks = options[Symbols.serialize]().extensions;
return Promise.all(tasks)
.then(extensions => {
caps.chromeOptions.extensions = extensions;
return caps;
});
};
function getChromeBuilder() {
return new Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options()
.addExtensions(encode(path.resolve(__dirname, '../../yoroi-test.crx')))
.addArguments(
'--start-maximized',
'--disable-setuid-sandbox',
'--no-sandbox',
'--disable-dev-shm-usage',
));
}