From c9cb0f1f1a867e2d7b6d44339477365a7d94395e Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Mon, 10 Aug 2020 23:53:30 -0400 Subject: [PATCH] Update the NodeJS Express Test Runner App --- integrations/node_js/ReadMe.md | 10 +++---- integrations/node_js/server.js | 48 ++++++++++++++-------------------- 2 files changed, 24 insertions(+), 34 deletions(-) diff --git a/integrations/node_js/ReadMe.md b/integrations/node_js/ReadMe.md index 6825742a..dc4f43c5 100755 --- a/integrations/node_js/ReadMe.md +++ b/integrations/node_js/ReadMe.md @@ -1,4 +1,4 @@ -

Creating a SeleniumBase Test Launcher by using NodeJS

+

Creating a SeleniumBase Test Runner with NodeJS

You can create a customized web app for running SeleniumBase tests by using NodeJS. (This tutorial assumes that you've already installed SeleniumBase by following the instructions from the [top-level ReadMe](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md) file.) @@ -15,7 +15,7 @@ You can create a customized web app for running SeleniumBase tests by using Node npm install -g express ``` -#### 3. Install the Example Test Launcher for SeleniumBase from the ``integrations/node_js`` folder +#### 3. Install the Example Test Runner for SeleniumBase from the ``integrations/node_js`` folder ```bash npm install @@ -23,7 +23,7 @@ npm install (You should see a ``node_modules`` folder appear in your ``node_js`` folder.) -#### 4. Run the NodeJS server for your SeleniumBase Test Launcher web app +#### 4. Run the NodeJS server for your SeleniumBase Test Runner web app ```bash node server.js @@ -31,7 +31,7 @@ node server.js (You can always stop the server by using ``CTRL-C``.) -#### 5. Open the SeleniumBase Test Launcher web app +#### 5. Open the SeleniumBase Test Runner web app * Navigate to [http://127.0.0.1:3000/](http://127.0.0.1:3000/) @@ -41,4 +41,4 @@ Click on a button to run a SeleniumBase example test. #### 7. Expand your web app -Now that you have a web app for launching SeleniumBase tests, you can expand it to run any script that you want after pressing a button. +Now that you have a web app for running SeleniumBase tests, you can expand it to run any script that you want after pressing a button. diff --git a/integrations/node_js/server.js b/integrations/node_js/server.js index 430e9397..97e05703 100644 --- a/integrations/node_js/server.js +++ b/integrations/node_js/server.js @@ -1,53 +1,43 @@ -var http = require('http'); -var express = require('express'); -var path = require('path'); -var app = express(); -var exec = require('child_process').exec; +const http = require('http'); +const express = require('express'); +const path = require('path'); +const app = express(); +const exec = require('child_process').exec; +var server_info = '\nServer running at http://127.0.0.1:3000/ (CTRL-C to stop)'; -function run_my_first_test() { - exec("pytest my_first_test.py"); -} - -function run_test_demo_site() { - exec("pytest test_demo_site.py"); -} - -function run_my_first_test_with_demo_mode() { - exec("pytest my_first_test.py --demo_mode"); -} - -function run_test_demo_site_with_demo_mode() { - exec("pytest test_demo_site.py --demo_mode"); +function run_command(command) { + console.log("\n" + command); + exec(command, (err, stdout, stderr) => console.log(stdout, server_info)); } app.get('/', function(req, res) { res.sendFile(path.join(__dirname + '/index.html')); -}) +}); app.get('/run_my_first_test', function(req, res) { res.sendFile(path.join(__dirname + '/index.html')); res.redirect('/'); - run_my_first_test() -}) + run_command("pytest my_first_test.py"); +}); app.get('/run_test_demo_site', function(req, res) { res.sendFile(path.join(__dirname + '/index.html')); res.redirect('/'); - run_test_demo_site() -}) + run_command("pytest test_demo_site.py"); +}); app.get('/run_my_first_test_with_demo_mode', function(req, res) { res.sendFile(path.join(__dirname + '/index.html')); res.redirect('/'); - run_my_first_test_with_demo_mode() -}) + run_command("pytest my_first_test.py --demo_mode"); +}); app.get('/run_test_demo_site_with_demo_mode', function(req, res) { res.sendFile(path.join(__dirname + '/index.html')); res.redirect('/'); - run_test_demo_site_with_demo_mode() -}) + run_command("pytest test_demo_site.py --demo_mode"); +}); app.listen(3000, "127.0.0.1", function() { - console.log('Server running at http://127.0.0.1:3000/ (CTRL-C to stop)'); + console.log(server_info); });