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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ node_modules/
lib/
coverage/
test-e2e/report.*
test-e2e/downloads/
.idea/
traces/
video/
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
:pencil: - chore
:microscope: - experimental

## [0.54.0]
- :rocket: added _I save file to {string} by clicking {string}_ step

## [0.53.0]
- :rocket: added _I grant {string} permission_ step
- :rocket: added _I revoke browser permissions_ step
Expand Down
58 changes: 35 additions & 23 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@qavajs/steps-playwright",
"version": "0.53.0",
"version": "0.54.0",
"description": "steps to interact with playwright",
"main": "./index.js",
"scripts": {
Expand All @@ -26,11 +26,11 @@
},
"homepage": "https://github.com/qavajs/steps-playwright#readme",
"devDependencies": {
"@cucumber/cucumber": "^11.0.0",
"@cucumber/cucumber": "^11.0.1",
"@qavajs/cli": "^0.40.0",
"@qavajs/console-formatter": "^0.7.2",
"@qavajs/console-formatter": "^0.8.0",
"@qavajs/html-formatter": "^0.18.1",
"@qavajs/memory": "^1.8.0",
"@qavajs/memory": "^1.9.0",
"@qavajs/webstorm-adapter": "^8.0.0",
"@types/chai": "^4.3.17",
"@types/express": "^4.17.21",
Expand All @@ -46,6 +46,6 @@
},
"dependencies": {
"@playwright/test": "^1.47.0",
"@qavajs/po-playwright": "^0.16.0"
"@qavajs/po-playwright": "^0.16.1"
}
}
15 changes: 15 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,21 @@ When('I scroll in {string} until {string} to be visible', async function (scroll
}
});

/**
* Save a file to relative path
* @param {string} pathAlias - file path
* @param {string} initiatorAlias - alias of an element triggering downloading process
* @example I save file to './folder/file.pdf' by clicking 'Download Button'
*/
When('I save file to {string} by clicking {string}', async function (pathAlias: string, initiatorAlias: string) {
const downloadPromise = page.waitForEvent('download');
const element = await getElement(await getValue(initiatorAlias));
const path = await getValue(pathAlias);
await element.click();
const download = await downloadPromise;
await download.saveAs(path);
});

/**
* Provide file url to upload input
* @param {string} alias - element to upload file
Expand Down
1 change: 1 addition & 0 deletions test-e2e/apps/actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
<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>
<a id="download" href="data:text/plain;charset=utf-8,Hello%20World!" download="hello.txt">Click to download</a>
<script>
const locationButton = document.getElementById("location");
function getLocation() {
Expand Down
4 changes: 4 additions & 0 deletions test-e2e/features/actions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,7 @@ Feature: actions
When I refresh page
When I click 'Location Button'
When I expect text of 'Location Button' to equal 'No location'

Scenario: save file
When I save file to '$downloadPath' by clicking 'Download Button'
When I expect file '$downloadPath' to exist
2 changes: 2 additions & 0 deletions test-e2e/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,6 @@ export default class Memory {
location = 'geolocation';

canada = { latitude: 62.39, longitude: -96.81};

downloadPath = './test-e2e/downloads/text.txt';
}
1 change: 1 addition & 0 deletions test-e2e/page_object/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default class App {
FetchButton = $('#fetchButton');
FetchResult = $('#fetchResult');
LocationButton = $('#location');
DownloadButton = $('#download');

// Electron
OpenNewWindowElectronButton = $('#electronButton');
Expand Down
9 changes: 7 additions & 2 deletions test-e2e/step-definitions/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Then } from '@cucumber/cucumber';
import memory from '@qavajs/memory';
import { Page, expect } from '@playwright/test';
import {getElement} from "../../src/transformers";
import {getValidation} from "@qavajs/validation";
import {getValue} from "../../src/transformers";
import * as fs from "fs";

declare global {
var page: Page;
Expand Down Expand Up @@ -41,3 +41,8 @@ Then('I set {int} ms delayed mock for {string} request', async function (delay:
}), delay);
});
})

Then('I expect file {string} to exist', async function (path: string){
const filePresence = fs.existsSync(await getValue(path));
expect(filePresence).toBeTruthy();
});