Skip to content

Commit 6b5eaf6

Browse files
authored
Merge pull request #636 from seleniumbase/chart-maker
Add SeleniumBase "Chart Maker" for creating pie charts
2 parents 0df878e + ab5256f commit 6b5eaf6

File tree

14 files changed

+568
-23
lines changed

14 files changed

+568
-23
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ allure-report
9090
allure_results
9191
allure-results
9292

93+
# Charts
94+
saved_charts
95+
9396
# Presentations
94-
presentations_saved
9597
saved_presentations
9698

9799
# Tours

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
livereload==2.6.2;python_version>="3.6"
22
mkdocs==1.1.2
3-
mkdocs-material==5.4.0
3+
mkdocs-material==5.5.0
44
mkdocs-simple-hooks==0.1.1
55
mkdocs-material-extensions==1.0
66
mkdocs-minify-plugin==0.3.0

examples/ReadMe.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<p align="center"><a align="center" href="https://github.com/seleniumbase/SeleniumBase/blob/master/README.md"><img align="center" src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb8.png" alt="SeleniumBase" width="290" /></a></p>
1+
<p align="center"><a align="center" href="https://github.com/seleniumbase/SeleniumBase/blob/master/README.md"><img align="center" src="https://cdn2.hubspot.net/hubfs/100006/images/SeleniumBaseText_F.png" alt="SeleniumBase" width="290" /></a></p>
22

33
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Running Example Tests:</h2>
44

@@ -131,7 +131,7 @@ python gui_test_runner.py
131131

132132
--------
133133

134-
<img src="https://cdn2.hubspot.net/hubfs/100006/images/SeleniumBaseText_F.png" title="SeleniumBase" width="290" />
134+
<img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb8.png" title="SeleniumBase" width="290" />
135135

136136
<a href="https://github.com/seleniumbase/SeleniumBase">
137137
<img src="https://img.shields.io/badge/tested%20with-SeleniumBase-04C38E.svg" alt="Tested with SeleniumBase" /></a>

