|
| 1 | +// Copyright 2023-2024 Lightpanda (Selecy SAS) |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +'use scrict' |
| 15 | + |
| 16 | +import puppeteer from 'puppeteer-core'; |
| 17 | +import assert from 'assert'; |
| 18 | + |
| 19 | +const browser = await puppeteer.connect({ |
| 20 | + browserWSEndpoint: 'ws://127.0.0.1:9222', |
| 21 | +}); |
| 22 | + |
| 23 | +const context = await browser.createBrowserContext(); |
| 24 | +const page = await context.newPage(); |
| 25 | + |
| 26 | +await context.setCookie({name: 'manual', value: 'A', url: "https://httpbin.io/cookies", path:"/cookies"}); |
| 27 | + |
| 28 | +const response = await page.goto("https://httpbin.io/cookies/set?manual=B", {waitUntil: 'load'}); |
| 29 | + |
| 30 | +const cookies = await context.cookies(); |
| 31 | + |
| 32 | +// we expect having one cookie set with name `manual` and `B1 value. |
| 33 | +assert.strictEqual(1, cookies.length, 'Exactly one cookie is set'); |
| 34 | +assert.strictEqual('manual', cookies[0].name, 'Cookie name is manual'); |
| 35 | +assert.strictEqual('B', cookies[0].value, 'Cookie value is B'); |
| 36 | + |
| 37 | +// check the httpbin output from the srv POV. |
| 38 | +const element = await page.$('pre'); |
| 39 | +const pre = await page.evaluate(el => el.textContent, element); |
| 40 | +const obj = JSON.parse(pre); |
| 41 | +assert.equal(obj.manual, "B"); |
| 42 | + |
| 43 | +await page.close(); |
| 44 | +await context.close(); |
| 45 | +await browser.disconnect(); |
0 commit comments