Best JavaScript code snippet using appium-xcuitest-driver
safari-basic-e2e-specs.js
Source:safari-basic-e2e-specs.js
...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 () {...
controllers.test.js
Source:controllers.test.js
...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();...
index.js
Source:index.js
...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...
cookies-base.js
Source:cookies-base.js
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 });...
safari-cookie-e2e-specs.js
Source:safari-cookie-e2e-specs.js
...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 });...
cookie.test.js
Source:cookie.test.js
...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 () => {...
driver-service.js
Source:driver-service.js
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...
nonElementRelated.js
Source:nonElementRelated.js
...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();...
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const should = chai.should();6const assert = chai.assert;7const expect = chai.expect;8const caps = {9};10driver.init(caps).then(function () {11 return driver.deleteAllCookies();12}).then(function () {13 console.log('Cookies deleted successfully');14});15[debug] [W3C (f1a4c0e1)] Calling AppiumDriver.deleteAllCookies() with args: [null,null]16[debug] [W3C (f1a4c0e1)] Encountered internal error running command: Error: Method ‘deleteAllCookies’ has not yet been implemented17[debug] [W3C (f1a4c0e1)] at XCUITestDriver.executeCommand (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/lib/commands/execute.js:28:13)18[debug] [W3C (f1a4c0e1)] at AppiumDriver.executeCommand (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/lib/appium.js:559:35)19[debug] [W3C (f1a4c0e1)] at processTicksAndRejections (internal/process/task_queues.js:97:5)20[debug] [W3C (f1a4c0e1)] at asyncHandler (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium
Using AI Code Generation
1const wdio = require("webdriverio");2const assert = require("assert");3const opts = {4 capabilities: {5 },6};7async function main() {8 const client = await wdio.remote(opts);9 await client.deleteAllCookies();10 await client.deleteSession();11}12main();13const wdio = require("webdriverio");14const assert = require("assert");15const opts = {16 capabilities: {17 },18};19async function main() {20 const client = await wdio.remote(opts);21 await client.deleteAllCookies();22 await client.deleteSession();23}24main();25deleteAllCookies()26deleteAllCookies()27deleteAllCookies()28deleteAllCookies()
Using AI Code Generation
1const wdio = require("webdriverio");2const opts = {3 capabilities: {4 }5};6async function main() {7 const client = await wdio.remote(opts);8 await client.deleteAllCookies();9 await client.deleteSession();10}11main();
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const expect = chai.expect;6const assert = chai.assert;7const should = chai.should();8const caps = {9};10driver.init(caps).then(async () => {11 await driver.deleteAllCookies();12 const cookies = await driver.getCookies();13 assert.equal(cookies.length, 0);14 await driver.quit();15});
Using AI Code Generation
1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const chaiExpect = chai.expect;5chai.use(chaiAsPromised);6const assert = chai.assert;7const path = require('path');8const { exec } = require('child_process');9const serverConfig = {10};11const caps = {12 app: path.resolve(__dirname, '../apps/UICatalog.app.zip'),13};14async function main() {15 const driver = await wd.promiseChainRemote(serverConfig);16 await driver.init(caps);17 await driver.deleteAllCookies();18 await driver.quit();19}20main();21const wd = require('wd');22const chai = require('chai');23const chaiAsPromised = require('chai-as-promised');24const chaiExpect = chai.expect;25chai.use(chaiAsPromised);26const assert = chai.assert;27const path = require('path');28const { exec } = require('child_process');29const serverConfig = {30};31const caps = {32 app: path.resolve(__dirname, '../apps/UICatalog.app.zip'),33};34async function main() {35 const driver = await wd.promiseChainRemote(serverConfig);36 await driver.init(caps);37 await driver.deleteAllCookies();38 await driver.quit();39}40main();41const wd = require('wd');42const chai = require('chai');43const chaiAsPromised = require('chai-as-promised');44const chaiExpect = chai.expect;45chai.use(chaiAsPromised);46const assert = chai.assert;47const path = require('path');48const { exec } = require('child_process');49const serverConfig = {
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('selenium')4 .build();5driver.deleteAllCookies()6 .then(function() {7 console.log('Cookies deleted');8 })9 .catch(function(err) {10 console.log('Error deleting cookies: ' + err);11 });12driver.quit();
Using AI Code Generation
1describe('Test', function() {2 it('should delete cookies', function() {3 browser.driver.deleteAllCookies();4 });5});6describe('Test', function() {7 it('should delete cookies', function() {8 browser.driver.deleteAllCookies();9 });10});11describe('Test', function() {12 it('should delete cookies', function() {13 browser.driver.deleteAllCookies();14 });15});16describe('Test', function() {17 it('should delete cookies', function() {18 browser.driver.deleteAllCookies();19 });20});21describe('Test', function() {22 it('should delete cookies', function() {23 browser.driver.deleteAllCookies();24 });25});26describe('Test', function() {27 it('should delete cookies', function() {28 browser.driver.deleteAllCookies();29 });30});31describe('Test', function() {32 it('should delete cookies', function() {33 browser.driver.deleteAllCookies();34 });35});36describe('Test', function() {37 it('should delete cookies', function() {38 browser.driver.deleteAllCookies();39 });40});41describe('Test', function() {42 it('should delete cookies', function() {43 browser.driver.deleteAllCookies();44 });45});46describe('Test', function() {47 it('should delete cookies', function() {48 browser.driver.deleteAllCookies();49 });50});51describe('Test', function() {52 it('should delete cookies', function() {53 browser.driver.deleteAllCookies();54 });55});56describe('Test', function() {57 it('should delete cookies', function() {58 browser.driver.deleteAllCookies();
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!