Update the NodeJS Express Test Runner App
This commit is contained in:
parent
bc94de850f
commit
c9cb0f1f1a
|
@ -1,4 +1,4 @@
|
|||
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Creating a SeleniumBase Test Launcher by using NodeJS</h2>
|
||||
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Creating a SeleniumBase Test Runner with NodeJS</h2>
|
||||
|
||||
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.
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue