Skip to content

Add SeleniumBase "Chart Maker" for creating pie charts #636

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,10 @@ allure-report
allure_results
allure-results

# Charts
saved_charts

# Presentations
presentations_saved
saved_presentations

# Tours
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
livereload==2.6.2;python_version>="3.6"
mkdocs==1.1.2
mkdocs-material==5.4.0
mkdocs-material==5.5.0
mkdocs-simple-hooks==0.1.1
mkdocs-material-extensions==1.0
mkdocs-minify-plugin==0.3.0
4 changes: 2 additions & 2 deletions examples/ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<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>
<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>

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

Expand Down Expand Up @@ -131,7 +131,7 @@ python gui_test_runner.py

--------

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

<a href="https://github.com/seleniumbase/SeleniumBase">
<img src="https://img.shields.io/badge/tested%20with-SeleniumBase-04C38E.svg" alt="Tested with SeleniumBase" /></a>
116 changes: 116 additions & 0 deletions examples/chart_maker/ReadMe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<h3 align="left"><img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb23.png" alt="SeleniumBase" width="290" /></h3>

# 📊 Chart Maker 📊

SeleniumBase Chart Maker allows you to create HTML charts with Python.<br />
The HighCharts library is used for creating charts.
(Currently only <b>pie charts</b> are supported.)

**Here's a sample chart:**

<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>

