Skip to content

Commit 6ed8617

Browse files
committed
Improve the NodeJS Python test launcher
1 parent 4a3e03e commit 6ed8617

File tree

4 files changed

+135
-31
lines changed

4 files changed

+135
-31
lines changed

integrations/node_js/ReadMe.md

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

3-
Great news: It's really easy to create a customized web app for kicking off SeleniumBase jobs using NodeJS. This tutorial will walk you through all the steps that you need. (I'll assume 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.)
3+
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.)
4+
5+
<img src="https://seleniumbase.io/other/node_runner.png" title="Node Runner" />
46

57
#### 1. Install NodeJS
68

@@ -35,8 +37,8 @@ node server.js
3537

3638
#### 6. Run an example test
3739

38-
Click on one of the buttons to run a SeleniumBase example test
40+
Click on a button to run a SeleniumBase example test.
3941

40-
#### 7. Enjoy your web app
42+
#### 7. Expand your web app
4143

42-
Congratulations! You now have a web app for kicking off SeleniumBase tests! NodeJS makes it easy!
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.

integrations/node_js/index.html

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<html>
22
<head>
3-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" crossorigin="anonymous">
3+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" crossorigin="anonymous">
44
<style>
55
body {font-family: Arial, Helvetica, sans-serif;}
66
h1 {color:#3366CC; font-size: 32px;}
@@ -9,19 +9,20 @@
99
</style>
1010
</head>
1111
<body>
12+
<script>0</script>
1213
<div class="container">
13-
<h1>Select an option:</h1>
14-
<form method="put" action="/run_my_first_test_in_chrome">
15-
<input type="submit" value="Run Test in Chrome">
14+
<h1>Select a script to run:</h1>
15+
<form method="put" action="/run_my_first_test">
16+
<input type="submit" value="pytest my_first_test.py">
1617
</form>
17-
<form method="put" action="/run_my_first_test_in_firefox">
18-
<input type="submit" value="Run Test in Firefox">
18+
<form method="put" action="/run_test_demo_site">
19+
<input type="submit" value="pytest test_demo_site.py">
1920
</form>
20-
<form method="put" action="/run_my_first_test_in_chrome_with_demo_mode">
21-
<input type="submit" value="Run Test in Chrome (Demo Mode)">
21+
<form method="put" action="/run_my_first_test_with_demo_mode">
22+
<input type="submit" value="pytest my_first_test.py --demo">
2223
</form>
23-
<form method="put" action="/run_my_first_test_in_firefox_with_demo_mode">
24-
<input type="submit" value="Run Test in Firefox (Demo Mode)">
24+
<form method="put" action="/run_test_demo_site_with_demo_mode">
25+
<input type="submit" value="pytest test_demo_site.py --demo">
2526
</form>
2627
</div>
2728
</body>

integrations/node_js/server.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,48 @@ var path = require('path');
44
var app = express();
55
var exec = require('child_process').exec;
66

7-
function run_my_first_test_in_chrome() {
8-
exec("pytest my_first_test.py --browser=chrome -s");
7+
function run_my_first_test() {
8+
exec("pytest my_first_test.py");
99
}
1010

11-
function run_my_first_test_in_firefox() {
12-
exec("pytest my_first_test.py --browser=firefox -s");
11+
function run_test_demo_site() {
12+
exec("pytest test_demo_site.py");
1313
}
1414

15-
function run_my_first_test_in_chrome_with_demo_mode() {
16-
exec("pytest my_first_test.py --browser=chrome --demo_mode -s");
15+
function run_my_first_test_with_demo_mode() {
16+
exec("pytest my_first_test.py --demo_mode");
1717
}
1818

19-
function run_my_first_test_in_firefox_with_demo_mode() {
20-
exec("pytest my_first_test.py --browser=firefox --demo_mode -s");
19+
function run_test_demo_site_with_demo_mode() {
20+
exec("pytest test_demo_site.py --demo_mode");
2121
}
2222

2323
app.get('/', function(req, res) {
2424
res.sendFile(path.join(__dirname + '/index.html'));
2525
})
2626

27-
app.get('/run_my_first_test_in_firefox', function(req, res) {
27+
app.get('/run_my_first_test', function(req, res) {
2828
res.sendFile(path.join(__dirname + '/index.html'));
2929
res.redirect('/');
30-
run_my_first_test_in_firefox()
30+
run_my_first_test()
3131
})
3232

33-
app.get('/run_my_first_test_in_chrome', function(req, res) {
33+
app.get('/run_test_demo_site', function(req, res) {
3434
res.sendFile(path.join(__dirname + '/index.html'));
3535
res.redirect('/');
36-
run_my_first_test_in_chrome()
36+
run_test_demo_site()
3737
})
3838

39-
app.get('/run_my_first_test_in_firefox_with_demo_mode', function(req, res) {
39+
app.get('/run_my_first_test_with_demo_mode', function(req, res) {
4040
res.sendFile(path.join(__dirname + '/index.html'));
4141
res.redirect('/');
42-
run_my_first_test_in_firefox_with_demo_mode()
42+
run_my_first_test_with_demo_mode()
4343
})
4444

45-
app.get('/run_my_first_test_in_chrome_with_demo_mode', function(req, res) {
45+
app.get('/run_test_demo_site_with_demo_mode', function(req, res) {
4646
res.sendFile(path.join(__dirname + '/index.html'));
4747
res.redirect('/');
48-
run_my_first_test_in_chrome_with_demo_mode()
48+
run_test_demo_site_with_demo_mode()
4949
})
5050

5151
app.listen(3000, "127.0.0.1", function() {
+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class MyTestClass(BaseCase):
5+
6+
def test_demo_site(self):
7+
self.open("https://seleniumbase.io/demo_page")
8+
9+
# Assert the title of the current web page
10+
self.assert_title("Web Testing Page")
11+
12+
# Assert that the element is visible on the page
13+
self.assert_element("tbody#tbodyId")
14+
15+
# Assert that the text appears within a given element
16+
self.assert_text("Demo Page", "h1")
17+
18+
# Type/update text in text fields on the page
19+
self.type("#myTextInput", "This is Automated")
20+
self.type("textarea.area1", "Testing Time!\n")
21+
self.type('[name="preText2"]', "Typing Text!")
22+
23+
# Verify that a hover dropdown link changes page text
24+
self.assert_text("Automation Practice", "h3")
25+
self.hover_and_click("#myDropdown", "#dropOption2")
26+
self.assert_text("Link Two Selected", "h3")
27+
28+
# Verify that a button click changes text on the page
29+
self.assert_text("This Text is Green", "#pText")
30+
self.click("#myButton")
31+
self.assert_text("This Text is Purple", "#pText")
32+
33+
# Assert that the given SVG is visible on the page
34+
self.assert_element('svg[name="svgName"]')
35+
36+
# Verify that a slider control updates a progrss bar
37+
self.assert_element('progress[value="50"]')
38+
self.press_right_arrow("#myslider", times=5)
39+
self.assert_element('progress[value="100"]')
40+
41+
# Verify that a "select" option updates a meter bar
42+
self.assert_element('meter[value="0.25"]')
43+
self.select_option_by_text("#mySelect", "Set to 75%")
44+
self.assert_element('meter[value="0.75"]')
45+
46+
# Assert an element located inside an iFrame
47+
self.assert_false(self.is_element_visible("img"))
48+
self.switch_to_frame("#myFrame1")
49+
self.assert_true(self.is_element_visible("img"))
50+
self.switch_to_default_content()
51+
52+
# Assert text located inside an iFrame
53+
self.assert_false(self.is_text_visible("iFrame Text"))
54+
self.switch_to_frame("#myFrame2")
55+
self.assert_true(self.is_text_visible("iFrame Text"))
56+
self.switch_to_default_content()
57+
58+
# Verify that clicking a radio button selects it
59+
self.assert_false(self.is_selected("#radioButton2"))
60+
self.click("#radioButton2")
61+
self.assert_true(self.is_selected("#radioButton2"))
62+
63+
# Verify that clicking a checkbox makes it selected
64+
self.assert_false(self.is_selected("#checkBox1"))
65+
self.click("#checkBox1")
66+
self.assert_true(self.is_selected("#checkBox1"))
67+
68+
# Verify clicking on multiple elements with one call
69+
self.assert_false(self.is_selected("#checkBox2"))
70+
self.assert_false(self.is_selected("#checkBox3"))
71+
self.assert_false(self.is_selected("#checkBox4"))
72+
self.click_visible_elements("input.checkBoxClassB")
73+
self.assert_true(self.is_selected("#checkBox2"))
74+
self.assert_true(self.is_selected("#checkBox3"))
75+
self.assert_true(self.is_selected("#checkBox4"))
76+
77+
# Verify that clicking an iFrame checkbox selects it
78+
self.assert_false(self.is_element_visible(".fBox"))
79+
self.switch_to_frame("#myFrame3")
80+
self.assert_true(self.is_element_visible(".fBox"))
81+
self.assert_false(self.is_selected(".fBox"))
82+
self.click(".fBox")
83+
self.assert_true(self.is_selected(".fBox"))
84+
self.switch_to_default_content()
85+
86+
# Assert link text
87+
self.assert_link_text("seleniumbase.com")
88+
self.assert_link_text("SeleniumBase on GitHub")
89+
self.assert_link_text("seleniumbase.io")
90+
91+
# Click link text
92+
self.click_link_text("SeleniumBase Demo Page")
93+
94+
# Assert exact text
95+
self.assert_exact_text("Demo Page", "h1")
96+
97+
# Assert no broken links (Can be slow if many links)
98+
# self.assert_no_404_errors()
99+
100+
# Assert no JavaScript errors (Can also detect 404s)
101+
self.assert_no_js_errors()

0 commit comments

Comments
 (0)