Skip to content

Commit

Permalink
chore: prepare non-api docs for non-js variants (#4969)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelfeldman committed Jan 11, 2021
1 parent 4dbbb47 commit 7a8214c
Show file tree
Hide file tree
Showing 15 changed files with 439 additions and 147 deletions.
32 changes: 16 additions & 16 deletions docs/src/api/python.md
Expand Up @@ -124,13 +124,13 @@ Performs action and waits for given `event` to fire. If predicate is provided, i
event's value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
Will throw an error if the page is closed before the `event` is fired.

```python-async
```python async
async with page.expect_event(event_name) as event_info:
await page.click("button")
value = await event_info.value
```

```python-sync
```python sync
with page.expect_event(event_name) as event_info:
page.click("button")
value = event_info.value
Expand All @@ -148,13 +148,13 @@ Performs action and waits for given `event` to fire. If predicate is provided, i
event's value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
Will throw an error if browser context is closed before the `event` is fired.

```python-async
```python async
async with context.expect_event(event_name) as event_info:
await context.click("button")
value = await event_info.value
```

```python-sync
```python sync
with context.expect_event(event_name) as event_info:
context.click("button")
value = event_info.value
Expand All @@ -172,13 +172,13 @@ Performs action and waits for given `event` to fire. If predicate is provided, i
event's value into the `predicate` function and waits for `predicate(event)` to return a truthy value.
Will throw an error if the socket is closed before the `event` is fired.

```python-async
```python async
async with ws.expect_event(event_name) as event_info:
await ws.click("button")
value = await event_info.value
```

```python-sync
```python sync
with ws.expect_event(event_name) as event_info:
ws.click("button")
value = event_info.value
Expand All @@ -195,13 +195,13 @@ value = event_info.value
Performs action and waits for the required load state. It resolves when the page reaches a required load state, `load` by default. The navigation must have been committed when this method is called. If current document has
already reached the required state, resolves immediately.

```python-async
```python async
async with page.expect_load_state():
await page.click('button') # Click triggers navigation.
# Context manager waits for 'load' event.
```

```python-sync
```python sync
with page.expect_load_state():
page.click('button') # Click triggers navigation.
# Context manager waits for 'load' event.
Expand All @@ -219,13 +219,13 @@ Shortcut for main frame's [`method: Frame.expectLoadState`].
Performs action and waits for the required load state. It resolves when the page reaches a required load state, `load` by default. The navigation must have been committed when this method is called. If current document has
already reached the required state, resolves immediately.

```python-async
```python async
async with frame.expect_load_state():
await frame.click('button') # Click triggers navigation.
# Context manager waits for 'load' event.
```

```python-sync
```python sync
with frame.expect_load_state():
frame.click('button') # Click triggers navigation.
# Context manager waits for 'load' event.
Expand All @@ -238,21 +238,21 @@ with frame.expect_load_state():
* langs: python
- returns: <[EventContextManager]>

Performs action and wait for the next navigation. In case of multiple redirects, the navigation will resolve with
Performs action and waits for the next navigation. In case of multiple redirects, the navigation will resolve with
the response of the last redirect. In case of navigation to a different anchor or navigation due to History API
usage, the navigation will resolve with `null`.

This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will
indirectly cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation
from a `setTimeout`. Consider this example:

```python-async
```python async
async with page.expect_navigation():
await page.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
# Context manager waited for the navigation to happen.
```

```python-sync
```python sync
with page.expect_navigation():
page.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
# Context manager waited for the navigation to happen.
Expand All @@ -271,21 +271,21 @@ Shortcut for main frame's [`method: Frame.expectNavigation`].
* langs: python
- returns: <[EventContextManager]>

Performs action and wait for the next navigation. In case of multiple redirects, the navigation will resolve with
Performs action and waits for the next navigation. In case of multiple redirects, the navigation will resolve with
the response of the last redirect. In case of navigation to a different anchor or navigation due to History API
usage, the navigation will resolve with `null`.

This resolves when the page navigates to a new URL or reloads. It is useful for when you run code which will
indirectly cause the page to navigate. e.g. The click target has an `onclick` handler that triggers navigation
from a `setTimeout`. Consider this example:

```python-async
```python async
async with frame.expect_navigation():
await frame.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
# Context manager waited for the navigation to happen.
```

```python-sync
```python sync
with frame.expect_navigation():
frame.click("a.delayed-navigation") # Clicking the link will indirectly cause a navigation
# Context manager waited for the navigation to happen.
Expand Down
12 changes: 6 additions & 6 deletions docs/src/assertions.md
Expand Up @@ -35,7 +35,7 @@ const checked = await page.getAttribute('input', 'checked');
assert(checked);
```

```python-async
```python async
# Assert text content
content = await page.text_content('nav:first-child')
assert content == 'home'
Expand All @@ -53,7 +53,7 @@ checked = await page.get_attribute('input', 'checked')
assert checked
```

```python-sync
```python sync
# Assert text content
content = page.text_content('nav:first-child')
assert content == 'home'
Expand Down Expand Up @@ -106,7 +106,7 @@ const classNames = await elementHandle.getAttribute('class');
assert(classNames.includes('highlighted'));
```

```python-async
```python async
# Get the element handle
element_handle = page.wait_for_selector('#box')

Expand All @@ -119,7 +119,7 @@ class_names = await element_handle.get_attribute('class')
assert 'highlighted' in class_names
```

```python-sync
```python sync
# Get the element handle
element_handle = page.wait_for_selector('#box')

Expand Down Expand Up @@ -171,7 +171,7 @@ const length = await page.$$eval('li.selected', (items) => items.length);
assert(length === 3);
```

```python-async
```python async
# Assert local storage value
user_id = page.evaluate("() => window.localStorage.getItem('user_id')")
assert user_id
Expand All @@ -190,7 +190,7 @@ length = await page.eval_on_selector_all('li.selected', '(items) => items.length
assert length == 3
```

```python-sync
```python sync
# Assert local storage value
user_id = page.evaluate("() => window.localStorage.getItem('user_id')")
assert user_id
Expand Down
16 changes: 8 additions & 8 deletions docs/src/auth.md
Expand Up @@ -36,7 +36,7 @@ await page.click('text=Submit');
// Verify app is logged in
```

```python-async
```python async
page = await context.new_page()
await page.goto('https://github.com/login')

Expand All @@ -48,7 +48,7 @@ await page.click('text=Submit')
# Verify app is logged in
```

```python-sync
```python sync
page = context.new_page()
page.goto('https://github.com/login')

Expand Down Expand Up @@ -88,7 +88,7 @@ const storageState = JSON.parse(process.env.STORAGE);
const context = await browser.newContext({ storageState });
```

```python-async
```python async
import json
import os
# Save storage state and store as an env variable
Expand All @@ -100,7 +100,7 @@ storage_state = json.loads(os.environ["STORAGE"])
context = await browser.new_context(storage_state=storage_state)
```

```python-sync
```python sync
import json
import os
# Save storage state and store as an env variable
Expand Down Expand Up @@ -134,7 +134,7 @@ await context.addInitScript(storage => {
}, sessionStorage);
```

```python-async
```python async
import os
# Get session storage and store as env variable
session_storage = await page.evaluate("() => JSON.stringify(sessionStorage)")
Expand All @@ -152,7 +152,7 @@ await context.add_init_script(storage => {
}, session_storage)
```

```python-sync
```python sync
import os
# Get session storage and store as env variable
session_storage = page.evaluate("() => JSON.stringify(sessionStorage)")
Expand Down Expand Up @@ -217,7 +217,7 @@ const context = await chromium.launchPersistentContext(userDataDir, { headless:
// Execute login steps manually in the browser window
```

```python-async
```python async
import asyncio
from playwright import async_playwright

Expand All @@ -230,7 +230,7 @@ async def main():
asyncio.get_event_loop().run_until_complete(main())
```

```python-sync
```python sync
from playwright import sync_playwright

with sync_playwright() as p:
Expand Down
12 changes: 6 additions & 6 deletions docs/src/ci.md
Expand Up @@ -50,13 +50,13 @@ Suggested configuration
});
```

```python-async
```python async
browser = await playwright.chromium.launch(
args=['--disable-dev-shm-usage']
)
```

```python-sync
```python sync
browser = playwright.chromium.launch({
args=['--disable-dev-shm-usage']
})
Expand Down Expand Up @@ -203,11 +203,11 @@ const { chromium } = require('playwright');
const browser = await chromium.launch({ chromiumSandbox: false });
```

```python-async
```python async
browser = await playwright.chromium.launch(chromiumSandbox=False)
```

```python-sync
```python sync
browser = playwright.chromium.launch(chromiumSandbox=False)
```

Expand Down Expand Up @@ -287,7 +287,7 @@ const { chromium } = require('playwright');
const browser = await chromium.launch({ headless: false });
```

```python-async
```python async
import asyncio
from playwright import async_playwright

Expand All @@ -299,7 +299,7 @@ async def main():
asyncio.get_event_loop().run_until_complete(main())
```

```python-sync
```python sync
from playwright import sync_playwright

with sync_playwright() as p:
Expand Down

0 comments on commit 7a8214c

Please sign in to comment.