From b7a1a131c153225f258cf77be92a6b95b36dc560 Mon Sep 17 00:00:00 2001 From: AlexandrLegchilov Date: Wed, 2 Oct 2024 16:14:10 +0300 Subject: [PATCH 1/6] add permissions steps --- CHANGELOG.md | 5 ++++- package-lock.json | 4 ++-- package.json | 2 +- src/actions.ts | 32 +++++++++++++++++++++++++++++++ test-e2e/apps/actions.html | 9 ++++++++- test-e2e/features/actions.feature | 16 ++++++++++++++++ test-e2e/memory/index.ts | 5 ++++- test-e2e/page_object/index.ts | 1 + 8 files changed, 68 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 81d71bc..ceeb797 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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} browser permissions_ 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] diff --git a/package-lock.json b/package-lock.json index f0d268b..3f68591 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@qavajs/steps-playwright", - "version": "0.52.0", + "version": "0.53.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@qavajs/steps-playwright", - "version": "0.52.0", + "version": "0.53.0", "license": "MIT", "dependencies": { "@playwright/test": "^1.47.0", diff --git a/package.json b/package.json index ff80cc8..8afb455 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/actions.ts b/src/actions.ts index 0b0e352..2d3b2d7 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -3,6 +3,7 @@ import { getValue, getElement } from './transformers'; import { po } from '@qavajs/po-playwright'; import { expect, Browser, BrowserContext, Page } from '@playwright/test'; import { parseCoords, parseCoordsAsObject, sleep } from './utils/utils'; +import memory from "@qavajs/memory"; declare global { var browser: Browser; @@ -465,3 +466,34 @@ When('I tap {string}', async function (alias: string) { const element = await getElement(alias); await element.tap(); }); + +/** + * Grants specified permissions to the browser context. + * @param {string} permissionsAlias - permissions array memory alias. + * @example I grant '$microphone' browser permissions + * where '$location' is memory alias of permissions array - ['geolocation']; + * Permissions documentation can be found here https://playwright.dev/docs/api/class-browsercontext#browser-context-grant-permissions-option-permissions + */ +When('I grant {string} browser permissions', async function (permissionsAlias: string) { + const permissions = await memory.getValue(permissionsAlias); + await context.grantPermissions(permissions); +}); + +/** + * 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 memory.getValue(geolocationAlias); + await context.setGeolocation(geolocation); +}); diff --git a/test-e2e/apps/actions.html b/test-e2e/apps/actions.html index a264ea4..1305d75 100644 --- a/test-e2e/apps/actions.html +++ b/test-e2e/apps/actions.html @@ -76,8 +76,15 @@
- +