examples/chart_maker/ReadMe.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<h3 align="left"><img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb23.png" alt="SeleniumBase" width="290" /></h3>
2+
3+
# 📊 Chart Maker 📊
4+
5+
SeleniumBase Chart Maker allows you to create HTML charts with Python.<br />
6+
The HighCharts library is used for creating charts.
7+
(Currently only <b>pie charts</b> are supported.)
8+
9+
**Here's a sample chart:**
10+
11+
<a href="https://seleniumbase.io/other/chart_presentation.html"><img width="500" src="https://seleniumbase.io/other/sample_pie_chart.png" title="Screenshot"></a><br>
12+
13+
([Click on the image for the actual chart](https://seleniumbase.io/other/chart_presentation.html))
14+
15+
Here's how to run the example (a chart in a presentation):
16+
```
17+
cd examples/chart_maker
18+
pytest my_chart.py
19+
```
20+
21+
22+
### Creating a new chart:
23+
24+
```python
25+
self.create_pie_chart(chart_name=None, title="My Chart")
26+
""" Creates a JavaScript pie chart using "HighCharts". """
27+
```
28+
29+
If creating multiple charts at the same time, you can pass the ``chart_name`` parameter to distinguish between different charts.
30+
31+
32+
### Adding a data point to a chart:
33+
34+
```python
35+
self.add_data_point(label, value, color=None, chart_name=None):
36+
""" Add a data point to a SeleniumBase-generated chart.
37+
@Params
38+
label - The label name for the data point.
39+
value - The numeric value of the data point.
40+
color - The HTML color of the data point.
41+
Can be an RGB color. Eg: "#55ACDC".
42+
Can also be a named color. Eg: "Teal".
43+
chart_name - If creating multiple charts,
44+
use this to select which one.
45+
"""
46+
```
47+
48+
49+
### Saving a chart to a file:
50+
51+
```python
52+
self.save_chart(chart_name=None, filename=None):
53+
""" Saves a SeleniumBase-generated chart to a file for later use.
54+
@Params
55+
chart_name - If creating multiple charts at the same time,
56+
use this to select the one you wish to use.
57+
filename - The name of the HTML file that you wish to
58+
save the chart to. (filename must end in ".html")
59+
"""
60+
```
61+
62+
The full HTML of the chart is saved to the ``saved_charts/`` folder.
63+
64+
65+
### Extracting the HTML of a chart:
66+
67+
```python
68+
self.extract_chart(chart_name=None):
69+
""" Extracts the HTML from a SeleniumBase-generated chart.
70+
@Params
71+
chart_name - If creating multiple charts at the same time,
72+
use this to select the one you wish to use.
73+
"""
74+
```
75+
76+
77+
### Displaying a chart in the browser window:
78+
79+
```python
80+
self.display_chart(chart_name=None, filename=None):
81+
""" Displays a SeleniumBase-generated chart in the browser window.
82+
@Params
83+
chart_name - If creating multiple charts at the same time,
84+
use this to select the one you wish to use.
85+
filename - The name of the HTML file that you wish to
86+
save the chart to. (filename must end in ".html")
87+
"""
88+
```
89+
90+
All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at once.
91+
92+
93+
### Here's an example of using SeleniumBase Chart Maker:
94+
95+
```python
96+
from seleniumbase import BaseCase
97+
98+
99+
class MyChartMakerClass(BaseCase):
100+
101+
def test_chart_maker(self):
102+
self.create_pie_chart(title="Automated Tests")
103+
self.add_data_point("Passed", 7, color="#95d96f")
104+
self.add_data_point("Untested", 2, color="#eaeaea")
105+
self.add_data_point("Failed", 1, color="#f1888f")
106+
self.create_presentation()
107+
self.add_slide(self.extract_chart())
108+
self.begin_presentation()
109+
110+
```
111+
112+
#### This example is from [my_chart.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/chart_maker/my_chart.py), which you can run from the ``examples/chart_maker`` folder with the following command:
113+
114+
```bash
115+
pytest my_chart.py
116+
```

examples/chart_maker/my_chart.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from seleniumbase import BaseCase
2+
3+
4+
class MyChartMakerClass(BaseCase):
5+
6+
def test_chart_maker(self):
7+
self.create_pie_chart(title="Automated Tests")
8+
self.add_data_point("Passed", 7, color="#95d96f")
9+
self.add_data_point("Untested", 2, color="#eaeaea")
10+
self.add_data_point("Failed", 1, color="#f1888f")
11+
self.create_presentation()
12+
self.add_slide(self.extract_chart())
13+
self.begin_presentation()

examples/presenter/ReadMe.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ The Reveal-JS library is used for running the presentations.
99

1010
<a href="https://seleniumbase.io/other/presenter.html"><img width="500" src="https://seleniumbase.io/other/presenter.gif" title="Screenshot"></a><br>
1111

12+
([Click on the image/GIF for the actual presentation](https://seleniumbase.io/other/presenter.html))
13+
1214
Slides can include HTML, code, images, and iframes.
1315

1416
Here's how to run the example presentation:

help_docs/chart_maker.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<h3 align="left"><img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb23.png" alt="SeleniumBase" width="290" /></h3>
2+
3+
# 📊 Chart Maker 📊
4+
5+
SeleniumBase Chart Maker allows you to create HTML charts with Python.<br />
6+
The HighCharts library is used for creating charts.
7+
(Currently only <b>pie charts</b> are supported.)
8+
9+
**Here's a sample chart:**
10+
11+
<a href="https://seleniumbase.io/other/chart_presentation.html"><img width="500" src="https://seleniumbase.io/other/sample_pie_chart.png" title="Screenshot"></a><br>
12+
13+
([Click on the image for the actual chart](https://seleniumbase.io/other/chart_presentation.html))
14+
15+
Here's how to run the example (a chart in a presentation):
16+
```
17+
cd examples/chart_maker
18+
pytest my_chart.py
19+
```
20+
21+
22+
### Creating a new chart:
23+
24+
```python
25+
self.create_pie_chart(chart_name=None, title="My Chart")
26+
""" Creates a JavaScript pie chart using "HighCharts". """
27+
```
28+
29+
If creating multiple charts at the same time, you can pass the ``chart_name`` parameter to distinguish between different charts.
30+
31+
32+
### Adding a data point to a chart:
33+
34+
```python
35+
self.add_data_point(label, value, color=None, chart_name=None):
36+
""" Add a data point to a SeleniumBase-generated chart.
37+
@Params
38+
label - The label name for the data point.
39+
value - The numeric value of the data point.
40+
color - The HTML color of the data point.
41+
Can be an RGB color. Eg: "#55ACDC".
42+
Can also be a named color. Eg: "Teal".
43+
chart_name - If creating multiple charts,
44+
use this to select which one.
45+
"""
46+
```
47+
48+
49+
### Saving a chart to a file:
50+
51+
```python
52+
self.save_chart(chart_name=None, filename=None):
53+
""" Saves a SeleniumBase-generated chart to a file for later use.
54+
@Params
55+
chart_name - If creating multiple charts at the same time,
56+
use this to select the one you wish to use.
57+
filename - The name of the HTML file that you wish to
58+
save the chart to. (filename must end in ".html")
59+
"""
60+
```
61+
62+
The full HTML of the chart is saved to the ``saved_charts/`` folder.
63+
64+
65+
### Extracting the HTML of a chart:
66+
67+
```python
68+
self.extract_chart(chart_name=None):
69+
""" Extracts the HTML from a SeleniumBase-generated chart.
70+
@Params
71+
chart_name - If creating multiple charts at the same time,
72+
use this to select the one you wish to use.
73+
"""
74+
```
75+
76+
77+
### Displaying a chart in the browser window:
78+
79+
```python
80+
self.display_chart(chart_name=None, filename=None):
81+
""" Displays a SeleniumBase-generated chart in the browser window.
82+
@Params
83+
chart_name - If creating multiple charts at the same time,
84+
use this to select the one you wish to use.
85+
filename - The name of the HTML file that you wish to
86+
save the chart to. (filename must end in ".html")
87+
"""
88+
```
89+
90+
All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at once.
91+
92+
93+
### Here's an example of using SeleniumBase Chart Maker:
94+
95+
```python
96+
from seleniumbase import BaseCase
97+
98+
99+
class MyChartMakerClass(BaseCase):
100+
101+
def test_chart_maker(self):
102+
self.create_pie_chart(title="Automated Tests")
103+
self.add_data_point("Passed", 7, color="#95d96f")
104+
self.add_data_point("Untested", 2, color="#eaeaea")
105+
self.add_data_point("Failed", 1, color="#f1888f")
106+
self.create_presentation()
107+
self.add_slide(self.extract_chart())
108+
self.begin_presentation()
109+
110+
```
111+
112+
#### This example is from [my_chart.py](https://github.com/seleniumbase/SeleniumBase/blob/master/examples/chart_maker/my_chart.py), which you can run from the ``examples/chart_maker`` folder with the following command:
113+
114+
```bash
115+
pytest my_chart.py
116+
```

help_docs/method_summary.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,18 @@ self.begin_presentation(name=None, filename=None, show_notes=False, interval=0)
371371

372372
############
373373

374+
self.create_pie_chart(chart_name=None, title=None)
375+
376+
self.add_data_point(label, value, color=None, chart_name=None)
377+
378+
self.save_chart(chart_name=None, filename=None)
379+
380+
self.display_chart(chart_name=None, filename=None)
381+
382+
self.extract_chart(chart_name=None)
383+
384+
############
385+
374386
self.create_tour(name=None, theme=None)
375387

376388
self.create_shepherd_tour(name=None, theme=None)

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ nav:
7474
- JS Package Manager: help_docs/js_package_manager.md
7575
- Site Tours: examples/tour_examples/ReadMe.md
7676
- Presenter: examples/presenter/ReadMe.md
77+
- Chart Maker: help_docs/chart_maker.md
7778
- Visual Testing: examples/visual_testing/ReadMe.md
7879
- Integrations:
7980
- Logging and Reports: examples/example_logs/ReadMe.md

requirements.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ wheel>=0.34.2
77
six==1.15.0
88
nose==1.3.7
99
ipdb==0.13.3
10+
parso==0.7.1
1011
jedi==0.17.2
1112
idna==2.10
1213
chardet==3.0.4
@@ -38,17 +39,17 @@ pygments==2.5.2;python_version<"3.5"
3839
pygments==2.6.1;python_version>="3.5"
3940
colorama==0.4.3
4041
pymysql==0.10.0
42+
coverage==5.2.1
4143
brython>=3.8.9
42-
coverage==5.2
4344
pyotp==2.3.0
4445
boto==2.49.0
4546
cffi==1.14.0
46-
rich==3.4.1;python_version>="3.6" and python_version<"4.0"
47+
rich==4.1.0;python_version>="3.6" and python_version<"4.0"
4748
flake8==3.7.9;python_version<"3.5"
4849
flake8==3.8.3;python_version>="3.5"
4950
pyflakes==2.1.1;python_version<"3.5"
5051
pyflakes==2.2.0;python_version>="3.5"
5152
certifi>=2020.6.20
52-
allure-pytest==2.8.16
53+
allure-pytest==2.8.17
5354
pdfminer.six==20191110;python_version<"3.5"
54-
pdfminer.six==20200720;python_version>="3.5"
55+
pdfminer.six==20200726;python_version>="3.5"

0 commit comments

Comments
 (0)