([Click on the image for the actual chart](https://seleniumbase.io/other/chart_presentation.html))

Here's how to run the example (a chart in a presentation):
```
cd examples/chart_maker
pytest my_chart.py
```


### Creating a new chart:

```python
self.create_pie_chart(chart_name=None, title="My Chart")
""" Creates a JavaScript pie chart using "HighCharts". """
```

If creating multiple charts at the same time, you can pass the ``chart_name`` parameter to distinguish between different charts.


### Adding a data point to a chart:

```python
self.add_data_point(label, value, color=None, chart_name=None):
""" Add a data point to a SeleniumBase-generated chart.
@Params
label - The label name for the data point.
value - The numeric value of the data point.
color - The HTML color of the data point.
Can be an RGB color. Eg: "#55ACDC".
Can also be a named color. Eg: "Teal".
chart_name - If creating multiple charts,
use this to select which one.
"""
```


### Saving a chart to a file:

```python
self.save_chart(chart_name=None, filename=None):
""" Saves a SeleniumBase-generated chart to a file for later use.
@Params
chart_name - If creating multiple charts at the same time,
use this to select the one you wish to use.
filename - The name of the HTML file that you wish to
save the chart to. (filename must end in ".html")
"""
```

The full HTML of the chart is saved to the ``saved_charts/`` folder.


### Extracting the HTML of a chart:

```python
self.extract_chart(chart_name=None):
""" Extracts the HTML from a SeleniumBase-generated chart.
@Params
chart_name - If creating multiple charts at the same time,
use this to select the one you wish to use.
"""
```


### Displaying a chart in the browser window:

```python
self.display_chart(chart_name=None, filename=None):
""" Displays a SeleniumBase-generated chart in the browser window.
@Params
chart_name - If creating multiple charts at the same time,
use this to select the one you wish to use.
filename - The name of the HTML file that you wish to
save the chart to. (filename must end in ".html")
"""
```

All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at once.


### Here's an example of using SeleniumBase Chart Maker:

```python
from seleniumbase import BaseCase


class MyChartMakerClass(BaseCase):

def test_chart_maker(self):
self.create_pie_chart(title="Automated Tests")
self.add_data_point("Passed", 7, color="#95d96f")
self.add_data_point("Untested", 2, color="#eaeaea")
self.add_data_point("Failed", 1, color="#f1888f")
self.create_presentation()
self.add_slide(self.extract_chart())
self.begin_presentation()

```

#### 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:

```bash
pytest my_chart.py
```
13 changes: 13 additions & 0 deletions examples/chart_maker/my_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from seleniumbase import BaseCase


class MyChartMakerClass(BaseCase):

def test_chart_maker(self):
self.create_pie_chart(title="Automated Tests")
self.add_data_point("Passed", 7, color="#95d96f")
self.add_data_point("Untested", 2, color="#eaeaea")
self.add_data_point("Failed", 1, color="#f1888f")
self.create_presentation()
self.add_slide(self.extract_chart())
self.begin_presentation()
2 changes: 2 additions & 0 deletions examples/presenter/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ The Reveal-JS library is used for running the presentations.

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

([Click on the image/GIF for the actual presentation](https://seleniumbase.io/other/presenter.html))

Slides can include HTML, code, images, and iframes.

Here's how to run the example presentation:
Expand Down
116 changes: 116 additions & 0 deletions help_docs/chart_maker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<h3 align="left"><img src="https://cdn2.hubspot.net/hubfs/100006/images/super_logo_sb23.png" alt="SeleniumBase" width="290" /></h3>

# 📊 Chart Maker 📊

SeleniumBase Chart Maker allows you to create HTML charts with Python.<br />
The HighCharts library is used for creating charts.
(Currently only <b>pie charts</b> are supported.)

**Here's a sample chart:**

<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>

([Click on the image for the actual chart](https://seleniumbase.io/other/chart_presentation.html))

Here's how to run the example (a chart in a presentation):
```
cd examples/chart_maker
pytest my_chart.py
```


### Creating a new chart:

```python
self.create_pie_chart(chart_name=None, title="My Chart")
""" Creates a JavaScript pie chart using "HighCharts". """
```

If creating multiple charts at the same time, you can pass the ``chart_name`` parameter to distinguish between different charts.


### Adding a data point to a chart:

```python
self.add_data_point(label, value, color=None, chart_name=None):
""" Add a data point to a SeleniumBase-generated chart.
@Params
label - The label name for the data point.
value - The numeric value of the data point.
color - The HTML color of the data point.
Can be an RGB color. Eg: "#55ACDC".
Can also be a named color. Eg: "Teal".
chart_name - If creating multiple charts,
use this to select which one.
"""
```


### Saving a chart to a file:

```python
self.save_chart(chart_name=None, filename=None):
""" Saves a SeleniumBase-generated chart to a file for later use.
@Params
chart_name - If creating multiple charts at the same time,
use this to select the one you wish to use.
filename - The name of the HTML file that you wish to
save the chart to. (filename must end in ".html")
"""
```

The full HTML of the chart is saved to the ``saved_charts/`` folder.


### Extracting the HTML of a chart:

```python
self.extract_chart(chart_name=None):
""" Extracts the HTML from a SeleniumBase-generated chart.
@Params
chart_name - If creating multiple charts at the same time,
use this to select the one you wish to use.
"""
```


### Displaying a chart in the browser window:

```python
self.display_chart(chart_name=None, filename=None):
""" Displays a SeleniumBase-generated chart in the browser window.
@Params
chart_name - If creating multiple charts at the same time,
use this to select the one you wish to use.
filename - The name of the HTML file that you wish to
save the chart to. (filename must end in ".html")
"""
```

All methods have the optional ``chart_name`` argument, which is only needed if you're creating multiple charts at once.


### Here's an example of using SeleniumBase Chart Maker:

```python
from seleniumbase import BaseCase


class MyChartMakerClass(BaseCase):

def test_chart_maker(self):
self.create_pie_chart(title="Automated Tests")
self.add_data_point("Passed", 7, color="#95d96f")
self.add_data_point("Untested", 2, color="#eaeaea")
self.add_data_point("Failed", 1, color="#f1888f")
self.create_presentation()
self.add_slide(self.extract_chart())
self.begin_presentation()

```

#### 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:

```bash
pytest my_chart.py
```
12 changes: 12 additions & 0 deletions help_docs/method_summary.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,18 @@ self.begin_presentation(name=None, filename=None, show_notes=False, interval=0)

############

self.create_pie_chart(chart_name=None, title=None)

self.add_data_point(label, value, color=None, chart_name=None)

self.save_chart(chart_name=None, filename=None)

self.display_chart(chart_name=None, filename=None)

self.extract_chart(chart_name=None)

############

self.create_tour(name=None, theme=None)

self.create_shepherd_tour(name=None, theme=None)
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ nav:
- JS Package Manager: help_docs/js_package_manager.md
- Site Tours: examples/tour_examples/ReadMe.md
- Presenter: examples/presenter/ReadMe.md
- Chart Maker: help_docs/chart_maker.md
- Visual Testing: examples/visual_testing/ReadMe.md
- Integrations:
- Logging and Reports: examples/example_logs/ReadMe.md
Expand Down
9 changes: 5 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ wheel>=0.34.2
six==1.15.0
nose==1.3.7
ipdb==0.13.3
parso==0.7.1
jedi==0.17.2
idna==2.10
chardet==3.0.4
Expand Down Expand Up @@ -38,17 +39,17 @@ pygments==2.5.2;python_version<"3.5"
pygments==2.6.1;python_version>="3.5"
colorama==0.4.3
pymysql==0.10.0
coverage==5.2.1
brython>=3.8.9
coverage==5.2
pyotp==2.3.0
boto==2.49.0
cffi==1.14.0
rich==3.4.1;python_version>="3.6" and python_version<"4.0"
rich==4.1.0;python_version>="3.6" and python_version<"4.0"
flake8==3.7.9;python_version<"3.5"
flake8==3.8.3;python_version>="3.5"
pyflakes==2.1.1;python_version<"3.5"
pyflakes==2.2.0;python_version>="3.5"
certifi>=2020.6.20
allure-pytest==2.8.16
allure-pytest==2.8.17
pdfminer.six==20191110;python_version<"3.5"
pdfminer.six==20200720;python_version>="3.5"
pdfminer.six==20200726;python_version>="3.5"
2 changes: 1 addition & 1 deletion seleniumbase/console_scripts/sb_mkdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def main():
data.append("allure-report")
data.append("allure_results")
data.append("allure-results")
data.append("presentations_saved")
data.append("saved_charts")
data.append("saved_presentations")
data.append("tours_exported")
data.append("images_exported")
Expand Down
Loading