Skip to content

Commit c9cb0f1

Browse files
committed
Update the NodeJS Express Test Runner App
1 parent bc94de8 commit c9cb0f1

File tree

2 files changed

+25
-35
lines changed

2 files changed

+25
-35
lines changed

integrations/node_js/ReadMe.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Creating a SeleniumBase Test Launcher by using NodeJS</h2>
1+
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Creating a SeleniumBase Test Runner with NodeJS</h2>
22

33
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.)
44

@@ -15,23 +15,23 @@ You can create a customized web app for running SeleniumBase tests by using Node
1515
npm install -g express
1616
```
1717

18-
#### 3. Install the Example Test Launcher for SeleniumBase from the ``integrations/node_js`` folder
18+
#### 3. Install the Example Test Runner for SeleniumBase from the ``integrations/node_js`` folder
1919

2020
```bash
2121
npm install
2222
```
2323

2424
(You should see a ``node_modules`` folder appear in your ``node_js`` folder.)
2525

26-
#### 4. Run the NodeJS server for your SeleniumBase Test Launcher web app
26+
#### 4. Run the NodeJS server for your SeleniumBase Test Runner web app
2727

2828
```bash
2929
node server.js
3030
```
3131

3232
(You can always stop the server by using ``CTRL-C``.)
3333

34-
#### 5. Open the SeleniumBase Test Launcher web app
34+
#### 5. Open the SeleniumBase Test Runner web app
3535

3636
* Navigate to [http://127.0.0.1:3000/](http://127.0.0.1:3000/)
3737

@@ -41,4 +41,4 @@ Click on a button to run a SeleniumBase example test.
4141

4242
#### 7. Expand your web app
4343

44-
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.
44+
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.

integrations/node_js/server.js

+20-30
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,43 @@
1-
var http = require('http');
2-
var express = require('express');
3-
var path = require('path');
4-
var app = express();
5-
var exec = require('child_process').exec;
6-
7-
function run_my_first_test() {
8-
exec("pytest my_first_test.py");
9-
}
10-
11-
function run_test_demo_site() {
12-
exec("pytest test_demo_site.py");
13-
}
14-
15-
function run_my_first_test_with_demo_mode() {
16-
exec("pytest my_first_test.py --demo_mode");
17-
}
18-
19-
function run_test_demo_site_with_demo_mode() {
20-
exec("pytest test_demo_site.py --demo_mode");
1+
const http = require('http');
2+
const express = require('express');
3+
const path = require('path');
4+
const app = express();
5+
const exec = require('child_process').exec;
6+
var server_info = '\nServer running at http://127.0.0.1:3000/ (CTRL-C to stop)';
7+
8+
function run_command(command) {
9+
console.log("\n" + command);
10+
exec(command, (err, stdout, stderr) => console.log(stdout, server_info));
2111
}
2212

2313
app.get('/', function(req, res) {
2414
res.sendFile(path.join(__dirname + '/index.html'));
25-
})
15+
});
2616

2717
app.get('/run_my_first_test', function(req, res) {
2818
res.sendFile(path.join(__dirname + '/index.html'));
2919
res.redirect('/');
30-
run_my_first_test()
31-
})
20+
run_command("pytest my_first_test.py");
21+
});
3222

3323
app.get('/run_test_demo_site', function(req, res) {
3424
res.sendFile(path.join(__dirname + '/index.html'));
3525
res.redirect('/');
36-
run_test_demo_site()
37-
})
26+
run_command("pytest test_demo_site.py");
27+
});
3828

3929
app.get('/run_my_first_test_with_demo_mode', function(req, res) {
4030
res.sendFile(path.join(__dirname + '/index.html'));
4131
res.redirect('/');
42-
run_my_first_test_with_demo_mode()
43-
})
32+
run_command("pytest my_first_test.py --demo_mode");
33+
});
4434

4535
app.get('/run_test_demo_site_with_demo_mode', function(req, res) {
4636
res.sendFile(path.join(__dirname + '/index.html'));
4737
res.redirect('/');
48-
run_test_demo_site_with_demo_mode()
49-
})
38+
run_command("pytest test_demo_site.py --demo_mode");
39+
});
5040

5141
app.listen(3000, "127.0.0.1", function() {
52-
console.log('Server running at http://127.0.0.1:3000/ (CTRL-C to stop)');
42+
console.log(server_info);
5343
});

0 commit comments

Comments
 (0)