|
1 | 1 | import { Selector, ClientFunction } from 'testcafe'; |
2 | 2 |
|
| 3 | +import { |
| 4 | + saveWindowState, |
| 5 | + restoreWindowState, |
| 6 | + getWindowHeight, |
| 7 | + getWindowWidth |
| 8 | +} from '../../../../window-helpers'; |
| 9 | + |
| 10 | + |
3 | 11 | const reload = ClientFunction(() => window.location.reload()); |
4 | 12 |
|
5 | 13 | const parentUrl = 'http://localhost:3000/fixtures/multiple-windows/pages/api/parent.html'; |
@@ -329,3 +337,66 @@ test('Refresh child and switch to parent', async t => { |
329 | 337 |
|
330 | 338 | await t.switchToParentWindow(); |
331 | 339 | }); |
| 340 | + |
| 341 | +fixture `Resize multiple windows` |
| 342 | + .page(parentUrl) |
| 343 | + .beforeEach(async t => { |
| 344 | + await saveWindowState(t); |
| 345 | + }) |
| 346 | + .afterEach(async t => { |
| 347 | + await restoreWindowState(t); |
| 348 | + }); |
| 349 | + |
| 350 | +test('Resize multiple windows', async t => { |
| 351 | + await t.resizeWindow(600, 600); |
| 352 | + await t.expect(await getWindowWidth()).eql(600); |
| 353 | + await t.expect(await getWindowHeight()).eql(600); |
| 354 | + |
| 355 | + await t.openWindow(child1Url); |
| 356 | + |
| 357 | + await t.resizeWindow(550, 550); |
| 358 | + await t.expect(await getWindowWidth()).eql(550); |
| 359 | + await t.expect(await getWindowHeight()).eql(550); |
| 360 | + |
| 361 | + await t.switchToParentWindow(); |
| 362 | + |
| 363 | + await t.expect(await getWindowWidth()).eql(600); |
| 364 | + await t.expect(await getWindowHeight()).eql(600); |
| 365 | + |
| 366 | + await t.resizeWindow(500, 500); |
| 367 | + |
| 368 | + await t.expect(await getWindowWidth()).eql(500); |
| 369 | + await t.expect(await getWindowHeight()).eql(500); |
| 370 | +}); |
| 371 | + |
| 372 | +test('Maximize multiple windows', async t => { |
| 373 | + // NOTE: to be sure that window is is maximized we check |
| 374 | + // that the width/height value increased at least on 10px |
| 375 | + const e = 10; |
| 376 | + |
| 377 | + const parentWidth = await getWindowWidth(); |
| 378 | + const parentHeight = await getWindowHeight(); |
| 379 | + |
| 380 | + await t.openWindow(child1Url); |
| 381 | + |
| 382 | + const childWidth = await getWindowWidth(); |
| 383 | + const childHeight = await getWindowHeight(); |
| 384 | + |
| 385 | + await t.maximizeWindow(); |
| 386 | + |
| 387 | + const maxChildWidth = await getWindowWidth(); |
| 388 | + const maxChildHeight = await getWindowHeight(); |
| 389 | + |
| 390 | + await t.expect(maxChildWidth).gt(childWidth + e); |
| 391 | + await t.expect(maxChildHeight).gt(childHeight + e); |
| 392 | + |
| 393 | + await t.switchToParentWindow(); |
| 394 | + |
| 395 | + await t.maximizeWindow(); |
| 396 | + |
| 397 | + const maxParentWidth = await getWindowWidth(); |
| 398 | + const maxParentHeight = await getWindowHeight(); |
| 399 | + |
| 400 | + await t.expect(maxParentWidth).gt(parentWidth + e); |
| 401 | + await t.expect(maxParentHeight).gt(parentHeight + e); |
| 402 | +}); |
0 commit comments