Skip to content

Commit

Permalink
remove expect-playwright, point to playwright docs for assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
jperl committed Jul 7, 2020
1 parent 8980953 commit 3c6c3c1
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 76 deletions.
2 changes: 1 addition & 1 deletion docs/docs/api/table_of_contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ title: API Table of Contents
<br/>
<br/>

In addition to the APIs below, you have full access to the [Playwright API](https://github.com/microsoft/playwright/blob/master/docs/api.md), the [Jest API](https://jestjs.io/docs/en/expect), and [expect-playwright API](https://github.com/playwright-community/expect-playwright#api-documentation).
In addition to the APIs below, you have full access to the [Playwright API](https://github.com/microsoft/playwright/blob/master/docs/api.md) and the [Jest API](https://jestjs.io/docs/en/expect).

The QA Wolf API is minimal by design, since we want to leverage the power of Playwright/Jest as much as possible.

Expand Down
63 changes: 1 addition & 62 deletions docs/docs/create_a_test.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ npx qawolf create http://todomvc.com/examples/react myTest

- [Edit as you go](#edit-as-you-go) in your code editor (`.qawolf/myTest.test.js`)

- [Add assertions](#optional-add-assertions) with the [expect-playwright](https://github.com/playwright-community/expect-playwright) library (included with QA Wolf):

```js
await expect(page).toHaveText('Clear completed');
await expect(page).toHaveSelector('.clear-completed');
```

- [Save your test](#save-a-test) by choosing `💾 Save and Exit` in the command line

:::
Expand Down Expand Up @@ -124,61 +117,7 @@ The test code is created in real-time, so you can edit the test as you create it

:::

## Optional: Add assertions

Let's add assertions to our test.

We recommend adding assertions with the [expect-playwright library](https://github.com/playwright-community/expect-playwright), which automatically waits for assertions. QA Wolf includes this library by default, so you do not need to install anything to use it.

### Assert that text appears

The first assertion we will add is to check that the text `"Clear completed"` appears after we complete our todo. Specifically, we will call expect-playwright's [`toHaveText` method](https://github.com/playwright-community/expect-playwright#tohavetext) to verify that the text appears on the page.

In our test code, let's add a line to assert that the text `"Clear completed"` appears on the page:

```js
// ...

test('myTest', async () => {
await page.goto('http://todomvc.com/examples/react');
await page.click('[placeholder="What needs to be done?"]');
await page.type('[placeholder="What needs to be done?"]', 'create test!');
await page.press('[placeholder="What needs to be done?"]', 'Enter');
await page.click('.toggle');
// custom code starts
await expect(page).toHaveText('Clear completed');
// custom code ends
await page.click('text=Clear completed');
});
```

### Assert that an element appears

Rather than asserting that the text `"Clear completed"` appears on the page, we could instead assert that the `"Clear completed"` button appears on the page.

In terms of the [DOM](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model), this means that there should be an element with the class `"clear-completed"`. The corresponding [CSS selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors) for an element with the class `"clear-completed"` is `.clear-completed`.

We'll use the [`toHaveSelector` method](https://github.com/playwright-community/expect-playwright#toHaveSelector) to assert that the CSS selector `.clear-completed` appears on the page after we complete our todo.

Our test now looks like this:

```js
// ...

test('myTest', async () => {
await page.goto('http://todomvc.com/examples/react');
await page.click('[placeholder="What needs to be done?"]');
await page.type('[placeholder="What needs to be done?"]', 'create test!');
await page.press('[placeholder="What needs to be done?"]', 'Enter');
await page.click('.toggle');
// custom code starts
await expect(page).toHaveSelector('.clear-completed');
// custom code ends
await page.click('text=Clear completed');
});
```

If the `"Clear completed"` button does not appear on the page, our test will fail.
You can edit this file with assertions. To learn about assertions, see Playwright's [documentation](https://playwright.dev/#version=v1.2.0&path=docs%2Fassertions.md&q=custom-assertions).

## Save a test

Expand Down
3 changes: 0 additions & 3 deletions expect-playwright.js

This file was deleted.

1 change: 0 additions & 1 deletion js-jest.config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"setupFilesAfterEnv": ["qawolf/expect-playwright"],
"transform": {}
}
5 changes: 0 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"types": "./build/index.d.ts",
"files": [
"build",
"expect-playwright.js",
"js-jest.config.json",
"postInstallMessage.js",
"ts-jest.config.json"
Expand Down Expand Up @@ -53,7 +52,6 @@
"commander": "^5.1.0",
"create-qawolf": "^1.0.2",
"debug": "*",
"expect-playwright": "^0.2.4",
"glob": "^7.1.6",
"inquirer": "^7.2.0",
"kleur": "^3.0.3",
Expand Down
1 change: 0 additions & 1 deletion test/.qawolf/scroll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ afterAll(async () => {
test('scroll', async () => {
await page.goto(`${TEST_URL}infinite-scroll`);
await page.evaluate(() => console.log('start scroll test'));
await expect(page).toHaveText('Item 1');
await qawolf.scroll(page, 'html', { x: 0, y: 500 });
});
1 change: 0 additions & 1 deletion ts-jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@
"diagnostics": false
}
},
"setupFilesAfterEnv": ["qawolf/expect-playwright"],
"transform": {}
}

0 comments on commit 3c6c3c1

Please sign in to comment.