Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
commands.getWindowHandle = async function getWindowHandle () { // eslint-disable-line require-await
if (!this.isWebContext()) {
throw new errors.NotImplementedError();
}
log.debug(`Getting current window handle`);
return this.curContext;
};
commands.setCookie = async function setCookie (cookie) {
if (!this.isWebContext()) {
throw new errors.NotImplementedError();
}
cookie = _.clone(cookie);
// if `path` field is not specified, Safari will not update cookies as expected; eg issue #1708
if (!cookie.path) {
cookie.path = '/';
}
const jsCookie = cookieUtils.createJSCookie(cookie.name, cookie.value, {
expires: _.isNumber(cookie.expiry) ? (new Date(cookie.expiry * 1000)).toUTCString() :
cookie.expiry,
path: cookie.path,
domain: cookie.domain,
httpOnly: cookie.httpOnly,
secure: cookie.secure
commands.deleteCookie = async function deleteCookie (cookieName) {
if (!this.isWebContext()) {
throw new errors.NotImplementedError();
}
// check cookie existence
let cookies = await this.getCookies();
if (_.indexOf(_.map(cookies, 'name'), cookieName) === -1) {
logger.debug(`Cookie '${cookieName}' not found. Ignoring.`);
return true;
}
return await this._deleteCookie(cookieName);
};
extensions.execute = async function execute (script, args) {
if (!script.match(/^mobile:/) && !this.isWebContext()) {
throw new errors.NotImplementedError();
}
return await iosExecute.call(this, script, args);
};
commands.deleteCookies = async function deleteCookies () {
if (!this.isWebContext()) {
throw new errors.NotImplementedError();
}
const cookies = await this.getCookies();
for (const cookie of cookies) {
await this._deleteCookie(cookie);
}
return true;
};
extensions.executeAsync = async function executeAsync (script, args) {
if (!this.isWebContext()) {
throw new errors.NotImplementedError();
}
args = this.convertElementsForAtoms(args);
this.asyncWaitMs = this.asyncWaitMs || 0;
const promise = this.remote.executeAtomAsync('execute_async_script', [script, args, this.asyncWaitMs], this.curWebFrames);
return await this.waitForAtom(promise);
};
commands.deleteCookies = async function deleteCookies () {
if (!this.isWebContext()) {
throw new errors.NotImplementedError();
}
let cookies = await this.getCookies();
if (cookies.length) {
for (let cookie of cookies) {
await this._deleteCookie(cookie.name);
}
}
return true;
};
commands.closeWindow = async function closeWindow () {
if (this.isWebContext()) {
let script = "return window.open('','_self').close();";
return await this.executeAtom('execute_script', [script, []], true);
} else {
throw new errors.NotImplementedError();
}
};
commands.submit = async function submit (el) {
if (this.isWebContext()) {
let atomsElement = this.useAtomsElement(el);
await this.executeAtom('submit', [atomsElement]);
} else {
throw new errors.NotImplementedError();
}
};
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,
});
};