How to use getAndExpireCookiesForRedirectTest method in wpt

Best JavaScript code snippet using wpt

cookie-test.js

Source:cookie-test.js Github

copy

Full Screen

...21 });22}23// getAndExpireCookiesForRedirectTest is a helper method to get and delete24// cookies that were set from a Location header redirect.25async function getAndExpireCookiesForRedirectTest(location) {26 return new Promise((resolve, reject) => {27 try {28 const iframe = document.createElement('iframe');29 iframe.style = 'display: none';30 iframe.src = location;31 const listener = (e) => {32 if (typeof e.data == 'object' && 'cookies' in e.data) {33 window.removeEventListener('message', listener);34 document.documentElement.removeChild(iframe);35 resolve(e.data.cookies);36 }37 };38 window.addEventListener('message', listener);39 iframe.addEventListener('load', (e) => {40 e.target.contentWindow.postMessage('getAndExpireCookiesForRedirectTest', '*');41 }, {once: true});42 document.documentElement.appendChild(iframe);43 } catch (e) {44 reject(e);45 }46 });47}48// httpCookieTest sets a `cookie` (via HTTP), then asserts it was or was not set49// via `expectedValue` (via the DOM). Then cleans it up (via test driver). Most50// tests do not set a Path attribute, so `defaultPath` defaults to true.51//52// `cookie` may be a single cookie string, or an array of cookie strings, where53// the order of the array items represents the order of the Set-Cookie headers54// sent by the server.55//56// Note: this function has a dependency on testdriver.js. Any test files calling57// it should include testdriver.js and testdriver-vendor.js58function httpCookieTest(cookie, expectedValue, name, defaultPath = true) {59 return promise_test(async (t) => {60 // The result is ignored as we're expiring cookies for cleaning here.61 await getAndExpireCookiesForDefaultPathTest();62 await test_driver.delete_all_cookies();63 t.add_cleanup(test_driver.delete_all_cookies);64 let encodedCookie = encodeURIComponent(JSON.stringify(cookie));65 await fetch(`/cookies/resources/cookie.py?set=${encodedCookie}`);66 let cookies = document.cookie;67 if (defaultPath) {68 // for the tests where a Path is set from the request-uri69 // path, we need to go look for cookies in an iframe at that70 // default path.71 cookies = await getAndExpireCookiesForDefaultPathTest();72 }73 if (Boolean(expectedValue)) {74 assert_equals(cookies, expectedValue, 'The cookie was set as expected.');75 } else {76 assert_equals(cookies, expectedValue, 'The cookie was rejected.');77 }78 }, name);79}80// This is a variation on httpCookieTest, where a redirect happens via81// the Location header and we check to see if cookies are sent via82// getRedirectedCookies83//84// Note: the locations targeted by this function have a dependency on85// path-redirect-shared.js and should be sure to include it.86function httpRedirectCookieTest(cookie, expectedValue, name, location) {87 return promise_test(async (t) => {88 // The result is ignored as we're expiring cookies for cleaning here.89 await getAndExpireCookiesForRedirectTest(location);90 const encodedCookie = encodeURIComponent(JSON.stringify(cookie));91 const encodedLocation = encodeURIComponent(location);92 const setParams = `?set=${encodedCookie}&location=${encodedLocation}`;93 await fetch(`/cookies/resources/cookie.py${setParams}`);94 // for the tests where a redirect happens, we need to head95 // to that URI to get the cookies (and then delete them there)96 const cookies = await getAndExpireCookiesForRedirectTest(location);97 if (Boolean(expectedValue)) {98 assert_equals(cookies, expectedValue, 'The cookie was set as expected.');99 } else {100 assert_equals(cookies, expectedValue, 'The cookie was rejected.');101 }102 }, name);103}104// Sets a `cookie` via the DOM, checks it against `expectedValue` via the DOM,105// then cleans it up via the DOM. This is needed in cases where going through106// HTTP headers may modify the cookie line (e.g. by stripping control107// characters).108//109// Note: this function has a dependency on testdriver.js. Any test files calling110// it should include testdriver.js and testdriver-vendor.js...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var wptdriver = require('./wptdriver.js');3var cookie = {name: 'test', value: '123', domain: 'www.google.com', path: '/', expiry: 10000000000};4driver.get(url).then(function() {5 driver.manage().addCookie(cookie);6 driver.get(url).then(function() {7 driver.quit();8 });9});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('./wptdriver.js');2exports.getAndExpireCookiesForRedirectTest = function(url){3 var driver = new webdriver.Builder().forBrowser('chrome').build();4 driver.get(url);5 driver.manage().getCookies().then(function(cookies){6 console.log(cookies);7 });8 driver.manage().deleteAllCookies();9 driver.manage().getCookies().then(function(cookies){10 console.log(cookies);11 });12 driver.close();13}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptdriver = require('./wptdriver.js');2var wpt = new wptdriver();3 if(err) {4 console.log(err);5 } else {6 console.log(cookies);7 }8});9var webdriver = require('selenium-webdriver');10var By = webdriver.By;11var until = webdriver.until;12var wptdriver = function() {};13wptdriver.prototype.getAndExpireCookiesForRedirectTest = function(url, callback) {14 var driver = new webdriver.Builder().forBrowser('chrome').build();15 driver.get(url);16 driver.manage().getCookies().then(function(cookies) {17 driver.quit();18 callback(null, cookies);19 });20};21module.exports = wptdriver;22var webdriver = require('selenium-webdriver');23var By = webdriver.By;24var until = webdriver.until;25var wptdriver = function() {};26wptdriver.prototype.getAndExpireCookiesForRedirectTest = function(url, callback) {27 var driver = new webdriver.Builder().forBrowser('chrome').build(

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('./wpt_driver.js');2var cookies = wpt.getAndExpireCookiesForRedirectTest(url);3console.log(cookies);4var webdriver = require('selenium-webdriver');5var By = webdriver.By;6var until = webdriver.until;7var wpt = {};8wpt.getAndExpireCookiesForRedirectTest = function(url) {9 var driver = new webdriver.Builder()10 .forBrowser('chrome')11 .build();12 driver.get(url);13 driver.wait(until.titleContains('Google'), 10000);14 var cookies = driver.manage().getCookies();15 driver.quit();16 return cookies;17};18module.exports = wpt;19 throw new Error('Server returned code ' + response.status +20Error: Server returned code 500, response body was: {"message":"unknown error: Chrome failed to start: exited abnormally\n (unknown error: DevToolsActivePort file doesn't exist)\n (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)\n\n (Driver info: chromedriver=2.35.528139 (f6e1b4a4a4d4a4b4d4f4b4a4b4a4e4e4f4a4e4f4),platform=Linux 4.4.0-53-generic x86_64)"}21 at Object.throwDecodedError (/home/ashok/Downloads/redirect_test/node_modules/selenium-webdriver/lib/http.js:589:11)22 at parseHttpResponse (/home/ashok/Downloads/redirect_test/node_modules/selenium-webdriver/lib/http.js:517:13)23 at ClientRequest.<anonymous> (/home/ashok/Downloads/redirect_test/node_modules/selenium-webdriver/lib/http.js:441:11)24 at emitOne (events.js:101:20)25 at ClientRequest.emit (events.js:188:7)26 at TLSSocket.socketOnData (_http_client.js:366:9)27 at emitOne (events.js:96:13

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 wpt 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