Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add aliasing in Element questions #88

Merged
merged 3 commits into from
Aug 12, 2024
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
11 changes: 11 additions & 0 deletions __tests__/aliasing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Actor } from '@testla/screenplay';
import { UseAPI } from '../src/api/abilities/UseAPI';
import { Get } from '../src/api/actions/Get';
import { BrowseTheWeb, Navigate } from '../src/web';
import { Element } from '../src/web/questions/Element';

const ALIAS = 'alias';

Expand Down Expand Up @@ -48,4 +49,14 @@ test.describe('Testing screenplay-playwright-js ability aliasing', () => {
);
await expect(BrowseTheWeb.as(actor, ALIAS).getPage()).toHaveURL('https://www.google.com');
});

test('BrowseTheWeb - Question with aliasing', async ({ actor }) => {
await actor.attemptsTo(
Navigate.to('https://the-internet.herokuapp.com/tables').withAbilityAlias(ALIAS),
);

await actor.asks(
Element.toHave.text('h3', 'Data Tables').withAbilityAlias(ALIAS),
);
});
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@testla/screenplay-playwright",
"version": "1.6.0",
"version": "1.6.1",
"description": "Implementation of the Playwright abilities, actions and questions.",
"main": "index.js",
"types": "index.d.ts",
Expand Down Expand Up @@ -61,4 +61,4 @@
"publishConfig": {
"access": "public"
}
}
}
4 changes: 3 additions & 1 deletion qodana.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
version: "1.0"
linter: jetbrains/qodana-js:2023.3
linter: jetbrains/qodana-js:2024.1
include:
- name: CheckDependencyLicenses
- name: DuplicatedCode
exclude:
- name: ES6PreferShortImport
26 changes: 25 additions & 1 deletion src/web/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,43 @@ import { Add } from './actions/Add';
import { Check } from './actions/Check';
import { Clear } from './actions/Clear';
import { Click } from './actions/Click';
import { Count } from './actions/Count';
import { DoubleClick } from './actions/DoubleClick';
import { Download } from './actions/Download';
import { DragAndDrop } from './actions/DragAndDrop';
import { Fill } from './actions/Fill';
import { Get } from './actions/Get';
import { Hover } from './actions/Hover';
import { Navigate } from './actions/Navigate';
import { Press } from './actions/Press';
import { Reload } from './actions/Reload';
import { Remove } from './actions/Remove';
import { Select } from './actions/Select';
import { Set } from './actions/Set';
import { Type } from './actions/Type';
import { Wait } from './actions/Wait';
import { Element } from './questions/Element';

export {
BrowseTheWeb, Check, Wait, Hover, Navigate, Fill, Press, DragAndDrop, Click, DoubleClick, Type, Element, Get, Add, Clear, Remove, Set,
BrowseTheWeb,
Add,
Check,
Clear,
Click,
Count,
DoubleClick,
Download,
DragAndDrop,
Fill,
Get,
Hover,
Navigate,
Press,
Reload,
Remove,
Select,
Set,
Type,
Wait,
Element,
};
18 changes: 9 additions & 9 deletions src/web/questions/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export class Element extends FrameEnabledQuestion {
*/
public async answeredBy(actor: Actor): Promise<boolean> {
const {
mode, selector, payload, checkMode, options, frameTree,
mode, selector, payload, checkMode, options, frameTree, abilityAlias,
} = this;

if (mode === 'visible') {
const locator = await BrowseTheWeb.as(actor).resolveSelectorToLocator(selector, { ...options, state: checkMode === 'positive' ? 'visible' : 'hidden' }, frameTree);
const locator = await BrowseTheWeb.as(actor, abilityAlias).resolveSelectorToLocator(selector, { ...options, state: checkMode === 'positive' ? 'visible' : 'hidden' }, frameTree);

if (this.checkMode === 'positive') {
await expect(locator).toBeVisible({ timeout: options?.timeout });
Expand All @@ -49,7 +49,7 @@ export class Element extends FrameEnabledQuestion {
return Promise.resolve(true); // if the ability method is not the expected result there will be an exception
}
if (mode === 'enabled') {
const locator = await BrowseTheWeb.as(actor).resolveSelectorToLocator(selector, options, frameTree);
const locator = await BrowseTheWeb.as(actor, abilityAlias).resolveSelectorToLocator(selector, options, frameTree);

if (this.checkMode === 'positive') {
await expect(locator).toBeEnabled({ timeout: options?.timeout });
Expand All @@ -59,7 +59,7 @@ export class Element extends FrameEnabledQuestion {
return Promise.resolve(true); // if the ability method is not the expected result there will be an exception
}
if (mode === 'text') {
const locator = await BrowseTheWeb.as(actor).resolveSelectorToLocator(selector, options, frameTree);
const locator = await BrowseTheWeb.as(actor, abilityAlias).resolveSelectorToLocator(selector, options, frameTree);

if (this.checkMode === 'positive') {
await expect(locator).toHaveText(payload as string, { timeout: options?.timeout });
Expand All @@ -69,7 +69,7 @@ export class Element extends FrameEnabledQuestion {
return Promise.resolve(true); // if the ability method is not the expected result there will be an exception
}
if (mode === 'value') {
const locator = await BrowseTheWeb.as(actor).resolveSelectorToLocator(selector, options, frameTree);
const locator = await BrowseTheWeb.as(actor, abilityAlias).resolveSelectorToLocator(selector, options, frameTree);

if (this.checkMode === 'positive') {
await expect(locator).toHaveValue(payload as string | RegExp, { timeout: options?.timeout });
Expand All @@ -79,7 +79,7 @@ export class Element extends FrameEnabledQuestion {
return Promise.resolve(true); // if the ability method is not the expected result there will be an exception
}
if (mode === 'checked') {
const locator = await BrowseTheWeb.as(actor).resolveSelectorToLocator(selector, options, frameTree);
const locator = await BrowseTheWeb.as(actor, abilityAlias).resolveSelectorToLocator(selector, options, frameTree);

if (this.checkMode === 'positive') {
await expect(locator).toBeChecked({ timeout: options?.timeout });
Expand All @@ -89,7 +89,7 @@ export class Element extends FrameEnabledQuestion {
return Promise.resolve(true); // if the ability method is not the expected result there will be an exception
}
if (mode === 'count') {
const locator = await BrowseTheWeb.as(actor).resolveSelectorToLocator(selector, { ...options, evaluateVisible: false }, frameTree);
const locator = await BrowseTheWeb.as(actor, abilityAlias).resolveSelectorToLocator(selector, { ...options, evaluateVisible: false }, frameTree);

if (this.checkMode === 'positive') {
await expect(locator).toHaveCount(payload as number, { timeout: options?.timeout });
Expand All @@ -100,9 +100,9 @@ export class Element extends FrameEnabledQuestion {
}
if (mode === 'minCount') {
if (checkMode === 'positive') {
await BrowseTheWeb.as(actor).resolveSelectorToLocator(`${selector} >> nth=${payload as number - 1}`, options, frameTree);
await BrowseTheWeb.as(actor, abilityAlias).resolveSelectorToLocator(`${selector} >> nth=${payload as number - 1}`, options, frameTree);
} else {
await BrowseTheWeb.as(actor).resolveSelectorToLocator(`${selector} >> nth=${payload as number - 1}`, { ...options, state: 'hidden' }, frameTree);
await BrowseTheWeb.as(actor, abilityAlias).resolveSelectorToLocator(`${selector} >> nth=${payload as number - 1}`, { ...options, state: 'hidden' }, frameTree);
}

return Promise.resolve(true);
Expand Down
Loading