Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should not go to the requested page', async function () {
await driver.timeouts({protocol: PROTOCOLS.MJSONWP, type: 'page load', ms: 5000}, '1dcfe021-8fc8-49bd-8dac-e986d3091b97');
await driver.setUrl(env.GUINEA_TEST_END_POINT + '?delay=30000');
// the page should not have time to load
(await driver.getPageSource()).should.include('Let\'s browse!');
});
});
it('should go to the requested page', async function () {
await driver.timeouts({protocol: PROTOCOLS.MJSONWP, type: 'command', ms: 120000}, '1dcfe021-8fc8-49bd-8dac-e986d3091b97');
await driver.timeouts({protocol: PROTOCOLS.MJSONWP, type: 'page load', ms: 0}, '1dcfe021-8fc8-49bd-8dac-e986d3091b97');
await driver.setUrl(env.GUINEA_TEST_END_POINT + '?delay=5000');
// the page should load after 70000
(await driver.getPageSource()).should.include('I am some page content');
(Date.now() - startMs).should.be.above(5000);
});
});
syncProtocol (cdVersion = null) {
const coercedVersion = semver.coerce(cdVersion);
if (!coercedVersion || coercedVersion.major < MIN_CD_VERSION_WITH_W3C_SUPPORT) {
log.debug(`Chromedriver v. ${cdVersion} does not fully support ${PROTOCOLS.W3C} protocol. ` +
`Defaulting to ${PROTOCOLS.MJSONWP}`);
return;
}
const chromeOptions = getCapValue(this.capabilities, 'chromeOptions', {});
if (chromeOptions.w3c === false) {
log.info(`Chromedriver v. ${cdVersion} supports ${PROTOCOLS.W3C} protocol, ` +
`but ${PROTOCOLS.MJSONWP} one has been explicitly requested`);
return;
}
this.desiredProtocol = PROTOCOLS.W3C;
// given caps might not be properly prefixed
// so we try to fix them in order to properly init
// the new W3C session
this.capabilities = toW3cCapNames(this.capabilities);
}
extensions.execute = async function execute (script, args) {
if (script.match(/^mobile:/)) {
logger.info(`Executing native command '${script}'`);
script = script.replace(/^mobile:/, '').trim();
return await this.executeMobile(script, _.isArray(args) ? args[0] : args);
}
if (!this.isWebContext()) {
throw new errors.NotImplementedError();
}
const endpoint = this.chromedriver.jwproxy.downstreamProtocol === PROTOCOLS.MJSONWP
? '/execute'
: '/execute/sync';
return await this.chromedriver.jwproxy.command(endpoint, 'POST', {
script,
args,
});
};
commands.getElementRect = async function (elementId) {
if (this.isWebContext()) {
log.debug(`Detected downstream chromedriver protocol: ${this.chromedriver.jwproxy.downstreamProtocol}`);
if (this.chromedriver.jwproxy.downstreamProtocol === PROTOCOLS.MJSONWP) {
const {x, y} = await this.chromedriver.jwproxy.command(`/element/${elementId}/location`, 'GET');
const {width, height} = await this.chromedriver.jwproxy.command(`/element/${elementId}/size`, 'GET');
return {x, y, width, height};
}
return await this.chromedriver.jwproxy.command(`/element/${elementId}/rect`, 'GET');
}
return await this.uiautomator2.jwproxy.command(`/element/${elementId}/rect`, 'GET');
};
this.useSystemExecutable = useSystemExecutable;
this.chromedriver = executable;
this.executableDir = executableDir;
this.mappingPath = mappingPath;
this.bundleId = bundleId;
this.executableVerified = false;
this.state = Chromedriver.STATE_STOPPED;
this.jwproxy = new JWProxy({server: this.proxyHost, port: this.proxyPort});
this.verbose = verbose;
this.logPath = logPath;
this.disableBuildCheck = !!disableBuildCheck;
this.storageClient = isAutodownloadEnabled
? new ChromedriverStorageClient({ chromedriverDir: this.executableDir })
: null;
this.capabilities = {};
this.desiredProtocol = PROTOCOLS.MJSONWP;
}