Skip to content

Commit 3fc68b7

Browse files
author
Oleksandr_Halichenko
committed
added I upload file step
1 parent 4e4f937 commit 3fc68b7

File tree

8 files changed

+565
-527
lines changed

8 files changed

+565
-527
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
## 0.0.12
2+
- :rocket: added _I upload file_ step
3+
14
## 0.0.11
25
- :rocket: removed po package dependency
36
- :rocket: added util functions exports to build custom steps
4-
-
7+
58
## 0.0.9
69
- :rocket: added scroll by offset steps
710
- :rocket: updated po dependency to support ignoreHierarchy options

package-lock.json

Lines changed: 522 additions & 522 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@qavajs/steps-playwright",
3-
"version": "0.0.11",
3+
"version": "0.0.12",
44
"description": "steps to interact with playwright",
55
"main": "./index.js",
66
"scripts": {
@@ -29,11 +29,11 @@
2929
"@qavajs/xunit-formatter": "^0.0.3",
3030
"@types/chai": "^4.3.4",
3131
"@types/jest": "^29.4.0",
32-
"jest": "^29.4.0",
32+
"jest": "^29.4.1",
3333
"ts-jest": "^29.0.5",
3434
"ts-node": "^10.9.1",
3535
"typescript": "^4.9.4",
36-
"@qavajs/po-playwright": "^0.0.6"
36+
"@qavajs/po-playwright": "^0.0.7"
3737
},
3838
"dependencies": {
3939
"@playwright/test": "^1.30.0",

src/actions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,3 +196,16 @@ When('I scroll by {string} in {string}', async function (offset: string, alias:
196196
element.scrollBy(...coords as [number, number]);
197197
}, coords);
198198
});
199+
200+
201+
/**
202+
* Provide file url to upload input
203+
* @param {string} alias - element to upload file
204+
* @param {string} value - file path
205+
* @example I upload '/folder/file.txt' to 'File Input'
206+
*/
207+
When('I upload {string} file to {string}', async function (value: string, alias: string) {
208+
const element = await getElement(alias);
209+
const filePath = await getValue(value);
210+
await element.setInputFiles(filePath);
211+
});

test-e2e/apps/actions.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<button id="button">Click Me!</button>
1010
<button id="buttonHover">Hover Me!</button>
1111
<label for="input"></label><input type="text" id="input"/>
12+
<input type="file" id="fileInput"/>
1213
<button class="button">Button1</button>
1314
<button class="button">Button2</button>
1415
<button class="button">Button3</button>
@@ -50,6 +51,7 @@
5051
const button = document.querySelector('#button');
5152
const buttonHover = document.querySelector('#buttonHover');
5253
const input = document.querySelector('#input');
54+
const fileInput = document.querySelector('#fileInput');
5355
const buttons = document.querySelectorAll('.button');
5456
const body = document.body;
5557
const select = document.querySelector('#select');
@@ -76,6 +78,10 @@
7678
action.innerText = input.value;
7779
});
7880

81+
fileInput.addEventListener('input', function () {
82+
action.innerText = 'file:' + fileInput.value;
83+
});
84+
7985
buttons.forEach(b => {
8086
b.addEventListener('click', function () {
8187
action.innerText = b.innerText;

test-e2e/features/actions.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,12 @@ Feature: actions
8484
Scenario: type in ignore hierarchy component
8585
When I type 'test value' to 'IgnoreHierarchyComponent > Input'
8686
Then I expect text of 'Action' to be equal 'test value'
87+
88+
Scenario: type in component without selector
89+
When I type 'test value' to 'Component Without Selector > Input'
90+
Then I expect text of 'Action' to be equal 'test value'
91+
92+
Scenario: upload file
93+
When I upload '$uploadFile' file to 'File Input'
94+
Then I expect text of 'Action' to be equal 'file:C:\fakepath\actions.html'
95+

test-e2e/memory/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ export default class Memory {
2828
{"name": "Memory Mock 2"},
2929
{"name": "Memory Mock 3"}
3030
]);
31+
32+
uploadFile = resolve('./test-e2e/apps/actions.html');
3133
}
3234

test-e2e/page_object/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default class App {
33
SimpleTextElement = $('#textValue');
44
SimpleTextListItems = $$('#textValueList li');
55
SimpleTextInput = $('#textInput');
6-
6+
FileInput = $('#fileInput');
77
Action = $('#action');
88
Button = $('#button');
99
ButtonHover = $('#buttonHover');
@@ -28,9 +28,14 @@ export default class App {
2828
OverflowContainer = $('#overflowContainer');
2929

3030
IgnoreHierarchyComponent = $(new IgnoreHierarchyComponent('#ignoreHierarchyComponent'));
31+
ComponentWithoutSelector = $(new ComponentWithoutSelector());
3132

3233
}
3334

3435
class IgnoreHierarchyComponent extends Component {
3536
Input = $('#input', { ignoreHierarchy: true });
3637
}
38+
39+
class ComponentWithoutSelector {
40+
Input = $('#input');
41+
}

0 commit comments

Comments
 (0)