Skip to content

Commit

Permalink
test: validate headless reading cookies written by headful (puppeteer…
Browse files Browse the repository at this point in the history
…#1266)

This test ensures that Chrome Headless can successfully read cookies written
by Chrome Headful.

References puppeteer#921
  • Loading branch information
aslushnikov authored Nov 3, 2017
1 parent cee3081 commit f08f334
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ cache:
yarn: true
directories:
- node_modules
# allow headful tests
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
install:
- yarn install
# puppeteer's install script downloads Chrome
Expand Down
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,26 @@ describe('Puppeteer', function() {
await browser2.close();
rm(userDataDir);
}));
xit('headless should be able to read cookies written by headful', SX(async function() {
const userDataDir = fs.mkdtempSync(path.join(__dirname, 'test-user-data-dir'));
const options = Object.assign({userDataDir}, defaultBrowserOptions);
// Write a cookie in headful chrome
options.headless = false;
const headfulBrowser = await puppeteer.launch(options);
const headfulPage = await headfulBrowser.newPage();
await headfulPage.goto(EMPTY_PAGE);
await headfulPage.evaluate(() => document.cookie = 'foo=true; expires=Fri, 31 Dec 9999 23:59:59 GMT');
await headfulBrowser.close();
// Read the cookie from headless chrome
options.headless = true;
const headlessBrowser = await puppeteer.launch(options);
const headlessPage = await headlessBrowser.newPage();
await headlessPage.goto(EMPTY_PAGE);
const cookie = await headlessPage.evaluate(() => document.cookie);
await headlessBrowser.close();
rm(userDataDir);
expect(cookie).toBe('foo=true');
}));
});
describe('Puppeteer.connect', function() {
it('should be able to connect multiple times to the same browser', SX(async function() {
Expand Down

0 comments on commit f08f334

Please sign in to comment.