Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
:pencil: - chore
:microscope: - experimental

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

## [0.52.0]
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qavajs/steps-playwright",
"version": "0.52.0",
"version": "0.53.0",
"description": "steps to interact with playwright",
"main": "./index.js",
"scripts": {
Expand Down
30 changes: 30 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,3 +465,33 @@ When('I tap {string}', async function (alias: string) {
const element = await getElement(alias);
await element.tap();
});

/**
* Grants specified permission to the browser context.
* @param {string} permissionAlias - permission alias.
* @example I grant 'geolocation' permission
* Permissions documentation can be found here https://playwright.dev/docs/api/class-browsercontext#browser-context-grant-permissions-option-permissions
*/
When('I grant {string} permission', async function (permissionAlias: string) {
const permission = await getValue(permissionAlias);
await context.grantPermissions([permission]);
});

/**
* Clears all permission overrides for the browser context.
*/
When('I revoke browser permissions', async function () {
await context.clearPermissions();
});

/**
* Sets a geolocation for a current context.
* @param {string} geolocationAlias - geolocation memory alias.
* @example I set '$minsk' geolocation
* where '$minsk' is memory alias of location object { latitude: 53.53, longitude: 27.34 };
* Passing null or undefined emulates position unavailable.
*/
When('I set {string} geolocation', async function (geolocationAlias: string) {
const geolocation = await getValue(geolocationAlias);
await context.setGeolocation(geolocation);
});
9 changes: 8 additions & 1 deletion test-e2e/apps/actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,15 @@

<div id="mouseEvent" style="height: 200px; width: 200px; background-color: #0f9e9e"></div>
<input id="keyboardEvent" style="height: 200px; width: 200px; background-color: #0f9e9e"></input>

<button id="location" onclick="getLocation()">No location</button>
<script>
const locationButton = document.getElementById("location");
function getLocation() {
navigator.geolocation.watchPosition(showPosition);
}
function showPosition(position) {
locationButton.innerText = `{"latitude":${position.coords.latitude},"longitude":${position.coords.longitude}}`;
}
const action = document.querySelector('#action');
const button = document.querySelector('#button');
const buttonTap = document.querySelector('#buttonTap');
Expand Down
16 changes: 16 additions & 0 deletions test-e2e/features/actions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,19 @@ Feature: actions

Scenario: scroll until visible in element
When I scroll in 'Infinite Scroll' until '#row 34 in Infinite Scroll Items' to be visible

Scenario: set location
When I set '$canada' geolocation
When I grant '$location' permission
When I click 'Location Button'
When I expect text of 'Location Button' to equal '$js(JSON.stringify($canada))'

Scenario: revoke permissions
When I set '$canada' geolocation
When I grant 'geolocation' permission
When I click 'Location Button'
When I expect text of 'Location Button' to equal '$js(JSON.stringify($canada))'
When I revoke browser permissions
When I refresh page
When I click 'Location Button'
When I expect text of 'Location Button' to equal 'No location'
5 changes: 4 additions & 1 deletion test-e2e/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,8 @@ export default class Memory {
button2 = 'Button2';

userInterceptionPredicate = (response: Response) => response.url().includes('users');
}

location = 'geolocation';

canada = { latitude: 62.39, longitude: -96.81};
}
1 change: 1 addition & 0 deletions test-e2e/page_object/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default class App {
PlusButton = $('#plusButton');
FetchButton = $('#fetchButton');
FetchResult = $('#fetchResult');
LocationButton = $('#location');

// Electron
OpenNewWindowElectronButton = $('#electronButton');
Expand Down