From d22c3b438333d2c415f06d86a7c2b670b2933c8f Mon Sep 17 00:00:00 2001 From: ericblackmonGoogle <129398736+ericblackmonGoogle@users.noreply.github.com> Date: Tue, 20 Jun 2023 17:10:07 +0000 Subject: [PATCH] Fix: Update browser test to run manually, and move browser test suiteSetup in to a separate function (#7138) * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Added basic example test for Blockly Playground and Blockly Demo * feat: Add functionality to run playground and block factory test locally * feat: Add functionality to run playground and block factory test locally * feat: Add functionality to run playground and block factory test locally * feat: Add functionality to run playground and block factory test locally * feat: Create procedure test * feat: Create procedure test * feat: Create procedure test * chore: test for procedures * chore: test for procedures * chore: test for procedures * chore: test for procedures * fix: Switch broswer_test.yaml to be macOS as to match local development evn * fix: Switch broswer_test.yaml to be macOS as to match local development evn * fix: Switch broswer_test.yaml to be macOS as to match local development evn * fix: Switch broswer_test.yaml to be macOS as to match local development evn * fix: Update browser test to run manually, and move browser test suiteSetup in to a separate function --- .github/workflows/browser_test.yml | 8 +- .../browser/test/basic_block_factory_test.js | 42 +--------- tests/browser/test/basic_playground_test.js | 40 +--------- tests/browser/test/procedure_test.js | 40 +--------- tests/browser/test/test_setup.js | 76 +++++++++++++++++++ 5 files changed, 85 insertions(+), 121 deletions(-) create mode 100644 tests/browser/test/test_setup.js diff --git a/.github/workflows/browser_test.yml b/.github/workflows/browser_test.yml index 414dd721b..16337cdd6 100644 --- a/.github/workflows/browser_test.yml +++ b/.github/workflows/browser_test.yml @@ -1,12 +1,10 @@ # This workflow will do a clean install, start the selenium server, and run # all of our browser based tests -name: Run browser test nightly +name: Run browser manually on: - # Trigger the workflow nightly - schedule: - - cron: '0 0 * * *' + workflow_dispatch: permissions: contents: read @@ -20,7 +18,7 @@ jobs: matrix: # TODO (#2114): re-enable osx build. # os: [ubuntu-latest, macos-latest] - os: [ubuntu-latest] + os: [macos-latest] node-version: [16.x, 18.x, 20.x] # See supported Node.js release schedule at # https://nodejs.org/en/about/releases/ diff --git a/tests/browser/test/basic_block_factory_test.js b/tests/browser/test/basic_block_factory_test.js index 7e726f314..cd9f09800 100644 --- a/tests/browser/test/basic_block_factory_test.js +++ b/tests/browser/test/basic_block_factory_test.js @@ -8,10 +8,8 @@ * @fileoverview Node.js script to run Automated tests in Chrome, via webdriver. */ -const webdriverio = require('webdriverio'); const chai = require('chai'); -const path = require('path'); -const {posixPath} = require('../../../scripts/helpers'); +const {testSetup, testFileLocations} = require('./test_setup'); let browser; suite('Testing Connecting Blocks', function (done) { @@ -20,43 +18,7 @@ suite('Testing Connecting Blocks', function (done) { // Setup Selenium for all of the tests suiteSetup(async function () { - const options = { - capabilities: { - 'browserName': 'chrome', - 'goog:chromeOptions': { - args: ['--allow-file-access-from-files'], - }, - }, - services: [['selenium-standalone']], - logLevel: 'warn', - }; - - // Run in headless mode on Github Actions. - if (process.env.CI) { - options.capabilities['goog:chromeOptions'].args.push( - '--headless', - '--no-sandbox', - '--disable-dev-shm-usage' - ); - } else { - // --disable-gpu is needed to prevent Chrome from hanging on Linux with - // NVIDIA drivers older than v295.20. See - // https://github.com/google/blockly/issues/5345 for details. - options.capabilities['goog:chromeOptions'].args.push('--disable-gpu'); - } - // Use Selenium to bring up the page - const url = - 'file://' + - posixPath( - path.join(__dirname, '..', '..', '..', 'demos', 'blockfactory') - ) + - '/index.html'; - console.log(url); - console.log('Starting webdriverio...'); - browser = await webdriverio.remote(options); - console.log('Loading URL: ' + url); - await browser.url(url); - return browser; + browser = await testSetup(testFileLocations.blockfactory); }); test('Testing Block Drag', async function () { diff --git a/tests/browser/test/basic_playground_test.js b/tests/browser/test/basic_playground_test.js index f70ada8a8..034b295af 100644 --- a/tests/browser/test/basic_playground_test.js +++ b/tests/browser/test/basic_playground_test.js @@ -8,10 +8,8 @@ * @fileoverview Node.js script to run Automated tests in Chrome, via webdriver. */ -const webdriverio = require('webdriverio'); const chai = require('chai'); -const path = require('path'); -const {posixPath} = require('../../../scripts/helpers'); +const {testSetup, testFileLocations} = require('./test_setup'); let browser; suite('Testing Connecting Blocks', function (done) { @@ -20,41 +18,7 @@ suite('Testing Connecting Blocks', function (done) { // Setup Selenium for all of the tests suiteSetup(async function () { - const options = { - capabilities: { - 'browserName': 'chrome', - 'goog:chromeOptions': { - args: ['--allow-file-access-from-files'], - }, - }, - services: [['selenium-standalone']], - logLevel: 'warn', - }; - - // Run in headless mode on Github Actions. - if (process.env.CI) { - options.capabilities['goog:chromeOptions'].args.push( - '--headless', - '--no-sandbox', - '--disable-dev-shm-usage' - ); - } else { - // --disable-gpu is needed to prevent Chrome from hanging on Linux with - // NVIDIA drivers older than v295.20. See - // https://github.com/google/blockly/issues/5345 for details. - options.capabilities['goog:chromeOptions'].args.push('--disable-gpu'); - } - // Use Selenium to bring up the page - const url = - 'file://' + - posixPath(path.join(__dirname, '..', '..')) + - '/playground.html'; - console.log(url); - console.log('Starting webdriverio...'); - browser = await webdriverio.remote(options); - console.log('Loading URL: ' + url); - await browser.url(url); - return browser; + browser = await testSetup(testFileLocations.playground); }); test('Testing Block Flyout', async function () { diff --git a/tests/browser/test/procedure_test.js b/tests/browser/test/procedure_test.js index 113deb2eb..7a4fa2c54 100644 --- a/tests/browser/test/procedure_test.js +++ b/tests/browser/test/procedure_test.js @@ -8,10 +8,8 @@ * @fileoverview Node.js script to run Automated tests in Chrome, via webdriver. */ -const webdriverio = require('webdriverio'); const chai = require('chai'); -const path = require('path'); -const {posixPath} = require('../../../scripts/helpers'); +const {testSetup, testFileLocations} = require('./test_setup'); let browser; suite('Testing Connecting Blocks', function (done) { @@ -20,41 +18,7 @@ suite('Testing Connecting Blocks', function (done) { // Setup Selenium for all of the tests suiteSetup(async function () { - const options = { - capabilities: { - 'browserName': 'chrome', - 'goog:chromeOptions': { - args: ['--allow-file-access-from-files'], - }, - }, - services: [['selenium-standalone']], - logLevel: 'warn', - }; - - // Run in headless mode on Github Actions. - if (process.env.CI) { - options.capabilities['goog:chromeOptions'].args.push( - '--headless', - '--no-sandbox', - '--disable-dev-shm-usage' - ); - } else { - // --disable-gpu is needed to prevent Chrome from hanging on Linux with - // NVIDIA drivers older than v295.20. See - // https://github.com/google/blockly/issues/5345 for details. - options.capabilities['goog:chromeOptions'].args.push('--disable-gpu'); - } - // Use Selenium to bring up the page - const url = - 'file://' + - posixPath(path.join(__dirname, '..', '..', '..', 'demos', 'code')) + - '/index.html'; - console.log(url); - console.log('Starting webdriverio...'); - browser = await webdriverio.remote(options); - console.log('Loading URL: ' + url); - await browser.url(url); - return browser; + browser = await testSetup(testFileLocations.code); }); test('Testing Procedure', async function () { diff --git a/tests/browser/test/test_setup.js b/tests/browser/test/test_setup.js new file mode 100644 index 000000000..b9a7b9b2c --- /dev/null +++ b/tests/browser/test/test_setup.js @@ -0,0 +1,76 @@ +/** + * @license + * Copyright 2023 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @fileoverview Node.js script to run automated functional tests in Chrome, via webdriver. + * This file is to be used in the suiteSetup for any automated fuctional test. + */ + +const webdriverio = require('webdriverio'); +const path = require('path'); +const {posixPath} = require('../../../scripts/helpers'); + +let browser; +async function testSetup(testFile) { + let url; + const options = { + capabilities: { + 'browserName': 'chrome', + 'goog:chromeOptions': { + args: ['--allow-file-access-from-files'], + }, + }, + services: [['selenium-standalone']], + logLevel: 'warn', + }; + + // Run in headless mode on Github Actions. + if (process.env.CI) { + options.capabilities['goog:chromeOptions'].args.push( + '--headless', + '--no-sandbox', + '--disable-dev-shm-usage' + ); + } else { + // --disable-gpu is needed to prevent Chrome from hanging on Linux with + // NVIDIA drivers older than v295.20. See + // https://github.com/google/blockly/issues/5345 for details. + options.capabilities['goog:chromeOptions'].args.push('--disable-gpu'); + } + // Use Selenium to bring up the page + if (testFile == testFileLocations.blockfactory) { + url = + 'file://' + + posixPath( + path.join(__dirname, '..', '..', '..', 'demos', 'blockfactory') + ) + + '/index.html'; + } else if (testFile == testFileLocations.code) { + url = + 'file://' + + posixPath(path.join(__dirname, '..', '..', '..', 'demos', 'code')) + + '/index.html'; + } else { + url = + 'file://' + + posixPath(path.join(__dirname, '..', '..')) + + '/playground.html'; + } + console.log(url); + console.log('Starting webdriverio...'); + browser = await webdriverio.remote(options); + console.log('Loading URL: ' + url); + await browser.url(url); + return browser; +} + +const testFileLocations = { + blockfactory: 0, + code: 1, + playground: 2, +}; + +module.exports = {testSetup, testFileLocations};