How to use driver.deleteAllCookies method in Appium

Best JavaScript code snippet using appium

safari-basic-e2e-specs.js

Source:safari-basic-e2e-specs.js Github

copy

Full Screen

...345 describe('cookies', function () {346 describe('within iframe webview', function () {347 it('should be able to get cookies for a page with none', async function () {348 await openPage(driver, GUINEA_PIG_IFRAME_PAGE);349 await driver.deleteAllCookies();350 await retryInterval(5, 1000, async function () {351 await driver.allCookies().should.eventually.have.length(0);352 });353 });354 });355 describe('within webview', function () {356 describe('insecure', function () {357 beforeEach(async function () {358 await openPage(driver, GUINEA_PIG_PAGE);359 await driver.deleteCookie(newCookie.name);360 });361 it('should be able to get cookies for a page', async function () {362 const cookies = await driver.allCookies();363 cookies.length.should.equal(2);364 doesIncludeCookie(cookies, oldCookie1);365 doesIncludeCookie(cookies, oldCookie2);366 });367 it('should be able to set a cookie for a page', async function () {368 await driver.setCookie(newCookie);369 const cookies = await driver.allCookies();370 doesIncludeCookie(cookies, newCookie);371 // should not clobber old cookies372 doesIncludeCookie(cookies, oldCookie1);373 doesIncludeCookie(cookies, oldCookie2);374 });375 it('should be able to set a cookie with expiry', async function () {376 const expiredCookie = Object.assign({}, newCookie, {377 expiry: parseInt(Date.now() / 1000, 10) - 1000, // set cookie in past378 name: 'expiredcookie',379 });380 let cookies = await driver.allCookies();381 doesNotIncludeCookie(cookies, expiredCookie);382 await driver.setCookie(expiredCookie);383 cookies = await driver.allCookies();384 // should not include cookie we just added because of expiry385 doesNotIncludeCookie(cookies, expiredCookie);386 // should not clobber old cookies387 doesIncludeCookie(cookies, oldCookie1);388 doesIncludeCookie(cookies, oldCookie2);389 await driver.deleteCookie(expiredCookie.name);390 });391 it('should be able to delete one cookie', async function () {392 await driver.setCookie(newCookie);393 let cookies = await driver.allCookies();394 doesIncludeCookie(cookies, newCookie);395 await driver.deleteCookie(newCookie.name);396 cookies = await driver.allCookies();397 doesNotIncludeCookie(cookies, newCookie);398 doesIncludeCookie(cookies, oldCookie1);399 doesIncludeCookie(cookies, oldCookie2);400 });401 it('should be able to delete all cookies', async function () {402 await driver.setCookie(newCookie);403 let cookies = await driver.allCookies();404 doesIncludeCookie(cookies, newCookie);405 await driver.deleteAllCookies();406 cookies = await driver.allCookies();407 cookies.length.should.equal(0);408 doesNotIncludeCookie(cookies, oldCookie1);409 doesNotIncludeCookie(cookies, oldCookie2);410 });411 describe('native context', function () {412 const notImplementedRegExp = /Method is not implemented/;413 let context;414 beforeEach(async function () {415 context = await driver.currentContext();416 await driver.context('NATIVE_APP');417 });418 afterEach(async function () {419 if (context) {420 await driver.context(context);421 }422 });423 it('should reject all functions', async function () {424 await driver.setCookie(newCookie).should.eventually.be.rejectedWith(notImplementedRegExp);425 await driver.allCookies().should.eventually.be.rejectedWith(notImplementedRegExp);426 await driver.deleteCookie(newCookie.name).should.eventually.be.rejectedWith(notImplementedRegExp);427 await driver.deleteAllCookies().should.eventually.be.rejectedWith(notImplementedRegExp);428 });429 });430 });431 describe('secure', function () {432 /*433 * secure cookie tests are in `./safari-ssl-e2e-specs.js`434 */435 });436 });437 });438 });439 describe('safariIgnoreFraudWarning', function () {440 describe('false', function () {441 beforeEach(async function () {...

Full Screen

Full Screen

controllers.test.js

Source:controllers.test.js Github

copy

Full Screen

...184 // assert.throws(g, errors.NoSuchFrame);185 // }186 });187 it('cookie handlers', async () => {188 await driver.deleteAllCookies();189 var cookies = await driver.getAllCookies();190 assert.equal(cookies.length, 0);191 var cookie = {192 url: pkg.homepage,193 name: pkg.name,194 value: pkg.name195 };196 await driver.addCookie(cookie);197 const res = await driver.getNamedCookie(cookie.name);198 assert.equal(res.length, 1);199 var cookie2 = {200 url: pkg.homepage,201 name: 'cookie-test',202 value: 'cookie-test'203 };204 await driver.addCookie(cookie2);205 cookies = await driver.getAllCookies();206 assert.equal(cookies.length, 2);207 await driver.deleteCookie('cookie-test', pkg.homepage);208 cookies = await driver.getAllCookies();209 assert.equal(cookies.length, 1);210 await driver.deleteAllCookies();211 cookies = await driver.getAllCookies();212 assert.equal(cookies.length, 0);213 });214 it('cookie handlers legacy deleteCookie behaviour', async () => {215 await driver.deleteAllCookies();216 let cookies;217 var cookie = {218 url: pkg.homepage,219 name: pkg.name,220 value: pkg.name221 };222 await driver.addCookie(cookie);223 var cookie2 = {224 url: pkg.homepage,225 name: 'cookie-test',226 value: 'cookie-test'227 };228 await driver.addCookie(cookie2);229 cookies = await driver.getAllCookies();...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

...138 case "delete":139 driver.del(options.url, options.headers, options.body, done);140 break;141 case "deleteAllCookies":142 driver.deleteAllCookies(done);143 break;144 default:145 if(done instanceof Function) done(new Error("Unsupported or unknown device interaction `" + interaction + "`"), null);146 }147 }148 else {149 if(done instanceof Function)150 done(new Error("Cannot perform device interaction, since the driver hasn't been started yet."), false);151 }152 return self;153 };154 /**155 * Gets the device orientation<br>156 * Results will always be 1, since *most* monitors cannot rotate...

Full Screen

Full Screen

cookies-base.js

Source:cookies-base.js Github

copy

Full Screen

1"use strict";2var setup = require("../setup-base"),3 webviewHelper = require("../../../helpers/webview"),4 loadWebView = webviewHelper.loadWebView,5 isChrome = webviewHelper.isChrome,6 testEndpoint = webviewHelper.testEndpoint,7 _ = require('underscore');8module.exports = function (desired) {9 describe('cookies', function () {10 var driver;11 setup(this, desired, {'no-reset': true}).then(function (d) { driver = d; });12 describe('within iframe webview', function () {13 it('should be able to get cookies for a page with none', function (done) {14 loadWebView(desired, driver, testEndpoint(desired) + 'iframes.html',15 "Iframe guinea pig").then(function () {16 return driver17 .deleteAllCookies()18 .get(testEndpoint(desired))19 .allCookies().should.eventually.have.length(0);20 }).nodeify(done);21 });22 });23 describe('within webview', function () {24 // TODO: investigate why we need that25 function _ignoreEncodingBug(value) {26 if (isChrome(desired)) {27 console.warn('Going round android bug: whitespace in cookies.');28 return encodeURI(value);29 } else return value;30 }31 beforeEach(function (done) {32 loadWebView(desired, driver).nodeify(done);33 });34 it('should be able to get cookies for a page', function (done) {35 driver36 .allCookies()37 .then(function (cookies) {38 cookies.length.should.equal(2);39 cookies[0].name.should.equal("guineacookie1");40 cookies[0].value.should.equal(_ignoreEncodingBug("i am a cookie value"));41 cookies[1].name.should.equal("guineacookie2");42 cookies[1].value.should.equal(_ignoreEncodingBug("cookié2"));43 }).nodeify(done);44 });45 it('should be able to set a cookie for a page', function (done) {46 var newCookie = {name: "newcookie", value: "i'm new here"};47 driver48 .deleteCookie(newCookie.name)49 .allCookies()50 .then(function (cookies) {51 _.pluck(cookies, 'name').should.not.include(newCookie.name);52 _.pluck(cookies, 'value').should.not.include(newCookie.value);53 }).then(function () {54 return driver55 .setCookie(newCookie)56 .allCookies();57 })58 .then(function (cookies) {59 _.pluck(cookies, 'name').should.include(newCookie.name);60 _.pluck(cookies, 'value').should.include(newCookie.value);61 // should not clobber old cookies62 _.pluck(cookies, 'name').should.include("guineacookie1");63 _.pluck(cookies, 'value').should.include(_ignoreEncodingBug("i am a cookie value"));64 })65 .nodeify(done);66 });67 it('should be able to set a cookie with expiry', function (done) {68 var newCookie = {name: "newcookie", value: "i'm new here"};69 var now = parseInt(Date.now() / 1000, 10);70 newCookie.expiry = now - 1000; // set cookie in past71 driver72 .deleteCookie(newCookie.name)73 .allCookies()74 .then(function (cookies) {75 _.pluck(cookies, 'name').should.not.include(newCookie.name);76 _.pluck(cookies, 'value').should.not.include(newCookie.value);77 })78 .then(function () {79 return driver80 .setCookie(newCookie)81 .allCookies();82 }).then(function (cookies) {83 // should not include cookie we just added because of expiry84 _.pluck(cookies, 'name').should.not.include(newCookie.name);85 _.pluck(cookies, 'value').should.not.include(newCookie.value);86 // should not clobber old cookies87 _.pluck(cookies, 'name').should.include("guineacookie1");88 _.pluck(cookies, 'value').should.include(_ignoreEncodingBug("i am a cookie value"));89 })90 .nodeify(done);91 });92 it('should be able to delete one cookie', function (done) {93 var newCookie = {name: "newcookie", value: "i'm new here"};94 driver95 .deleteCookie(newCookie.name)96 .allCookies()97 .then(function (cookies) {98 _.pluck(cookies, 'name').should.not.include(newCookie.name);99 _.pluck(cookies, 'value').should.not.include(newCookie.value);100 }).then(function () {101 return driver102 .setCookie(newCookie)103 .allCookies();104 }).then(function (cookies) {105 _.pluck(cookies, 'name').should.include(newCookie.name);106 _.pluck(cookies, 'value').should.include(newCookie.value);107 }).then(function () {108 return driver109 .deleteCookie('newcookie')110 .allCookies();111 }).then(function (cookies) {112 _.pluck(cookies, 'name').should.not.include(newCookie.name);113 _.pluck(cookies, 'value').should.not.include(newCookie.value);114 }).nodeify(done);115 });116 it('should be able to delete all cookie', function (done) {117 var newCookie = {name: "newcookie", value: "i'm new here"};118 driver119 .deleteCookie(newCookie.name)120 .allCookies()121 .then(function (cookies) {122 _.pluck(cookies, 'name').should.not.include(newCookie.name);123 _.pluck(cookies, 'value').should.not.include(newCookie.value);124 }).then(function () {125 return driver126 .setCookie(newCookie)127 .allCookies();128 }).then(function (cookies) {129 _.pluck(cookies, 'name').should.include(newCookie.name);130 _.pluck(cookies, 'value').should.include(newCookie.value);131 }).then(function () {132 return driver133 .deleteAllCookies()134 .allCookies();135 }).then(function (cookies) {136 cookies.length.should.equal(0);137 }).nodeify(done);138 });139 });140 });...

Full Screen

Full Screen

safari-cookie-e2e-specs.js

Source:safari-cookie-e2e-specs.js Github

copy

Full Screen

...22 });23 describe('within iframe webview', function () {24 it('should be able to get cookies for a page with none', async () => {25 await driver.get(GUINEA_PIG_IFRAME_PAGE);26 await driver.deleteAllCookies();27 await driver.get(GUINEA_PIG_IFRAME_PAGE);28 let cookies = await driver.allCookies();29 cookies.should.have.length(0);30 });31 });32 describe('within webview', function () {33 const newCookie = {34 name: 'newcookie',35 value: 'i am new here'36 };37 const oldCookie1 = {38 name: 'guineacookie1',39 value: 'i am a cookie value'40 };41 const oldCookie2 = {42 name: 'guineacookie2',43 value: 'cookié2'44 };45 let doesIncludeCookie = function (cookies, cookie) {46 cookies.map((c) => c.name).should.include(cookie.name);47 cookies.map((c) => c.value).should.include(cookie.value);48 };49 let doesNotIncludeCookie = function (cookies, cookie) {50 cookies.map((c) => c.name).should.not.include(cookie.name);51 cookies.map((c) => c.value).should.not.include(cookie.value);52 };53 beforeEach(async () => {54 await driver.get(GUINEA_PIG_PAGE);55 });56 it('should be able to get cookies for a page', async () => {57 let cookies = await driver.allCookies();58 cookies.length.should.equal(2);59 doesIncludeCookie(cookies, oldCookie1);60 doesIncludeCookie(cookies, oldCookie2);61 });62 it('should be able to set a cookie for a page', async () => {63 await driver.deleteCookie(newCookie.name);64 let cookies = await driver.allCookies();65 doesNotIncludeCookie(cookies, newCookie);66 await driver.setCookie(newCookie);67 cookies = await driver.allCookies();68 doesIncludeCookie(cookies, newCookie);69 // should not clobber old cookies70 doesIncludeCookie(cookies, oldCookie1);71 doesIncludeCookie(cookies, oldCookie2);72 });73 it('should be able to set a cookie with expiry', async () => {74 let expiredCookie = _.defaults({75 expiry: parseInt(Date.now() / 1000, 10) - 1000 // set cookie in past76 }, newCookie);77 await driver.deleteCookie(expiredCookie.name);78 let cookies = await driver.allCookies();79 doesNotIncludeCookie(cookies, expiredCookie);80 await driver.setCookie(expiredCookie);81 cookies = await driver.allCookies();82 // should not include cookie we just added because of expiry83 doesNotIncludeCookie(cookies, expiredCookie);84 // should not clobber old cookies85 doesIncludeCookie(cookies, oldCookie1);86 doesIncludeCookie(cookies, oldCookie2);87 });88 it('should be able to delete one cookie', async () => {89 await driver.deleteCookie(newCookie.name);90 let cookies = await driver.allCookies();91 doesNotIncludeCookie(cookies, newCookie);92 await driver.setCookie(newCookie);93 cookies = await driver.allCookies();94 doesIncludeCookie(cookies, newCookie);95 await driver.deleteCookie(newCookie.name);96 cookies = await driver.allCookies();97 doesNotIncludeCookie(cookies, newCookie);98 doesIncludeCookie(cookies, oldCookie1);99 doesIncludeCookie(cookies, oldCookie2);100 });101 it('should be able to delete all cookies', async () => {102 await driver.deleteCookie(newCookie.name);103 let cookies = await driver.allCookies();104 doesNotIncludeCookie(cookies, newCookie);105 await driver.setCookie(newCookie);106 cookies = await driver.allCookies();107 doesIncludeCookie(cookies, newCookie);108 await driver.deleteAllCookies();109 cookies = await driver.allCookies();110 cookies.length.should.equal(0);111 doesNotIncludeCookie(cookies, oldCookie1);112 doesNotIncludeCookie(cookies, oldCookie2);113 });114 });...

Full Screen

Full Screen

cookie.test.js

Source:cookie.test.js Github

copy

Full Screen

...41 * https://macacajs.github.io/macaca-wd/#deleteAllCookies42 */43 describe('deleteAllCookies', async () => {44 it('should work', async () => {45 await driver.deleteAllCookies();46 assert.equal(server.ctx.url, '/wd/hub/session/sessionId/cookie');47 assert.equal(server.ctx.method, 'DELETE');48 assert.deepEqual(server.ctx.request.body, {});49 assert.deepEqual(server.ctx.response.body, {50 sessionId: 'sessionId',51 status: 0,52 value: ''53 });54 });55 });56 /**57 * https://macacajs.github.io/macaca-wd/#deleteCookie58 */59 describe('deleteCookie', async () => {...

Full Screen

Full Screen

driver-service.js

Source:driver-service.js Github

copy

Full Screen

1'use strict';2const wd = require("wd");3const consoleLog = require('../helpers/console-log');4const driverService = require('./driver-service');5const fs = require('fs');6const driverInit = (options, done) => {7 const driver = wd.promiseChainRemote(options.serverConfig);8 require("../helpers/logging").configure(driver);9 let time = 0;10 function recInit() {11 time++;12 driver.init(options.desired, (err, sessionID, capabilities) => {13 if (err && (time < 5)) {14 consoleLog(err);15 setTimeout(function () {16 recInit();17 }, 62000);18 } else done(driver);19 });20 }21 recInit();22};23const driverQuit = (driver, suitePassed, sauceLabs, done) => {24 return driver25 .deleteAllCookies()26 .close()27 .quit()28 .finally(function () {29 if (sauceLabs) {30 return driver.sauceJobStatus(suitePassed, (err) => {31 if (err) consoleLog(err);32 done();33 });34 } else done();35 });36};37const driverAssure = (driver, options, done) => {38 driver.status((err, status) => {39 if (err) {40 consoleLog('RE-INIT A SESSION');41 driver.quit();42 driverService.init(options, (wd) => done(wd));43 } else done(driver);44 });45};46const takeScreenshot = (driver, site) => {47 driver.takeScreenshot((err, screenShot) => {48 const date = new Date();49 const fileName = `${site}_${date}.png`;50 consoleLog(fileName);51 consoleLog(fileName);52 fs.writeFile(`./screenshot/${fileName}`, screenShot, 'base64', function(err){53 if (err) consoleLog(err);54 })55 })56};57module.exports = {58 init: driverInit,59 quit: driverQuit,60 assure: driverAssure,61 takeScreenshot: takeScreenshot...

Full Screen

Full Screen

nonElementRelated.js

Source:nonElementRelated.js Github

copy

Full Screen

...20 driver.navigate().back();21 // Add a cookie to browser session22 driver.addCookie({'foo':'bar'});23 // Clear all cookies from browser session24 driver.deleteAllCookies();25 // Execute a javascript command26 driver.executeScript('javascript function');27 // Return page source28 driver.getPageSource();29 // Return current page url30 driver.getCurrentUrl();...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = { desiredCapabilities: { browserName: 'chrome' } };3var client = webdriverio.remote(options);4 .init()5 .deleteAllCookies()6 .end();7➜ webdriverio git:(master) ✗ node test.js8[0-0] COMMAND: POST /wd/hub/session {"desiredCapabilities":{"browserName":"chrome"}}9[0-0] DATA: {}10[0-0] RESULT: {"sessionId":"6e8a3c3d-6c0d-4f2a-a8f6-0b6b1c6d7f6e","status":0,"value":{"browserName":"chrome","browserVersion":"45.0.2454.101","chrome":{"chromedriverVersion":"2.18.343547 (2a5a5d7d5f9a5a7f5e5f5e7d5a5a5a5a5a5a5a5a)","userDataDir":"/var/folders/3q/0kq7m2_16zj8w2t2y6gj5f7h0000gn/T/.org.chromium.Chromium.9yJ0xR"},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"platform":"Mac OS X","rotatable":false,"takesHeapSnapshot":true,"takesScreenshot":true,"version":"45.0.2454.101","webStorageEnabled":true}}11[0-0] DATA: {}

Full Screen

Using AI Code Generation

copy

Full Screen

1var options = { desiredCapabilities: { browserName: 'chrome' } };2var client = webdriverio.remote(options);3 .init()4 .deleteAllCookies()5 .end();6➜ webdriverio git:(master) ✗ node test.js7[0-0] COMMAND: POST /wd/hub/session {"desiredCapabilities":{"browserName":"chrome"}}8[0-0] DATA: {}9[0-0] RESULT: {"sessionId":"6e8a3c3d-6c0d-5f2a-a8f6-0b6b1c6d7f6e","status":0,"value":{"browserName":"chrome","browserVersion":"45.0.2454.101","chrome":{"chromedriverVersion":"2.18.343547 (2a5a5d7d5f9a5a7f5e5f5e7d5a5a5a5a5a5a5a5a)","userDataDir":"/var/folders/3q/0kq7m2_16zj8w2t2y6gj5f7h0000gn/T/.org.chromium.Chromium.9yJ0xR"},"cssSelectorsEnabled":true,"databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":false,"javascriptEnabled":true,"locationContextEnabled":true,"mobileEmulationEnabled":false,"nativeEvents":true,"platform":"Mac OS X","rotatable":false,"takesHeapSnapshot":true,"takesScreenshot":true,"version":"45.0.2454.101","webStorageEnabled":true}}10[0-0] DATA: {}

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require(‘selenium-webdriver’);2var driver = new webdriver.Builder().forBrowser(‘chrome’).build();3driver.manage().deleteAllCookies();4driver.quit();5var webdriver = require(‘selenium-webdriver’);6var driver = new webdriver.Builder().forBrowser(‘chrome’).build();7driver.manage().deleteCookie(‘cookieName’);8driver.quit();9winw().maxmiz()Appwd10Get All Cookieswinow().sPstion()Appwd11window().sSz()Appwd12manag().wndow().gRec()wbdvr

Full Screen

Using AI Code Generation

copy

Full Screen

1iver.mange().timeouts().impicityWait() method of Appium wbriver2mana().indw().setR()wbdivb‘ser.m3.manage()wn().setRect()wdverwinw().maxmiz()Appwd4winow().sPstion()Appwd5iver.manage().window().getSizewondow().full creen()of Appium wAppverwd6manae().window().sR()wbderwinw().getPstion()Appwd7.manage()wdow().etRecmanag)().wdvdow().geeRec()wbdvr8mag().wdow().setRemt(manag.().window().gewRn(.()Rectmwebdrivdrwbdver9.mmana().idow().stRe()wbdiv10code to use driver.manama().w).dow().ietRect()ndow().setRect() mwdbdrivAm11mange().window().geRe()webder12manag().windw().getRct()webdir13.manage()wdow().eRct() webdriver() method of Appium webdriver14var driver = new webdriver.Builder().forBrowser(‘chrome’).build();15driver.manage().getAllCookies().then(function(cookies){16console.log(cookies);17});18driver.quit();19var webdriver = require(‘selenium-webdriver’);20var driver = new webdriver.Builder().for

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful