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
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
:pencil: - chore
:microscope: - experimental

## [3.2.0]
- :rocket: Added capability to provide _defaultResolver_ to define default logic to identify element
```typescript
class App {
defaultResolver({ alias }: { alias: string }) {
return ({ parent }: { parent: Locator }) => parent.getByText(alias);
}
}
```

## [3.1.0]
- :rocket: updated playwright to 1.53.0
- :rocket: added support of `locator.describe()` to log alias and corresponding locator
Expand Down
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ qavajs implementation for playwright test runner

## Installation

```
npm install @qavajs/playwright`
```bash
npm install @qavajs/playwright
```

## Configuration
Expand Down Expand Up @@ -38,13 +38,21 @@ export default defineConfig({

## Development and testing
Install dependencies
`npm install`
```bash
npm install
```

Install playwright browsers
`install:browsers`
```bash
install:browsers
```

Build lib
`npm run build`
```bash
npm run build
```

Execute e2e browser tests
`npm run test:e2e`
```bash
npm run test:e2e
```
44 changes: 22 additions & 22 deletions package-lock.json

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

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qavajs/playwright",
"version": "3.1.0",
"version": "3.2.0",
"description": "steps to interact with playwright",
"main": "./index.js",
"scripts": {
Expand All @@ -26,14 +26,14 @@
"homepage": "https://github.com/qavajs/playwright#readme",
"devDependencies": {
"@types/express": "^5.0.3",
"@types/node": "^24.0.1",
"electron": "^36.4.0",
"@types/node": "^24.1.0",
"electron": "^37.2.4",
"express": "^5.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
},
"dependencies": {
"@playwright/test": "^1.53.0",
"@playwright/test": "^1.54.1",
"@qavajs/playwright-runner-adapter": "^1.4.3",
"@qavajs/memory": "^1.10.2"
}
Expand Down
12 changes: 8 additions & 4 deletions src/pageObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,15 @@ export function query(root: any, path: string) {
for (const element of elements) {
const groups = element.match(/^(?<alias>.+?)(?:\((?<argument>.+)\))?$/)?.groups as { alias: string, argument: string };
const alias = groups.alias.replace(/\s/g, '');
if (!currentComponent) {
throw new Error(`Alias '${currentAlias}' is not a component`);
let currentElement = currentComponent[alias];
if (!currentElement && (!currentComponent.defaultResolver || typeof currentComponent.defaultResolver !== 'function')) {
throw new Error(`Alias '${alias}' has not been found in '${currentAlias}'`);
}
if (!currentElement && currentComponent.defaultResolver) {
currentElement = {};
currentElement.selector = currentComponent.defaultResolver({ alias: groups.alias, argument: groups.argument });
currentElement.type = 'native';
}
const currentElement = currentComponent[alias];
if (!currentElement) throw new Error(`Alias '${alias}' has not been found in '${currentAlias}'`);
currentAlias = groups.alias;
currentComponent = currentElement.component ? new currentElement.component() : null;

Expand Down
5 changes: 4 additions & 1 deletion test-e2e/features/pageObject.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ Feature: page object
Then I expect text of 'Simple Text Element ({$selector})' to be equal 'text value'

Scenario: top level component
Then I expect text of 'Top Level Component > Text Element' to be equal 'text value'
Then I expect text of 'Top Level Component > Text Element' to be equal 'text value'

Scenario: default resolver
Then I expect text of 'third value' to be equal 'third value'
5 changes: 5 additions & 0 deletions test-e2e/page_object/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { locator } from '../../src/pageObject';
import { Locator } from '@playwright/test';

export default class App {
SimpleTextElement = locator('#textValue');
Expand Down Expand Up @@ -69,6 +70,10 @@ export default class App {
BodyComponentNative = locator.native(({ page }) => page.locator('body')).as(BodyComponent);

TopLevelComponent = locator.as(BodyComponent);

defaultResolver({ alias }: { alias: string }) {
return ({ parent }: { parent: Locator }) => parent.getByText(alias);
}
}

class BodyComponent {
Expand Down