Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(examples): setup get started with examples guide #1441

Merged
merged 1 commit into from Mar 21, 2020

Conversation

arjunattam
Copy link
Contributor

@arjunattam arjunattam commented Mar 20, 2020

Follow up PRs to add more examples, add a section explaining core concepts (like browser contexts), and maybe elaborate on the dev environment.

Would love to get your feedback.

Related to #660

@arjunattam arjunattam linked an issue Mar 20, 2020 that may be closed by this pull request
@arjunattam arjunattam removed a link to an issue Mar 20, 2020
Copy link
Member

@yury-s yury-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!


It is also possible to open **browser dev tools** during execution, to inspect the DOM tree or network activity.

<p align="center"><a href="https://user-images.githubusercontent.com/284612/77158031-c18e7e80-6a5f-11ea-8a71-4a4bea54f879.png"><img src="https://user-images.githubusercontent.com/284612/77158031-c18e7e80-6a5f-11ea-8a71-4a4bea54f879.png" width="500" alt="WebKit dev tools"></a></p>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather use Chromium DevTools in the example as WebKit doesn't support multiple clients yet and once the user opens Web Inspector it will take over control of the page and kick playwright out.

nit: if you want to stick with WebKit, let's change the hint to 'WebKit Web Inspector'


### [Authentication](authentication.js)

This scripts logs in on GitHub.com through Chromium, and then reuses the login cookies state in WebKit. This recipe can be used to speed up tests by logging in once and reusing login state.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: This script_ logs

})();

const verifyIsLoggedIn = async (page) => {
await page.waitForSelector('"Create repository"');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: for the verification purposes I wouldn't want to wait for the selector but rather bail out immediately, so I'd either rename the function or change its implementation to not wait depending on the scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I moved to use page.$ but perhaps there is a better solution.

const verifyIsLoggedIn = async (page) => {
  // Find element through text value and assert it exists.
  assert(await page.$('text="Create repository"'));
}

Once installed, you can `require` Playwright in your Node.js scripts.

```js
const playwright = require('playwright');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We recommend destructuring everywhere: const { chromium } = require('playwright');.


## Setup dev environment

Playwright scripts can be developed just like any other Node.js script. You can use the [Node.js debugger](https://nodejs.org/api/debugger.html) or [VS Code debugging](https://code.visualstudio.com/docs/nodejs/nodejs-debugging) to set breakpoints and get fine grained control over execution.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say 'for example' to not imply we only work with these two debuggers.

By default, Playwright runs the browsers in headless mode. To see the browser UI, pass the `headless: false` flag while launching the browser. You can also use `slowMo` to slow down execution.

```js
playwright.firefox.launch({ headless: false, slowMo: 50 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • chromium.launch(...)
  • Let's use chromium everywhere for consistency, and mention at the top that all examples use Chromium, but can be similarly run with Firefox/WebKit?


<!--
Other examples
* Page navigation and wait for load
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Filling a form
  • Uploading a file
  • Handling a popup, e.g. clicking "I accept" to close it

@arjunattam arjunattam merged commit 6df17c6 into microsoft:master Mar 21, 2020
@arjunattam arjunattam deleted the examples-1 branch March 21, 2020 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants