Best JavaScript code snippet using appium-xcuitest-driver
safari-basic-e2e-specs.js
Source:safari-basic-e2e-specs.js
...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 () {...
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 });...
myDriver.js
Source:myDriver.js
...87 } else if (frameworkFromArgument === 'framework:puppeteer') {88 if (argumentS._.includes('deleteCookies')) {89 if (browserFromArgument === 'browser:chrome') {90 let cookies = await driver.cookies();91 await driver.deleteCookie(...cookies);92 cookies = await driver.cookies();93 await driver.deleteCookie(...cookies);94 } else if (browserFromArgument === 'browser:firefox') {95 console.log('Delete Cookies not works on puppeteer firefox');96 }97 }98 await browser.close();99 }100 }...
cookies-specs.js
Source:cookies-specs.js
...28 let newCookie = {29 name: `newcookie`,30 value: `i'm new here`31 };32 await driver.deleteCookie(newCookie.name);33 let cookies = await driver.getCookies();34 cookies.map((c) => c.name).should.not.include(newCookie.name);35 cookies.map((c) => c.value).should.not.include(newCookie.value);36 await driver.setCookie(newCookie);37 cookies = await driver.getCookies();38 cookies.map((c) => c.name).should.include(newCookie.name);39 cookies.map((c) => c.value).should.include(newCookie.value);40 // should not clobber old cookies41 cookies.map((c) => c.name).should.include('guineacookie1');42 cookies.map((c) => c.value).should.include('i am a cookie value');43 });44 it('should be able to set a cookie with expiry', async function () {45 let newCookie = {46 name: `newcookie`,47 value: `i'm new here`48 };49 newCookie.expiry = parseInt(Date.now() / 1000, 10) - 1000; // set cookie in past50 await driver.deleteCookie(newCookie.name);51 let cookies = await driver.getCookies();52 cookies.map((c) => c.name).should.not.include(newCookie.name);53 cookies.map((c) => c.value).should.not.include(newCookie.value);54 await driver.setCookie(newCookie);55 cookies = await driver.getCookies();56 // should not include cookie we just added because of expiry57 cookies.map((c) => c.name).should.not.include(newCookie.name);58 cookies.map((c) => c.value).should.not.include(newCookie.value);59 // should not clobber old cookies60 cookies.map((c) => c.name).should.include('guineacookie1');61 cookies.map((c) => c.value).should.include('i am a cookie value');62 });63 it('should be able to delete one cookie', async function () {64 let newCookie = {65 name: `newcookie`,66 value: `i'm new here`67 };68 await driver.deleteCookie(newCookie.name);69 let cookies = await driver.getCookies();70 cookies.map((c) => c.name).should.not.include(newCookie.name);71 cookies.map((c) => c.value).should.not.include(newCookie.value);72 await driver.setCookie(newCookie);73 cookies = await driver.getCookies();74 cookies.map((c) => c.name).should.include(newCookie.name);75 cookies.map((c) => c.value).should.include(newCookie.value);76 await driver.deleteCookie('newcookie');77 cookies = await driver.getCookies();78 cookies.map((c) => c.name).should.not.include(newCookie.name);79 cookies.map((c) => c.value).should.not.include(newCookie.value);80 });81 it('should be able to delete all cookie', async function () {82 let newCookie = {83 name: `newcookie`,84 value: `i'm new here`85 };86 await driver.deleteCookie(newCookie.name);87 let cookies = await driver.getCookies();88 cookies.map((c) => c.name).should.not.include(newCookie.name);89 cookies.map((c) => c.value).should.not.include(newCookie.value);90 await driver.setCookie(newCookie);91 cookies = await driver.getCookies();92 cookies.map((c) => c.name).should.include(newCookie.name);93 cookies.map((c) => c.value).should.include(newCookie.value);94 await driver.deleteCookies();95 cookies = await driver.getCookies();96 cookies.length.should.equal(0);97 });98 });...
safari-cookie-e2e-specs.js
Source:safari-cookie-e2e-specs.js
...59 doesIncludeCookie(cookies, oldCookie1);60 doesIncludeCookie(cookies, oldCookie2);61 });62 it('should be able to set a cookie for a page', async function () {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 function () {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 function () {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 function () {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 });...
safari-ssl-e2e-specs.js
Source:safari-ssl-e2e-specs.js
...71 });72 beforeEach(async function () {73 await driver.get(LOCAL_HTTPS_URL);74 await driver.setCookie(oldCookie1);75 await driver.deleteCookie(secureCookie.name);76 });77 it('should be able to set a secure cookie', async function () {78 let cookies = await driver.allCookies();79 doesNotIncludeCookie(cookies, secureCookie);80 await driver.setCookie(secureCookie);81 cookies = await driver.allCookies();82 doesIncludeCookie(cookies, secureCookie);83 // should not clobber old cookie84 doesIncludeCookie(cookies, oldCookie1);85 });86 it('should be able to set a secure cookie', async function () {87 await driver.setCookie(secureCookie);88 let cookies = await driver.allCookies();89 doesIncludeCookie(cookies, secureCookie);90 // should not clobber old cookie91 doesIncludeCookie(cookies, oldCookie1);92 await driver.deleteCookie(secureCookie.name);93 cookies = await driver.allCookies();94 doesNotIncludeCookie(cookies, secureCookie);95 });96 });97 });...
cookie.test.js
Source:cookie.test.js
...57 * https://macacajs.github.io/macaca-wd/#deleteCookie58 */59 describe('deleteCookie', async () => {60 it('should work', async () => {61 await driver.deleteCookie('test_cookie');62 assert.equal(63 server.ctx.url,64 '/wd/hub/session/sessionId/cookie/test_cookie'65 );66 assert.equal(server.ctx.method, 'DELETE');67 assert.deepEqual(server.ctx.request.body, {});68 assert.deepEqual(server.ctx.response.body, {69 sessionId: 'sessionId',70 status: 0,71 value: ''72 });73 });74 });75 /**...
deleteCookies.js
Source:deleteCookies.js
...11 * @function deleteCookies12 * @param {String|String[]=} names - Cookie name or a list of cookie names to delete.13 */14module.exports = async function(names) {15 await this.driver.deleteCookie(names);...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .withCapabilities({4 })5 .build();6driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');7driver.findElement(webdriver.By.name('btnG')).click();8driver.wait(function() {9 return driver.getTitle().then(function(title) {10 return title === 'webdriver - Google Search';11 });12}, 1000);13driver.deleteCookie('myCookie');14driver.quit();
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;7let driver;8let allPassed = true;9let desiredCaps = {10};11describe('iOS Test', function () {12 this.timeout(300000);13 before(async () => {14 await driver.init(desiredCaps);15 await driver.sleep(3000);16 });17 after(async () => {18 await driver.quit();19 });20 afterEach(function () {21 allPassed = allPassed && this.currentTest.state === 'passed';22 });23 it('should delete cookie', async () => {24 let cookie = {25 };26 await driver.setCookie(cookie);27 await driver.deleteCookie('test');28 let cookies = await driver.getCookies();29 assert.equal(cookies.length, 0);30 });31});32* Appium version (or git revision) that exhibits the issue: 1.11.133* Last Appium version that did not exhibit the issue (if applicable):34* Node.js version (unless using Appium.app|exe): v10.15.0
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.pause(3000);10 await client.deleteCookie("NID");11 await client.pause(3000);12 const cookies = await client.getCookies();13 console.log(cookies);14 assert.strictEqual(cookies.length, 0);15}16main();17* Appium version (or git revision) that exhibits the issue: 1.16.0-beta.118* Node.js version (unless using Appium.app|exe): v10.16.3
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('selenium')4 .build();5driver.manage().deleteCookie('NID');6driver.quit();7var webdriver = require('selenium-webdriver');8var driver = new webdriver.Builder()9 .forBrowser('selenium')10 .build();11driver.manage().deleteAllCookies();12driver.quit();13var webdriver = require('selenium-webdriver');14var driver = new webdriver.Builder()15 .forBrowser('selenium')16 .build();17driver.manage().deleteCookie('NID');18driver.quit();19var webdriver = require('selenium-webdriver');20var driver = new webdriver.Builder()21 .forBrowser('selenium')22 .build();23driver.manage().deleteAllCookies();24driver.quit();25var webdriver = require('selenium-webdriver');26var driver = new webdriver.Builder()27 .forBrowser('selenium')28 .build();29driver.manage().deleteCookie('NID');30driver.quit();31var webdriver = require('selenium-webdriver');32var driver = new webdriver.Builder()33 .forBrowser('selenium')34 .build();35driver.manage().deleteAllCookies();36driver.quit();37var webdriver = require('selenium-webdriver');38var driver = new webdriver.Builder()39 .forBrowser('selenium')40 .build();41driver.manage().deleteCookie('NID');42driver.quit();43var webdriver = require('selenium-webdriver');44var driver = new webdriver.Builder()45 .forBrowser('selenium')46 .build();
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.setCookies({10 });11 let cookies = await client.getCookies();12 console.log(cookies);13 await client.deleteCookie('test');14 cookies = await client.getCookies();15 console.log(cookies);16 await client.deleteCookies();17 cookies = await client.getCookies();18 console.log(cookies);19 await client.deleteCookies();20 await client.deleteCookie('test');21 await client.deleteCookie('test');22 await client.deleteCookies();23 await client.deleteCookies();24 await client.deleteCookies();25 await client.deleteCookie('test');
Using AI Code Generation
1describe('deleteCookie', function () {2 it('should delete a cookie', async function () {3 await driver.deleteCookie('cookieName');4 });5});6describe('deleteAllCookies', function () {7 it('should delete all cookies', async function () {8 await driver.deleteAllCookies();9 });10});11describe('getCookies', function () {12 it('should get all cookies', async function () {13 let cookies = await driver.getCookies();14 });15});16describe('setOrientation', function () {17 it('should set the orientation to LANDSCAPE', async function () {18 await driver.setOrientation('LANDSCAPE');19 });20});21describe('getOrientation', function () {22 it('should get the orientation', async function () {23 let orientation = await driver.getOrientation();24 });25});26describe('backgroundApp', function () {27 it('should background the app for 5 seconds', async function () {28 await driver.backgroundApp(5);29 });30});31describe('closeApp', function () {32 it('should close the app', async function () {33 await driver.closeApp();34 });35});36describe('resetApp', function () {37 it('should reset the app', async function () {38 await driver.resetApp();39 });40});41describe('launchApp', function () {42 it('should launch the app', async function () {43 await driver.launchApp();44 });45});46describe('installApp
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!!