From 66565195603d122685db2e8ed6d94d64a6ff6318 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 20 Nov 2018 20:18:57 -0800 Subject: [PATCH] test: split out dialog tests (#3586) --- test/dialog.spec.js | 50 +++++++++++++++++++++++++++++++++++++++++ test/evaluation.spec.js | 10 --------- test/jshandle.spec.js | 17 ++++++++++++++ test/page.spec.js | 36 ----------------------------- test/test.js | 1 + 5 files changed, 68 insertions(+), 46 deletions(-) create mode 100644 test/dialog.spec.js diff --git a/test/dialog.spec.js b/test/dialog.spec.js new file mode 100644 index 00000000..6ccfb859 --- /dev/null +++ b/test/dialog.spec.js @@ -0,0 +1,50 @@ +/** + * Copyright 2018 Google Inc. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +module.exports.addTests = function({testRunner, expect}) { + const {describe, xdescribe, fdescribe} = testRunner; + const {it, fit, xit} = testRunner; + const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; + + describe('Page.Events.Dialog', function() { + it('should fire', async({page, server}) => { + page.on('dialog', dialog => { + expect(dialog.type()).toBe('alert'); + expect(dialog.defaultValue()).toBe(''); + expect(dialog.message()).toBe('yo'); + dialog.accept(); + }); + await page.evaluate(() => alert('yo')); + }); + it('should allow accepting prompts', async({page, server}) => { + page.on('dialog', dialog => { + expect(dialog.type()).toBe('prompt'); + expect(dialog.defaultValue()).toBe('yes.'); + expect(dialog.message()).toBe('question?'); + dialog.accept('answer!'); + }); + const result = await page.evaluate(() => prompt('question?', 'yes.')); + expect(result).toBe('answer!'); + }); + it('should dismiss the prompt', async({page, server}) => { + page.on('dialog', dialog => { + dialog.dismiss(); + }); + const result = await page.evaluate(() => prompt('question?')); + expect(result).toBe(null); + }); + }); +}; diff --git a/test/evaluation.spec.js b/test/evaluation.spec.js index d626fb6f..edd0707a 100644 --- a/test/evaluation.spec.js +++ b/test/evaluation.spec.js @@ -171,16 +171,6 @@ module.exports.addTests = function({testRunner, expect}) { expect(error).toBeTruthy(); expect(error.message).toContain('JSHandles can be evaluated only in the context they were created'); }); - it('should accept object handle as an argument', async({page, server}) => { - const navigatorHandle = await page.evaluateHandle(() => navigator); - const text = await page.evaluate(e => e.userAgent, navigatorHandle); - expect(text).toContain('Mozilla'); - }); - it('should accept object handle to primitive types', async({page, server}) => { - const aHandle = await page.evaluateHandle(() => 5); - const isFive = await page.evaluate(e => Object.is(e, 5), aHandle); - expect(isFive).toBeTruthy(); - }); it('should simulate a user gesture', async({page, server}) => { await page.evaluate(playAudio); // also test evaluating strings diff --git a/test/jshandle.spec.js b/test/jshandle.spec.js index f9036bd4..26bc5223 100644 --- a/test/jshandle.spec.js +++ b/test/jshandle.spec.js @@ -19,6 +19,23 @@ module.exports.addTests = function({testRunner, expect}) { const {it, fit, xit} = testRunner; const {beforeAll, beforeEach, afterAll, afterEach} = testRunner; + describe('Page.evaluateHandle', function() { + it('should work', async({page, server}) => { + const windowHandle = await page.evaluateHandle(() => window); + expect(windowHandle).toBeTruthy(); + }); + it('should accept object handle as an argument', async({page, server}) => { + const navigatorHandle = await page.evaluateHandle(() => navigator); + const text = await page.evaluate(e => e.userAgent, navigatorHandle); + expect(text).toContain('Mozilla'); + }); + it('should accept object handle to primitive types', async({page, server}) => { + const aHandle = await page.evaluateHandle(() => 5); + const isFive = await page.evaluate(e => Object.is(e, 5), aHandle); + expect(isFive).toBeTruthy(); + }); + }); + describe('JSHandle.getProperty', function() { it('should work', async({page, server}) => { const aHandle = await page.evaluateHandle(() => ({ diff --git a/test/page.spec.js b/test/page.spec.js index 3b585135..35fb6f31 100644 --- a/test/page.spec.js +++ b/test/page.spec.js @@ -189,13 +189,6 @@ module.exports.addTests = function({testRunner, expect, headless}) { }); }); - describe('Page.evaluateHandle', function() { - it('should work', async({page, server}) => { - const windowHandle = await page.evaluateHandle(() => window); - expect(windowHandle).toBeTruthy(); - }); - }); - describe('ExecutionContext.queryObjects', function() { it('should work', async({page, server}) => { // Instantiate an object @@ -498,35 +491,6 @@ module.exports.addTests = function({testRunner, expect, headless}) { }); }); - describe('Page.Events.Dialog', function() { - it('should fire', async({page, server}) => { - page.on('dialog', dialog => { - expect(dialog.type()).toBe('alert'); - expect(dialog.defaultValue()).toBe(''); - expect(dialog.message()).toBe('yo'); - dialog.accept(); - }); - await page.evaluate(() => alert('yo')); - }); - it('should allow accepting prompts', async({page, server}) => { - page.on('dialog', dialog => { - expect(dialog.type()).toBe('prompt'); - expect(dialog.defaultValue()).toBe('yes.'); - expect(dialog.message()).toBe('question?'); - dialog.accept('answer!'); - }); - const result = await page.evaluate(() => prompt('question?', 'yes.')); - expect(result).toBe('answer!'); - }); - it('should dismiss the prompt', async({page, server}) => { - page.on('dialog', dialog => { - dialog.dismiss(); - }); - const result = await page.evaluate(() => prompt('question?')); - expect(result).toBe(null); - }); - }); - describe('Page.Events.PageError', function() { it('should fire', async({page, server}) => { let error = null; diff --git a/test/test.js b/test/test.js index 4b0bace3..a6c38ce5 100644 --- a/test/test.js +++ b/test/test.js @@ -161,6 +161,7 @@ describe('Browser', function() { require('./jshandle.spec.js').addTests({testRunner, expect}); require('./network.spec.js').addTests({testRunner, expect}); require('./page.spec.js').addTests({testRunner, expect, headless}); + require('./dialog.spec.js').addTests({testRunner, expect, headless}); require('./navigation.spec.js').addTests({testRunner, expect, headless}); require('./evaluation.spec.js').addTests({testRunner, expect, headless}); require('./emulation.spec.js').addTests({testRunner, expect, headless});