Skip to content

Commit 7e3a61b

Browse files
authored
add permissions steps (#130)
1 parent 37d267c commit 7e3a61b

File tree

8 files changed

+66
-6
lines changed

8 files changed

+66
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1010
:pencil: - chore
1111
:microscope: - experimental
1212

13-
## [Unreleased]
13+
## [0.53.0]
14+
- :rocket: added _I grant {string} permission_ step
15+
- :rocket: added _I revoke browser permissions_ step
16+
- :rocket: added _I set {string} geolocation_ step
1417
- :beetle: improved _I scroll until_ steps to use same locator
1518

1619
## [0.52.0]

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/steps-playwright",
3-
"version": "0.52.0",
3+
"version": "0.53.0",
44
"description": "steps to interact with playwright",
55
"main": "./index.js",
66
"scripts": {

src/actions.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,3 +465,33 @@ When('I tap {string}', async function (alias: string) {
465465
const element = await getElement(alias);
466466
await element.tap();
467467
});
468+
469+
/**
470+
* Grants specified permission to the browser context.
471+
* @param {string} permissionAlias - permission alias.
472+
* @example I grant 'geolocation' permission
473+
* Permissions documentation can be found here https://playwright.dev/docs/api/class-browsercontext#browser-context-grant-permissions-option-permissions
474+
*/
475+
When('I grant {string} permission', async function (permissionAlias: string) {
476+
const permission = await getValue(permissionAlias);
477+
await context.grantPermissions([permission]);
478+
});
479+
480+
/**
481+
* Clears all permission overrides for the browser context.
482+
*/
483+
When('I revoke browser permissions', async function () {
484+
await context.clearPermissions();
485+
});
486+
487+
/**
488+
* Sets a geolocation for a current context.
489+
* @param {string} geolocationAlias - geolocation memory alias.
490+
* @example I set '$minsk' geolocation
491+
* where '$minsk' is memory alias of location object { latitude: 53.53, longitude: 27.34 };
492+
* Passing null or undefined emulates position unavailable.
493+
*/
494+
When('I set {string} geolocation', async function (geolocationAlias: string) {
495+
const geolocation = await getValue(geolocationAlias);
496+
await context.setGeolocation(geolocation);
497+
});

test-e2e/apps/actions.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,15 @@
7676

7777
<div id="mouseEvent" style="height: 200px; width: 200px; background-color: #0f9e9e"></div>
7878
<input id="keyboardEvent" style="height: 200px; width: 200px; background-color: #0f9e9e"></input>
79-
79+
<button id="location" onclick="getLocation()">No location</button>
8080
<script>
81+
const locationButton = document.getElementById("location");
82+
function getLocation() {
83+
navigator.geolocation.watchPosition(showPosition);
84+
}
85+
function showPosition(position) {
86+
locationButton.innerText = `{"latitude":${position.coords.latitude},"longitude":${position.coords.longitude}}`;
87+
}
8188
const action = document.querySelector('#action');
8289
const button = document.querySelector('#button');
8390
const buttonTap = document.querySelector('#buttonTap');

test-e2e/features/actions.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,19 @@ Feature: actions
241241

242242
Scenario: scroll until visible in element
243243
When I scroll in 'Infinite Scroll' until '#row 34 in Infinite Scroll Items' to be visible
244+
245+
Scenario: set location
246+
When I set '$canada' geolocation
247+
When I grant '$location' permission
248+
When I click 'Location Button'
249+
When I expect text of 'Location Button' to equal '$js(JSON.stringify($canada))'
250+
251+
Scenario: revoke permissions
252+
When I set '$canada' geolocation
253+
When I grant 'geolocation' permission
254+
When I click 'Location Button'
255+
When I expect text of 'Location Button' to equal '$js(JSON.stringify($canada))'
256+
When I revoke browser permissions
257+
When I refresh page
258+
When I click 'Location Button'
259+
When I expect text of 'Location Button' to equal 'No location'

test-e2e/memory/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,8 @@ export default class Memory {
3737
button2 = 'Button2';
3838

3939
userInterceptionPredicate = (response: Response) => response.url().includes('users');
40-
}
4140

41+
location = 'geolocation';
42+
43+
canada = { latitude: 62.39, longitude: -96.81};
44+
}

test-e2e/page_object/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export default class App {
6060
PlusButton = $('#plusButton');
6161
FetchButton = $('#fetchButton');
6262
FetchResult = $('#fetchResult');
63+
LocationButton = $('#location');
6364

6465
// Electron
6566
OpenNewWindowElectronButton = $('#electronButton');

0 commit comments

Comments
 (0)