Commit Graph

837 Commits

Author SHA1 Message Date
dmitrysteblyuk
fb859115c0
fix: do not use old utility world (#6528)
Don’t use the old utility world, as it is being destroyed later when browser reconnects to the page.

Issue: #6527
2020-11-26 12:43:42 +01:00
Michael Kebede
b57f3fcd53
feat: support promise as return value for page.waitForResponse predicate (#6624)
Co-authored-by: Joni <josalmi@google.com>
2020-11-25 11:35:47 +01:00
Jack Franklin
659193a4f5
chore: mark launcher spec as failing on Windows (#6574)
We've pushed this date back a lot, let's make it permanent until we have
more time to investigate.
2020-11-03 10:11:29 +00:00
Peter Thaleikis
3bb417b14b
chore: fix typo in test (#6566) 2020-11-01 09:43:07 +01:00
Johan Bay
729cdfe98a
chore: mark version v5.4.0 (#6542) 2020-10-23 16:28:38 +02:00
Jack Franklin
e655bb6ca2
chore(agnostification): split up root Puppeteer class (#6504)
The `Puppeteer` class had two concerns:

* connect to an existing browser
* launch a new browser

The first of those concerns is needed in all environments, but the
second is only needed in Node.
https://github.com/puppeteer/puppeteer/pull/6484 landing enabled us to
pull the `Puppeteer` class apart into two:

1. `Puppeteer` which hosts the behaviour for connecting to existing
   browsers.
2. `PuppeteerNode`, which extends `Puppeteer` and also adds the ability
   to launch a new browser.

This is a non-breaking change, because Node users will still get an
instance of a class with all the methods they expect, but it'll be a
`PuppeteerNode` rather than `Puppeteer`. I don't expect this to cause
people any issues.

We also now have new files that are effectively the entry points for
Puppeteer:

* `node.ts`: the main entry point for Puppeteer on Node.
* `web.ts`: the main entry point for Puppeteer on the web.
* `node-puppeteer-core.ts`: for those using puppeteer-core (which only
  exists in Node, not on the web).
2020-10-13 16:19:26 +01:00
Ralf Vogler
f3086d7c97
fix(launcher): support relative userDataDir on headless Windows (#6506)
Launching headless with a relative `userDataDir` hangs on Windows. Fix by calling `path.resolve` (idempotent) to add an absolute path instead in `defaultArgs`.

Issues: #3453
2020-10-13 12:59:58 +02:00
Johan Bay
8fabe32800
feat(queryhandler): add built-in pierce handler (#6509)
Adds a handler 'pierce' that pierces shadow roots while querying.
2020-10-13 11:05:47 +02:00
Jack Franklin
f04bec5a15
chore: update eslint & eslint plugins (#6487)
Updates ESLint, the TypeScript ESLint plugins, and updates code where
the rules have changed.
2020-10-12 10:30:35 +01:00
Jack Franklin
4846b8723c
chore(agnostification): split up launcher class (#6484)
The `Launcher` class was serving two purposes:

1. Launch browsers
2. Connect to browsers

Number 1) only needs to be done in Node land, but 2) is agnostic; in a
browser version of Puppeteer we'll need the ability to connect over a
websocket to send commands back and forth.

As part of the agnostification work we needed to split the `Launcher` up
so that the connection part can be made agnostic. Additionally, I
removed dependencies on `https`, `http` and `URL` from Node, instead
leaning on fetch (via `node-fetch` if in Node land) and the browser
`URL` API (which was added to Node in Node 10).
2020-10-12 10:08:57 +01:00
Johan Bay
3afe1935da
feat(a11y-query): extend aria handler with waitFor (#6472)
This commit adds waitFor to the built-in aria handler (#6307).
2020-10-07 10:49:11 +02:00
Johan Bay
950ae334ca
feat(a11y-query): aria query handler sans waitfor (#6459)
This commit adds a new built-in handler for querying by accessible name and role (#6307).
Support for waitForSelector will be added in a follow-up commit.
2020-10-05 08:25:55 +02:00
Maja Frydrychowicz
41ef3eec90
fix: update preferences in default Firefox profile (#6465) 2020-10-05 07:17:21 +02:00
Johan Bay
49f25e2412
feat(chromium) roll Chromium to r809590 (#6458)
This corresponds to Chromium 87.0.4272.0
This roll includes:
- Reland "idle-detection: Implement requestPermission() method"
  (crrev.com/c/2417779)
2020-10-01 08:24:47 +02:00
Maja Frydrychowicz
4cdbebe1ac
chore: disable firefox windows launcher test until Nov (#6451) 2020-09-29 16:04:07 +01:00
Jack Franklin
caa9a1cafa
chore(agnostic): Remove use of util.promisify (#6446)
In `src/common` we now use `fs.promises.X` which we can dynamically
`import`. In a browser environment this code will never run because it's
gated on `isNode` (in a future PR we will add tree-shaking to the bundle
step such that this code is eliminated). By using `import`, we ensure
TypeScript still can track types and give good type information.

In `src/node` we continue to use `util.promisify` but that's not a
concern as that code explicitly is never run in the browser.
2020-09-28 10:35:35 +01:00
Yang Guo
96f3d439f5
feat(console): expose stack trace for console messages (#6445) 2020-09-25 15:27:13 +02:00
Johan Bay
72fe86fe6a
feat(a11y-query): introduce internal handlers (#6437)
This commit changes the internal representation of query handlers to contain Puppeteer-level code instead of page functions.
The interface `CustomQueryHandler` is introduced for user-defined query handlers. When a `CustomQueryHandler` is registered using  `registerCustomQueryHandler` a corresponding Puppeteer-level handler is created through `makeQueryHandler` by wrapping the page functions as appropriate.
The internal query handlers (defined by the interface `QueryHandler`) contain two new functions: `waitFor` and `queryAllArray`.
- `waitFor` allows page-based handlers to make use of the `WaitTask`-backed implementation in `DOMWorld`, whereas purely Puppeteer-based handlers can define an alternative approach instead.
- `queryAllArray` is similar to `queryAll` but with a slightly different interface; it returns a `JSHandle` to an array with the results as opposed to an array of `ElementHandle`. It is used by `$$eval`. 

After this change, we can introduce built-in query handlers that are not executed in the page context (#6307).
2020-09-23 16:02:22 +02:00
Johan Bay
b1c3efaa34
feat(a11y-query): split waitFor logic for selectors and xpath (#6426)
The logic for waitForXPath and waitForSelector is currently very tightly coupled. This commit tries to untangle that relationship. This is the first step towards introducing built-in query handlers that are not executed in the page context (#6307).
2020-09-21 15:47:33 +02:00
campersau
083ea41e94
test(frame): correct terminology in URL fragment test (#6416)
Bug: #6398
2020-09-14 13:42:32 +02:00
Maksim Sadym
17960e5d8d
feat(page): emulate idle state (#6410)
* https://bugs.chromium.org/p/chromium/issues/detail?id=1090802
* added `page.emulateIdleState(...)` allowing emulate or remove emulation of the idle state;
* added test `emulate idle` -> `remove emulation` -> `emulate idle` -> `remove emulation`;
* added launch argument `--enable-blink-features=IdleDetection` to turn IdleDetection on.
2020-09-14 11:31:23 +02:00
Mathias Bynens
e22ca4c7c4
chore: extend Firefox launch test deadline by a month (#6403)
Ref. #5673.
2020-09-08 15:08:23 +02:00
Bryan Maloyer
b6bbfd0ede
fix: ensure frame.url() includes the query string (#6398)
Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-09-08 10:49:44 +02:00
Maja Frydrychowicz
054d782c82
fix(Launcher): use wait-for-process Firefox option (#6315) 2020-08-10 10:23:17 +02:00
Christian Bromann
9bc063b5ef
chore: assert location value of ConsoleMessage in tests (#6282) 2020-07-29 12:13:50 +01:00
Jack Franklin
21552f8fe7
feat: page.waitForTimeout (#6268) 2020-07-28 10:37:49 +02:00
Christian Bromann
8c1a5866c5
fix: handle promise for reading protocol stream of trace (#6270) 2020-07-23 16:21:15 +02:00
Johan Bay
e89e264a16
feat(chromium): roll Chromium to r782078 (#6250)
This corresponds to Chromium 85.0.4182.0.

This roll includes: 
- Enable SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure
   https://crrev.com/c/2231445
- [FlexNG] Enable FlexNG by default
   https://crrev.com/c/2216595

Closes #6151.
2020-07-20 17:17:06 +02:00
Johan Bay
313774c553
feat: change QueryHandler to contain QueryOne and QueryAll methods (#6218)
Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-07-17 07:29:42 +02:00
Jack Franklin
f1a6b8d66d
chore: vendor Mitt & update project structure (#6209)
* chore: vendor Mitt into src/common/third-party

As discussed in #6203 we need to vendor our common dependencies in so
that when we ship an ESM build all imports point to file paths and do
not rely on Node resolution (e.g. a browser does not understand `import
mitt from 'mitt'`).
2020-07-14 16:57:29 +01:00
Jack Franklin
ffec2475d0
chore: enforce file extensions on imports (#6202)
* chore: enforce file extensions on imports

To make our output agnostic it should include file extensions in the
output, as per the ESM spec. It's a bit odd for Node packages but makes
it easier to publish a browser build.
2020-07-13 10:22:26 +01:00
Changhao Han
790c277f0e
feat(chromium): roll Chromium to r768783 (#6201)
* feat(chromium): roll Chromium to r768783

* fix: update unit test for crrev:2135046

* chore: update devtools-protocol revision

Co-authored-by: Changhao Han <changhaohan@chromium.org>
2020-07-10 15:32:44 +02:00
Jack Franklin
9b3005c105
feat(types): improve page.evaluate types (#6193) 2020-07-10 11:52:13 +01:00
Jack Franklin
f666be3f5f
chore: remove src/api.ts (#6191)
Now the async hooks helper is gone api.ts was only used by the coverage
tools and by doclint.

DocLint is nearing the end of its lifespan with the TSDoc work, so I
focused on how best to define a list of modules for the coverage
tooling. They define an object of classes, and the path to that module.
They need the full path because we also check if the module exports any
events that need to be emitted - the coverage tool asserts that the
emitting of those events is also tested.

It's not _great_ that DocLint relies on a constant defined in the
coverage utils, but it should only be this way for a short period of
time and no one is actively working on DocLint (bar the effort to remove
it) so I don't think this is worth worrying about.

This change also broke the DocLint tests; based on the fact that DocLint is on its way out it doesn't feel worth fixing the tests, so this commit also removes them.
2020-07-10 10:07:28 +01:00
Jack Franklin
12434663e2
chore: remove installAsyncStackHooks helper (#6186)
* chore: remove `installAsyncStackHooks` helper

This code was written when browsers/Node didn't support errors in async
functions very well. They now do a much better job of this, so we can
lose the additonal complexity from our codebase and leave it to the host
environment :)

* lazy launcher is private

* remove async stack test
2020-07-09 11:38:25 +01:00
Christian Bromann
e67a860eb0
feat: add Mouse#wheel (#6141) 2020-07-06 09:27:17 +02:00
Jack Franklin
5049b83186
feat(types): add types for page.$$eval (#6139)
* feat(types): add types for `page.$$eval`

* Add new-docs for $$eval

* fix example

* linting
2020-07-03 15:23:51 +01:00
Jack Franklin
6474edb9ba
feat(types): add types for $eval (#6135)
This pulls in the types (based on the DefinitelyTyped repo) for
`page.$eval` (and the `$eval` method on other classes). The `$eval`
method is quite hard to type due to the way we wrap and unwrap
ElementHandles that are passed to / returned from the `pageFunction`
that users provide.

Longer term we can improve the types by providing type overloads as
DefinitelyTyped does but I've deferred that for now (see the `TODO` in
the code for more details).
2020-07-02 10:09:34 +01:00
Jack Franklin
8370ec88ae
feat(types): add (and fix) evaluateHandle types (#6130)
This change started as a small change to pull types from DefinitelyTyped over to
Puppeteer for the `evaluateHandle` function but instead ended up also fixing
what looks to be a long standing issue with our existing documentation.

`evaluateHandle` can in fact return an `ElementHandle` rather than a `JSHandle`.
Note that `ElementHandle` extends `JSHandle` so whilst the docs are technically
correct (all ElementHandles are JSHandles) it's confusing because JSHandles
don't have methods like `click` on them, but ElementHandles do.

if you return something that is an HTML element:

```
const button = page.evaluateHandle(() => document.querySelector('button'));
// this is an ElementHandle, not a JSHandle
```

Therefore I've updated the original docs and added a large explanation to the
TSDoc for `page.evaluateHandle`.

In TypeScript land we'll assume the function will return a `JSHandle` but you
can tell TS otherwise via the generic argument, which can only be `JSHandle`
(the default) or `ElementHandle`:

```
const button = page.evaluateHandle<ElementHandle>(() => document.querySelector('button'));
```
2020-07-01 12:44:08 +01:00
Jack Franklin
3c0dc45e47
chore: update Windows skipped tests. (#6133)
The headful one I'm permanently skipping as I don't know what the issue is and I can't debug without getting my hands on a Windows machine. If anyone has one or is able to help, that'd be great!

The other I'm deferring another month and will ping the FF folks :)
2020-07-01 11:28:13 +01:00
Jack Franklin
a4d12a2b21 chore: remove helper.promisify (#6100)
It was just re-exporting the built-in Node module so let's just import
from that directly.
2020-06-25 13:01:46 +02:00
Jack Franklin
785551997f chore: tidy up TODO from TS tests migration (#6090)
Deleting `Node` errors in strict mode; we don't need to have this test
any more.
2020-06-25 13:01:36 +02:00
Jack Franklin
37f6032003
feat(api): remove emulateMedia method (#6084)
It has been deprecated for a while. In the next breaking release let's remove it.

BREAKING CHANGE: swap to `emulateMediaType` instead.
2020-06-23 16:27:37 +01:00
Jack Franklin
381b0f833c
chore: declare toBeGolden to TypeScript (#6080)
Which means we can avoid all the ts-expect-errors on any `toBeGolden`
calls.
2020-06-23 15:02:09 +01:00
Jack Franklin
70a900e93b
chore: fix ESLint violation and lessen rule strictness (#6081) 2020-06-23 12:55:42 +01:00
Jack Franklin
28797dee41
chore: migrate tests to TypeScript (#6075)
This CL migrates all the tests to TypeScript. The main benefits of this is that we start consuming our TypeScript definitions and therefore find errors in them. The act of migrating found some bugs in our definitions and now we can be sure to avoid them going forwards.

You'll notice the addition of some `TODO`s in the code; I didn't want this CL to get any bigger than it already is but I intend to follow those up once this lands. It's mostly figuring out how to extend the `expect` types with our `toBeGolden` helpers and some other slight confusions with types that the tests exposed.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-06-23 07:18:46 +02:00
Jack Franklin
e7b91a7f41
chore: enforce a max line length on comments (#6055) 2020-06-19 15:39:03 +01:00
Jack Franklin
7a4170fe6e
chore: remove top level errors and DeviceDescriptors (#6043)
As far as I can tell these became irrelevant as of v1.15 which added
`puppeteer.errors` and `puppeteer.devices [1]. This is a breaking change
but one that's easily mitigated. We've said that we don't consider
changes to our folder/file structure a breaking change, but we can't
really do that if we have these two top level files that we've
documented.

[1]: e3abb0aa32 (diff-522b24108d7446af4c59873472a90444)
2020-06-19 15:15:13 +02:00
Jack Franklin
759b28080a
chore: upgrade to Mocha v8 (#5997)
* chore: upgrade to Mocha v8

Mocha v8 has some nice improvements and also unlocks the potential
to have parallel test runs which may speed up CI.
2020-06-18 16:26:30 +01:00
Jack Franklin
9522f80116
chore: create common directory (#6042)
These files will be used by both the web and node versions of Puppeteer.
Another name for this might be "core" but I don't want to cause
confusion with the puppeteer-core package that we publish at the moment.
2020-06-18 15:53:23 +01:00
Tim van der Lippe
03ab1c1b9c
fix: improve Ctrl + C support (#6011)
Fix child process killing when the parent process SIGINTs.

If you `ctrl + c` the Puppeteer parent process, we would sometimes not properly handle killing of the child processes. This would then leave child processes behind, with running Chromium instances. This in turn could block Puppeteer from launching again and results in
cryptic errors.

Instead of using the generic `process.kill` with the process id (which for some reason is negative the pid, which I don't get), we can kill the child process directly by calling `proc.kill`.

Fixes #5729.
Fixes #4796.
Fixes #4963.
Fixes #4333.
Fixes #1825.
2020-06-15 15:02:00 +02:00
Jack Franklin
b659969a38
chore: migrate away from Node's EventEmitter (#5979) 2020-06-15 11:52:19 +01:00
Maja Frydrychowicz
3d56a9e76f chore: add test configuration options for running tests against multiple products (#5964)
* chore: remove "Extracting..." log message

Fixes #5741.

* test: support extra Launcher options and skips

The extra Launcher options and skipping conditions enable
unit tests to be run more easily by third-parties, e.g.
browser vendors that are interested in Puppeteer support.

Extra Launcher options were previously removed as part of
switching away from the custom test harness.

* test: enable more tests for Firefox
2020-06-12 15:56:11 +02:00
Jack Franklin
8a099a0c2c
docs: replace @return with @returns (#6006)
The former is not understood by TSDoc.
2020-06-12 12:38:24 +02:00
Henrik Skupin
9c656d417e
chore: remove prefers-color-scheme: no-preference (#5990)
The 'no-preference' value has been removed from the spec per resolution in [1]. The appropriate web-platform-tests [2] have already been updated.

[1] https://github.com/w3c/csswg-drafts/issues/3857#issuecomment-634779976
[2] https://github.com/web-platform-tests/wpt/pull/24024
2020-06-09 23:17:07 +02:00
Jack Franklin
81e32481e9
chore: Defer Windows FF tests for longer (#5954)
We deferred this initially because our Windows CI built wasn't stable
and so debugging this was hard. It's now much more stable so let's push
this back a month but at the same time I'll reach out to the Moz folks
as it should be easier to debug reliably now CI is stable on Windows.
2020-06-01 11:12:25 +01:00
Mathias Bynens
7eab7f8dd9
feat(api): add page.emulateVisionDeficiency(type) (#5901)
Design doc: https://goo.gle/devtools-cvd
2020-05-26 17:14:20 +02:00
Jack Franklin
24ac11e76e
chore: fix undefined rm in mocha-utils (#5920)
Closes #5916.
2020-05-26 16:37:39 +02:00
Henrik Skupin
6cfe142af1
Don't use expect within Promises (#5466) (#5473)
* Don't use expect within Promises (#5466)

If a call to expect fails within a Promise it will not
be resolved, and causing the test to crash.

The patch aligns the code similar to what is used by all
the other tests.
2020-05-26 09:22:11 +01:00
Jack Franklin
d8e0557d18
chore: update Travis to run latest macOS and fix HTTPS test (#5903)
* chore: fix invalid SSL assertion on Catalina

The error Chrome gives with an invalid cert changes between older Mac
versions and Catalina as detailed here:
https://support.google.com/chrome/thread/18125056?hl=en.

This PR changes Travis to run Catalina (and we think most devs run up to
date OS versions) so this fix ensures the test behaviour is consistent
locally and on Travis.

For those on older Mac versions I've left a comment by the tests to
hopefully save them debugging!

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-05-21 15:36:59 +01:00
Jack Franklin
9a08d31319
chore: error if coverage couldn't find the given class (#5863)
The coverage utils depend on `src/api.ts` being up to date and pointing to the right modules. If they aren't, you would get a cryptic error on CI:

```
1) "before all" hook in "{root}":
   TypeError: Cannot read property 'prototype' of undefined
    at traceAPICoverage (test/coverage-utils.js:40:54)
    at Context.before (test/coverage-utils.js:103:7)
2) "after all" hook in "{root}":
   TypeError: Cannot read property 'stop' of undefined
    at Context.after (test/mocha-utils.js:168:22)
```

This change logs a clearer error that highlights the missing class and exits, so it's much easier to realise what's gone wrong.

Ideally the  coverage wouldn't need a hardcoded list of sources, but until then this will help spot this error in the future.
2020-05-20 11:00:29 +02:00
Islam ElHakmi
caaf4d2086
fix: support async functions as an argument for waitForFunction (#5682) 2020-05-19 09:09:31 +02:00
Michal TOMA
a17bd89fb9 feat: add securityDetails.subjectAlternativeNames() #5628 (#5881)
Co-authored-by: Michal TOMA <michaltoma2205@gmail.com>
Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>

Fixes #5625. Closes #5628.
2020-05-18 12:59:57 +02:00
Alex Rudenko
e8232890a4
feat(chromium): roll Chromium to r756035 (#5879)
This corresponds to Chromium 83.0.4103.0.

This roll includes:

- Enable SameSiteByDefaultCookies and CookiesWithoutSameSiteMustBeSecure https://crrev.com/c/2122809
2020-05-18 11:06:42 +02:00
Jack Franklin
3e76554fcb
chore: fix async dialog specs when they fail (#5859)
When this test was failing, it would cause no future tests to run. This
was because the `expect` call within the `page.on` callback would throw
an error, and that would trigger a unhandled promise rejection that
caused the test framework to stop.

The fundamental issue here is making `expect` calls within callbacks.
They are brittle due to the fact that they throw, and the test framework
won't catch it, but also because you have no guarantee that they will
run. If the callback is never executed you dont' know about it.

Although it's slightly more code, using a stub is the way to do this.
Not only can we assert that the stub was called, we can make synchronous
`expect` calls that Mocha will pick up properly if they fail.

Before this change, running the tests (and making it fail on purpose)
would cause all test execution to stop:

```
> puppeteer@3.0.4-post unit /Users/jacktfranklin/src/puppeteer
> mocha --config mocha-config/puppeteer-unit-tests.js

  .(node:69580) UnhandledPromiseRejectionWarning: Error: expect(received).toBe(expected) // Object.is equality

Expected: "yes."
Received: ""
    at Page.<anonymous> (/Users/jacktfranklin/src/puppeteer/test/dialog.spec.js:42:37)
    [snip]
(node:69580) UnhandledPromiseRejectionWarning: Unhandled promise rejection ... [snip]
```

But with this change, the rest of the tests run:

```
> puppeteer@3.0.4-post unit /Users/jacktfranklin/src/puppeteer
> mocha --config mocha-config/puppeteer-unit-tests.js

  Page.Events.Dialog
    ✓ should fire
    1) should allow accepting prompts
    ✓ should dismiss the prompt

  2 passing (2s)
  1 failing

  1) Page.Events.Dialog
       should allow accepting prompts:
     Error: expect(received).toBe(expected) // Object.is equality

Expected: "yes."
Received: ""
      at Context.<anonymous> (test/dialog.spec.js:53:35)
      at processTicksAndRejections (internal/process/task_queues.js:94:5)
```

This is much better because one failing test now doesn't stop the rest
of the test suite.

This probably isn't the only instance of this in the codebase so I
propose as we encounter them we fix them usng this commit as the
template.
2020-05-14 11:34:22 +02:00
Mathias Bynens
b2552e4f7d
chore: restore page.setUserAgent test (#5868)
Ref. #5781.
2020-05-14 10:24:30 +01:00
Christian Bromann
b510c354c7
chore: fetch Firefox from JSON source instead of RegExp (#5864)
Fetch Firefox from https://product-details.mozilla.org/1.0/firefox_versions.json.

Fixes #5742.
2020-05-13 15:48:39 +02:00
Jack Franklin
f5d2597bac
chore: add running TSC to test README (#5852) 2020-05-13 09:20:33 +01:00
Jack Franklin
b38bb4334f
Warn when given unsupported product name. (#5845)
* Warn when given unsupported product name.

Fixes #5844.

This change means when a user launches Puppeteer with a product name
that is not supported (which at the time of this commit means it's not
`firefox` or `chrome) we will warn them about it.

Decided on just a warning vs an error because the current behaviour is
that we fallback to launching Chrome and I don't think this warrants a
breaking change.
2020-05-12 10:30:24 +01:00
Jack Franklin
4fdb1e3cab
chore: add Prettier (#5825) 2020-05-07 12:54:55 +02:00
Jack Franklin
890c215142
chore: migrate src/Puppeteer to TypeScript (#5789)
* chore: migrate src/Puppeteer to TypeScript.

* fix api js
2020-05-05 09:36:44 +01:00
Jack Franklin
5518bac291
chore: update how we track coverage during unit tests (#5779)
* chore: update how we track coverage during unit tests

The old method of tracking coverage was causing issues. If a test failed
on CI, that test's failure would be lost because the test failing would
in turn cause the coverage to fail, but the `process.exit(1)` in the
coverage code caused Mocha to not output anything useful.

Instead the coverage checker now:

* tracks the coverage in memory in a Map (this hasn't changed)
* after all tests, writes that to disk in test/coverage.json (which is
gitignored)
* we then run a single Mocha test that asserts every method was called.

This means if the test run fails, the build will fail and give the error
about that test run, and that output won't be lost when the coverage
then fails too.

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-04-30 13:00:41 +01:00
Paul Lewis
4a47867a24
feat: add support for string-based custom queries (#5753) 2020-04-30 12:45:52 +01:00
Jack Franklin
3116bb9c2d
chore: log product + binary on unit test runs (#5785)
This way it's super clear which product and binary you're testing against.
2020-04-30 13:03:16 +02:00
Mathias Bynens
862eea850e
chore: disable flaky setUserAgent test in Firefox (#5780) 2020-04-30 12:10:28 +02:00
Jack Franklin
8a5008e30b
chore: migrate src/FrameManager to TypeScript (#5773) 2020-04-29 13:28:16 +02:00
Jack Franklin
1ccfbcb684
chore: enforce naming of errors in catch blocks (#5763) 2020-04-28 15:16:28 +02:00
Jack Franklin
06d62c0165
chore: migrate src/Browser to TS (#5761) 2020-04-28 14:26:37 +02:00
Paul Lewis
79e82e5b65
fix: make uploadFile throw for non-existent files (#5733) 2020-04-24 13:36:46 +02:00
Jack Franklin
8509f4660e
chore: migrate src/Accessibility to TypeScript (#5726) 2020-04-23 15:35:03 +01:00
Jack Franklin
e3922ea1f3
chore: enforce consistent spacing around object curlys (#5700)
The codebase was incredibly inconsistent with the use of spacing around
curly braces, e.g.:

```
// this?
const a = {b: 1}
// or?
const a = { b: 1 }
```

This extended into import statements also. Google's styleguide is no
spacing, so we're going with that.
2020-04-21 10:40:04 +01:00
Jack Franklin
c4fe4e46c2
chore(ci): re-enable tests on Windows (#5637)
* chore: Add Windows to Travis

This commit runs the unit tests on Windows.

There are two tests failing on Windows that we skip.

I spoke to Mathias B and we agreed to
defer debugging this for now in favour of getting tests running on
Windows. But we didn't want to ignore it forever, hence giving the test
a date at which it will start to fail.
2020-04-17 14:27:50 +01:00
Paul Lewis
532ae573d2
fix(JSHandle): Fixes file upload (#5655)
This PR returns to using `DOM.setFileInputFiles`, but with some additional fixes and checks for events and multiple files.
2020-04-16 16:22:52 +01:00
Changhao Han
3387aab37f feat(chromium): roll Chromium to r737027 (#5644)
This corresponds to Chromium 81.0.4044.0.

This roll includes:

- [DevTools] Add Cookie Priority support to CDP
  https://chromium-review.googlesource.com/c/chromium/src/+/1959029
- Reject cookies with empty names and values
  https://chromium-review.googlesource.com/c/chromium/src/+/1982549
2020-04-16 09:54:00 +02:00
Maja Frydrychowicz
35989a78ba
fix: set revision based on PUPPETEER_PRODUCT (#5643) 2020-04-15 13:30:42 +02:00
Jack Franklin
0bcc5a7ad8
chore: migrate remaining tests to Mocha (#5616)
This commit updates all the non-Puppeteer unit tests to run using Mocha and then deletes the custom test runner framework from this repository. The documentation has also been updated.
2020-04-09 20:12:32 +02:00
Jack Franklin
17cd8703f9
chore: migrate unit tests to Mocha (#5600)
Rather than maintain our own test runner we should instead lean on the community and use Mocha which is very popular and also our test runner of choice in DevTools too.

Note that this commit doesn't remove the TestRunner source as it's still used for other unit tests, but they will be updated in a future PR and then we can remove the TestRunner.

The main bulk of this PR is updating the tests as the old TestRunner passed in contextual data via the `it` function callback whereas Mocha does not, so we introduce some helpers for the tests to make it easier.
2020-04-09 07:56:25 +02:00
Jack Franklin
841c2a5fc0
chore: fix emulateMedia tests (#5593)
See the large code comment in the diff for a full explanation but we can't rely on the functions being referentially equivalent so instead we test the behaviour in duplicate tests across the deprecated method and the new method.
2020-04-06 12:25:09 +02:00
Jack Franklin
8fa034bf2f
chore: remove flakiness dashboard (#5592)
We're not using it at all so might as well cut down on code in the codebase.
2020-04-06 11:55:15 +02:00
Jack Franklin
a99a3cf757
chore: skip failing cookie tests in Firefox (#5575)
They fail because cookies in Firefox return a `sameSite` key which the tests don't expect.

This is a solution that at least gets the Travis Firefox build (hopefully!) green again. Longer term it'd be great to allow the assertion to change based on the browser, rather than skip these tests entirely.
2020-04-06 10:34:45 +02:00
Tim Gates
99ecdbad0a
docs: fix simple typo (#5585)
There is a small typo in test/utils.js, utils/flakiness-dashboard/FlakinessDashboard.js.

Should read `existence` rather than `existance`.
2020-04-06 08:49:15 +02:00
Jack Franklin
6522e4f524
chore: Use expect for assertions (#5581)
Rather than use our own custom expect library, we can use expect from npm [1], which has an API almost identical to the one Puppeteer has, but with more options, better diffing, and is used by many in the community as it's the default assertions library that comes with Jest.

It's also thoroughly documented [2].

[1]: https://www.npmjs.com/package/expect
[2]: https://jestjs.io/docs/en/expect
2020-04-03 13:22:55 +02:00
Philipp Hagemeister
067662c677
Emit change event on uploadFile calls (#5389)
In puppeteer 1.20.0, the following code emitted an alert:
```
const puppeteer = require('puppeteer');

(async () => {
	const browser = await puppeteer.launch({args: ['--no-sandbox'], headless: false});
	const page = (await browser.pages())[0];

	await page.setContent(`
		<input type=file>
		<script>
		document.querySelector('input').addEventListener('change', () => {
			alert('Uploaded a file');
		});
		</script>
		`);
	const input = await page.waitForSelector('input[type="file"]');
	await input.uploadFile(__filename);
})();
```

A bisection yielded 6091a34a36 as the commit that broke this.

Emitting the change event as well seems to fix the problem.
2020-03-12 17:26:03 +01:00
Maja Frydrychowicz
33f1967072
(feat) Add option to fetch Firefox Nightly (#5467)
* (feat) Add option to fetch Firefox Nightly

Add Firefox support to BrowserFetcher and the install script.
By default, the latest Firefox Nightly is downloaded
directly from archive.mozilla.org (dmg, tar.bz2 and zip)

This also required changes that impact `puppeteer.launch()`
and `puppeteer.executablePath()`

Fixes #5151

* Update docs/api.md

Co-Authored-By: Mathias Bynens <mathias@qiwi.be>

* Clean up revision promise

* Improve error handling in revision check

* Remove matchAll

* Use explicit octal mode

* Update .gitignore

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
2020-03-10 21:59:03 +01:00
Maja Frydrychowicz
0b1a9ceee2
chore: Replace Juggler with Firefox Nightly in CI (#5395)
Fixes #5150.
2020-02-20 13:57:15 +01:00
Mathias Bynens
013a86cf28
feat(chromium): roll Chromium to r722269 (#5289)
This corresponds to Chromium 80.0.3987.0.

This roll includes:

- Implement support for the new ARIA `generic` role
  https://chromium-review.googlesource.com/c/chromium/src/+/1872305
- Expose button's children to accessibility tree
  https://chromium-review.googlesource.com/c/chromium/src/+/1845810
- Remove `Page.handleFileChooser` from CDP
  https://chromium-review.googlesource.com/c/chromium/src/+/1935410
2020-01-27 14:44:53 +01:00
den
5e63254e62 chore: fix typo in test name (#5217) 2019-12-11 15:41:41 +01:00
Darío Kondratiuk
f0bf645c47 test: reduce flakiness for accessibility tests with autofocus (#5116) 2019-11-27 10:36:17 +01:00
Mathias Bynens
eddb23b521
chore: update URLs (#5185) 2019-11-26 13:12:25 +01:00
Maja Frydrychowicz
c5a72e9887 feat(launcher): add option to run Puppeteer with different browsers (#5137)
* feat: Set which browser to launch via PUPPETEER_PRODUCT

This change introduces a PUPPETEER_PRODUCT environment
variable as a first step toward using Puppeteer with
many different browsers. Setting PUPPETEER_PRODUCT=firefox, for
example, enables Firefox-specific Launcher settings.

The state is also exposed as `puppeteer.product` in the API
to support adding other product-specific behaviour as needed.

The bulk of the change is a refactoring in Launcher
to decouple generic browser start-up from product-specific
configuration.

Respecting the puppeteer-core restriction for PUPPETEER_
environment variables, lazily instantiate the Launcher
based on a `product` Puppeteer.launch option, if available.

* test: Distinguish Juggler unit tests from Firefox

The funit script is renamed to fjunit (j for Juggler, which is
used only by the experimental puppeteer-firefox package.

In contrast, the funit script now refers to running Puppeteer
unit tests against the main puppeteer package with Firefox.
To do so with Firefox Nightly, run:

`BINARY=path/to/firefox npm run funit`

A number of changes in this patch make it easier to run
Puppeteer unit tests in Mozilla's CI.
2019-11-26 10:23:19 +01:00