Skip to content

Commit efcab33

Browse files
committed
Fix issue with duplicate Highcharts library declarations
1 parent f4e9631 commit efcab33

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

seleniumbase/fixtures/base_case.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def __init__(self, *args, **kwargs):
9292
self._chart_data = {}
9393
self._chart_count = 0
9494
self._chart_label = {}
95+
self._chart_xcount = 0
9596
self._chart_first_series = {}
9697
self._chart_series_count = {}
9798
self._tour_steps = {}
@@ -4368,6 +4369,24 @@ def save_presentation(
43684369
show_notes_str,
43694370
interval_ms))
43704371

4372+
# Remove duplicate ChartMaker library declarations
4373+
chart_libs = (
4374+
"""
4375+
<script src="%s"></script>
4376+
<script src="%s"></script>
4377+
<script src="%s"></script>
4378+
<script src="%s"></script>
4379+
""" % (
4380+
constants.HighCharts.HC_JS,
4381+
constants.HighCharts.EXPORTING_JS,
4382+
constants.HighCharts.EXPORT_DATA_JS,
4383+
constants.HighCharts.ACCESSIBILITY_JS))
4384+
if the_html.count(chart_libs) > 1:
4385+
chart_libs_comment = '<!-- HighCharts Libraries Imported -->'
4386+
the_html = the_html.replace(chart_libs, chart_libs_comment)
4387+
# Only need to import the HighCharts libraries once
4388+
the_html = the_html.replace(chart_libs_comment, chart_libs, 1)
4389+
43714390
saved_presentations_folder = constants.Presentations.SAVED_FOLDER
43724391
if saved_presentations_folder.endswith("/"):
43734392
saved_presentations_folder = saved_presentations_folder[:-1]
@@ -4622,15 +4641,14 @@ def __create_highchart(
46224641
subtitle = subtitle.replace("'", "\\'")
46234642
unit = unit.replace("'", "\\'")
46244643
self._chart_count += 1
4644+
# If chart_libs format is changed, also change: save_presentation()
46254645
chart_libs = (
46264646
"""
46274647
<script src="%s"></script>
46284648
<script src="%s"></script>
46294649
<script src="%s"></script>
46304650
<script src="%s"></script>
4631-
<script src="%s"></script>
46324651
""" % (
4633-
constants.JQuery.MIN_JS,
46344652
constants.HighCharts.HC_JS,
46354653
constants.HighCharts.EXPORTING_JS,
46364654
constants.HighCharts.EXPORT_DATA_JS,
@@ -4682,7 +4700,7 @@ def __create_highchart(
46824700
chart_figure = (
46834701
"""
46844702
<figure class="highcharts-figure">
4685-
<div id="chartcontainer%s"></div>
4703+
<div id="chartcontainer_num_%s"></div>
46864704
<p class="highcharts-description">%s</p>
46874705
</figure>
46884706
""" % (self._chart_count, chart_description))
@@ -4693,7 +4711,7 @@ def __create_highchart(
46934711
"""
46944712
<script>
46954713
// Build the chart
4696-
Highcharts.chart('chartcontainer%s', {
4714+
Highcharts.chart('chartcontainer_num_%s', {
46974715
credits: {
46984716
enabled: false
46994717
},
@@ -5054,6 +5072,9 @@ def extract_chart(self, chart_name=None):
50545072
axis += "'%s'," % label
50555073
axis += "], crosshair: false},"
50565074
the_html = the_html.replace("xAxis: { },", axis)
5075+
self._chart_xcount += 1
5076+
the_html = the_html.replace(
5077+
"chartcontainer_num_", "chartcontainer_%s_" % self._chart_xcount)
50575078
return the_html
50585079

50595080
############

0 commit comments

Comments
 (0)