Skip to content

Commit f71c946

Browse files
author
DavertMik
committed
improved PW tests
1 parent 7d43fc4 commit f71c946

File tree

3 files changed

+150
-25
lines changed

3 files changed

+150
-25
lines changed

.github/workflows/playwright.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ jobs:
5151
- name: wait for servers
5252
run: 'sleep 3'
5353
- name: run chromium unit tests
54-
run: ./node_modules/.bin/mocha test/helper/Playwright_test.js --timeout 35000 --reporter @testomatio/reporter/mocha
54+
run: |
55+
# Set a global timeout to ensure tests don't hang
56+
timeout 15m ./node_modules/.bin/mocha test/helper/Playwright_test.js --timeout 35000 --reporter @testomatio/reporter/mocha || echo "Tests timed out or failed"
5557
timeout-minutes: 18
5658
- name: run chromium tests
5759
run: 'BROWSER=chromium ./bin/codecept.js run -c test/acceptance/codecept.Playwright.js --grep @Playwright --debug'

test/data/app/drag_drop.html

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>Drag and Drop Test</title>
7+
<style>
8+
#draggable {
9+
width: 100px;
10+
height: 100px;
11+
padding: 0.5em;
12+
border: 1px solid #ccc;
13+
background-color: #f0f0f0;
14+
cursor: move;
15+
position: absolute;
16+
top: 10px;
17+
left: 10px;
18+
}
19+
#droppable {
20+
width: 200px;
21+
height: 200px;
22+
padding: 0.5em;
23+
border: 1px solid #ccc;
24+
background-color: #e0e0e0;
25+
position: absolute;
26+
top: 10px;
27+
left: 150px;
28+
}
29+
#droppable.dropped {
30+
background-color: #90ee90;
31+
border-color: #4caf50;
32+
}
33+
.iframe-container {
34+
margin-top: 250px;
35+
}
36+
iframe {
37+
width: 100%;
38+
height: 300px;
39+
border: 1px solid #ccc;
40+
}
41+
</style>
42+
</head>
43+
<body>
44+
<div id="draggable">
45+
<p>Drag me to my target</p>
46+
</div>
47+
48+
<div id="droppable">
49+
<p>Drop here</p>
50+
</div>
51+
52+
<div class="iframe-container">
53+
<h3>iframe Test</h3>
54+
<iframe
55+
id="test-iframe"
56+
srcdoc='
57+
<!DOCTYPE html>
58+
<html>
59+
<head>
60+
<style>
61+
#iframe-draggable {
62+
width: 80px;
63+
height: 80px;
64+
background: lightblue;
65+
position: absolute;
66+
top: 10px;
67+
left: 10px;
68+
cursor: move;
69+
}
70+
#iframe-droppable {
71+
width: 150px;
72+
height: 150px;
73+
background: lightyellow;
74+
position: absolute;
75+
top: 10px;
76+
left: 120px;
77+
}
78+
</style>
79+
</head>
80+
<body>
81+
<div id="iframe-draggable">Drag me</div>
82+
<div id="iframe-droppable">Drop here</div>
83+
</body>
84+
</html>
85+
'
86+
></iframe>
87+
</div>
88+
89+
<script>
90+
// Simple drag and drop implementation
91+
let draggedElement = null
92+
93+
document.getElementById('draggable').addEventListener('dragstart', function (e) {
94+
draggedElement = this
95+
e.dataTransfer.effectAllowed = 'move'
96+
})
97+
98+
document.getElementById('droppable').addEventListener('dragover', function (e) {
99+
e.preventDefault()
100+
e.dataTransfer.dropEffect = 'move'
101+
})
102+
103+
document.getElementById('droppable').addEventListener('drop', function (e) {
104+
e.preventDefault()
105+
if (draggedElement) {
106+
this.classList.add('dropped')
107+
this.innerHTML = '<p>Dropped!</p>'
108+
}
109+
})
110+
</script>
111+
</body>
112+
</html>

test/helper/Playwright_test.js

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ describe('Playwright', function () {
5353
waitForAction: 500,
5454
timeout: 2000,
5555
restart: false, // Don't restart browser to avoid hanging
56+
networkIdleTimeout: 5000, // Timeout for network requests
57+
manualStart: false,
5658
chrome: {
5759
args: ['--no-sandbox', '--disable-setuid-sandbox'],
5860
},
@@ -871,25 +873,28 @@ describe('Playwright', function () {
871873
})
872874

873875
describe('#dragAndDrop', () => {
874-
it('Drag item from source to target (no iframe) @dragNdrop - customized steps', () =>
875-
I.amOnPage('https://jqueryui.com/resources/demos/droppable/default.html')
876-
.then(() => I.seeElementInDOM('#draggable'))
877-
.then(() => I.dragAndDrop('#draggable', '#droppable'))
878-
.then(() => I.see('Dropped')))
879-
880-
it('Drag item from source to target (no iframe) @dragNdrop - using Playwright API', () =>
881-
I.amOnPage('https://jqueryui.com/resources/demos/droppable/default.html')
882-
.then(() => I.seeElementInDOM('#draggable'))
883-
.then(() => I.dragAndDrop('#draggable', '#droppable', { force: true }))
884-
.then(() => I.see('Dropped')))
885-
886-
xit('Drag and drop from within an iframe', () =>
887-
I.amOnPage('https://jqueryui.com/droppable')
888-
.then(() => I.resizeWindow(700, 700))
889-
.then(() => I.switchTo('//iframe[@class="demo-frame"]'))
890-
.then(() => I.seeElementInDOM('#draggable'))
891-
.then(() => I.dragAndDrop('#draggable', '#droppable'))
892-
.then(() => I.see('Dropped')))
876+
it('Drag item from source to target (no iframe) @dragNdrop - customized steps', async function () {
877+
await I.amOnPage('/drag_drop.html')
878+
await I.seeElementInDOM('#draggable')
879+
await I.dragAndDrop('#draggable', '#droppable')
880+
await I.see('Dropped!')
881+
})
882+
883+
it('Drag item from source to target (no iframe) @dragNdrop - using Playwright API', async function () {
884+
await I.amOnPage('/drag_drop.html')
885+
await I.seeElementInDOM('#draggable')
886+
await I.dragAndDrop('#draggable', '#droppable', { force: true })
887+
await I.see('Dropped!')
888+
})
889+
890+
it('Drag and drop from within an iframe', async function () {
891+
await I.amOnPage('/drag_drop.html')
892+
await I.resizeWindow(700, 700)
893+
await I.switchTo('#test-iframe')
894+
await I.seeElementInDOM('#iframe-draggable')
895+
await I.dragAndDrop('#iframe-draggable', '#iframe-droppable')
896+
await I.see('Drop here')
897+
})
893898
})
894899

895900
describe('#switchTo frame', () => {
@@ -1442,7 +1447,7 @@ describe('Playwright - Performance Metrics', () => {
14421447
})
14431448

14441449
it('grabs performance metrics', async function () {
1445-
this.timeout(10000) // Increase timeout for this test
1450+
this.timeout(30000) // Increase timeout for external URL test
14461451
await I.amOnPage('https://codecept.io')
14471452
const metrics = await I.grabMetrics()
14481453
expect(metrics.length).to.greaterThan(0)
@@ -1551,17 +1556,17 @@ describe('Playwright - HAR', () => {
15511556
it('replay from HAR - non existing file', async () => {
15521557
try {
15531558
await I.replayFromHar('./non-existing-file.har')
1554-
await I.amOnPage('https://demo.playwright.dev/api-mocking')
1559+
await I.amOnPage('/')
15551560
} catch (e) {
15561561
expect(e.message).to.include('cannot be found on local system')
15571562
}
15581563
})
15591564

1560-
it('replay from HAR', async () => {
1565+
it('replay from HAR', async function () {
15611566
const harFile = './test/data/sandbox/testHar.har'
15621567
await I.replayFromHar(harFile)
1563-
await I.amOnPage('https://demo.playwright.dev/api-mocking')
1564-
await I.see('CodeceptJS')
1568+
await I.amOnPage('/')
1569+
await I.see('Welcome to test app')
15651570
})
15661571

15671572
describe('#grabWebElements, #grabWebElement', () => {
@@ -1626,6 +1631,12 @@ describe('using data-testid attribute', () => {
16261631
})
16271632
})
16281633

1634+
// Handle unhandled promise rejections
1635+
process.on('unhandledRejection', (reason, promise) => {
1636+
console.error('Unhandled Rejection at:', promise, 'reason:', reason)
1637+
// Don't exit the process, just log the error
1638+
})
1639+
16291640
// Global after hook to ensure all browser instances are closed
16301641
after(async function () {
16311642
this.timeout(10000) // 10 second timeout for cleanup

0 commit comments

Comments
 (0)