Best JavaScript code snippet using appium
safari-basic-e2e-specs.js
Source:safari-basic-e2e-specs.js
...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 });...
instagram.js
Source:instagram.js
...35 await this.driver.removeCookie('mid');36 await this.driver.removeCookie('sessionid');37 await this.driver.removeCookie('ig_did');38 await this.driver.removeCookie('csrftoken');39 await this.driver.setCookie({ name: 'ig_did', value: sessionFile.ig_did, 'sameSite': 'Strict' });40 await this.driver.setCookie({ name: 'sessionid', value: sessionFile.sessionid, 'sameSite': 'Strict' });41 await this.driver.setCookie({ name: 'ds_user_id', value: sessionFile.ds_user_id, 'sameSite': 'Strict' });42 await this.driver.setCookie({ name: 'mid', value: sessionFile.mid, 'sameSite': 'Strict' });43 await this.driver.setCookie({ name: 'csrftoken', value: sessionFile.csrftoken, 'sameSite': 'Strict' });44 this.driver.sleep(6);45 await this.driver.openUrl("https://www.instagram.com/");46 }47 /**48 * @param {string} username49 * @param {string} password50 * @param {string} path51 */52 async normalLogin(username, password, path) {53 let url = 'https://www.instagram.com/accounts/login/';54 await this.driver.openUrl(url);55 let inputs = 'form input';56 var element = await this.driver.getElements('css', inputs);57 await this.driver.type(element[0], username);...
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 });...
cookies-specs.js
Source:cookies-specs.js
...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
...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 });...
safari-ssl-e2e-specs.js
Source:safari-ssl-e2e-specs.js
...70 driver = await initSession(caps);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 });...
ios-safari.js
Source:ios-safari.js
...45 it("should delete cookie passing domain and path", function () {46 var complexCookieDelete = function(name, path, domain) {47 return function() {48 path = path || '|';49 return driver.setCookie({name: name, value: '', path: path, 50 domain: domain, expiry: 0}); 51 };52 };53 return driver54 .get('http://en.wikipedia.org')55 .waitForElementByCss('.mediawiki', 5000)56 .allCookies() // 'GeoIP' cookie is there57 .deleteCookie('GeoIP') 58 .allCookies() // 'GeoIP' is still there, because it is set on59 // the .wikipedia.org domain60 .then(complexCookieDelete('GeoIP', '/', '.wikipedia.org'))61 .allCookies() // now 'GeoIP' cookie is gone62 .sleep(1000);63 });...
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('chrome')4 .build();5driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');6driver.findElement(webdriver.By.name('btnG')).click();7driver.wait(function() {8 return driver.getTitle().then(function(title) {9 return title === 'webdriver - Google Search';10 });11}, 1000);12driver.manage().addCookie({name: 'cookie1', value: 'value1'});13driver.manage().addCookie({name: 'cookie2', value: 'value2'});14driver.manage().getCookies().then(function(cookies) {15 console.log('Cookies: ', cookies);16});17driver.quit();18Cookies: [ { name: 'cookie1', value: 'value1' },19 { name: 'cookie2', value: 'value2' } ]
Using AI Code Generation
1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().forBrowser('chrome').build();3driver.manage().addCookie({4});5driver.quit();6var webdriver = require('selenium-webdriver');7var driver = new webdriver.Builder().forBrowser('chrome').build();8driver.manage().addCookie({9});10driver.manage().deleteAllCookies();11driver.quit();12var webdriver = require('selenium-webdriver');13var driver = new webdriver.Builder().forBrowser('chrome').build();14driver.manage().addCookie({15});16driver.manage().deleteCookie('test');17driver.quit();18var webdriver = require('selenium-webdriver');19var driver = new webdriver.Builder().forBrowser('chrome').build();20driver.manage().addCookie({21});22driver.manage().getCookie('test').then(function(cookie) {23 console.log(cookie);24});25driver.quit();26var webdriver = require('selenium-webdriver');27var driver = new webdriver.Builder().forBrowser('chrome').build();28driver.manage().addCookie({29});
Using AI Code Generation
1driver.setCookie({name: 'cookieName', value: 'cookieValue'}).then(function() {2 driver.getCookie('cookieName').then(function(cookie) {3 console.log(cookie);4 });5});6driver.setCookie({name: 'cookieName', value: 'cookieValue'}).then(function() {7 driver.getCookie('cookieName').then(function(cookie) {8 console.log(cookie);9 });10});11driver.setCookie({name: 'cookieName', value: 'cookieValue'}).then(function() {12 driver.getCookie('cookieName').then(function(cookie) {13 console.log(cookie);14 });15});16driver.setCookie({name: 'cookieName', value: 'cookieValue'}).then(function() {17 driver.getCookie('cookieName').then(function(cookie) {18 console.log(cookie);19 });20});21driver.setCookie({name: 'cookieName', value: 'cookieValue'}).then(function() {22 driver.getCookie('cookieName').then(function(cookie) {23 console.log(cookie);24 });25});26driver.setCookie({name: 'cookieName', value: 'cookieValue'}).then(function() {27 driver.getCookie('cookieName').then(function(cookie) {28 console.log(cookie);29 });30});31driver.setCookie({name: 'cookieName', value: 'cookieValue
Using AI Code Generation
1const driver = require('webdriverio').remote(options);2driver.init();3driver.setCookie({name: 'cookieName', value: 'cookieValue'});4driver.deleteCookie('cookieName');5const driver = require('webdriverio').remote(options);6driver.init();7driver.getCookies();8const driver = require('webdriverio').remote(options);9driver.init();10driver.deleteAllCookies();11const driver = require('webdriverio').remote(options);12driver.init();13driver.getWindowHandles();14const driver = require('webdriverio').remote(options);15driver.init();16driver.getWindowHandle();17const driver = require('webdriverio').remote(options);18driver.init();19driver.switchToWindow('windowHandle');20const driver = require('webdriverio').remote(options);21driver.init();22driver.closeWindow('windowHandle');23const driver = require('webdriverio').remote(options);24driver.init();25driver.openNotifications();26const driver = require('webdriverio').remote(options);27driver.init();28driver.getOrientation();29const driver = require('webdriverio').remote(options);30driver.init();31driver.setOrientation('LANDSCAPE');32const driver = require('webdriverio').remote(options);33driver.init();34driver.getGeoLocation();35const driver = require('webdriverio').remote(options);36driver.init();37driver.setGeoLocation({latitude: 40.7143528, longitude: -74.0059731, altitude: 100});38const driver = require('webdriverio
Using AI Code Generation
1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setCapability("platformName", "iOS");3capabilities.setCapability("platformVersion", "10.3");4capabilities.setCapability("deviceName", "iPhone 7");5capabilities.setCapability("browserName", "Safari");6DesiredCapabilities capabilities = new DesiredCapabilities();7capabilities.setCapability("platformName", "iOS");8capabilities.setCapability("platformVersion", "10.3");9capabilities.setCapability("deviceName", "iPhone 7");10capabilities.setCapability("browserName", "Chrome");11DesiredCapabilities capabilities = new DesiredCapabilities();12capabilities.setCapability("platformName", "iOS");13capabilities.setCapability("platformVersion", "10.3");14capabilities.setCapability("deviceName", "iPhone 7");15capabilities.setCapability("browserName", "Edge");16DesiredCapabilities capabilities = new DesiredCapabilities();17capabilities.setCapability("platformName", "iOS");18capabilities.setCapability("platformVersion", "10.3");19capabilities.setCapability("deviceName", "iPhone 7");20capabilities.setCapability("browserName", "Firefox");
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!!