Skip to content

Commit

Permalink
fix: remove unsupported default_browser_type option and improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkurev committed Jan 14, 2024
1 parent d8a88c5 commit 459e33c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/internal/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async def new_context(

# PlaywrightError: options.isMobile is not supported in Firefox
del options['is_mobile']
del options['default_browser_type']

options |= {
'bypass_csp': True,
Expand Down
3 changes: 2 additions & 1 deletion app/routers/query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ def __init__(
'and whether it has touch enabled.<br>Individual parameters like `user-agent`, `viewport-width`, and `viewport-height` '
'can also be used; in such cases, they will override the `device` settings.<br>'
'List of [available devices]'
'(https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json).<br><br>'
'(https://github.com/microsoft/playwright/blob/main/packages/playwright-core/src/server/deviceDescriptorsSource.json).'
'<br><br>'
),
),
] = 'iPhone 12',
Expand Down
31 changes: 31 additions & 0 deletions app/routers/test_query_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,37 @@ def test_various_query_params():
'url': 'https://en.wikipedia.org/wiki/African_humid_period',
'cache': False,
'screenshot': True,
'device': 'Desktop Firefox', # to raise (Page.screenshot): Cannot take screenshot larger than 32767
}
response = client.get(api_url, params=params)
assert response.status_code == 200

# test viewport and screen settings
url = 'https://en.wikipedia.org/wiki/World_Wide_Web'
params = {
'url': url,
'cache': False,
'viewport-width': 390,
'viewport-height': 844,
'screen-width': 1170,
'screen-height': 2532,
'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4 like Mac OS X) '
}
response = client.get(api_url, params=params)
assert response.status_code == 200

# test wrong device name
params = {
'url': url,
'device': 'not-exists',
}
response = client.get(api_url, params=params)
assert response.status_code == 422
assert response.json() == {
'detail': [{
'input': 'not-exists',
'loc': ['query', 'device'],
'msg': 'Device not found',
'type': 'device_parsing',
}]
}

0 comments on commit 459e33c

Please sign in to comment.