Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3455093

Browse files
committed
WebAgg: Add test for toolbar save button
1 parent 361f9d6 commit 3455093

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

lib/matplotlib/tests/test_backend_webagg.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,30 @@ def test_webagg_toolbar(page, toolbar):
147147
page.mouse.move(x, y, steps=2)
148148
message = page.locator('span.mpl-message')
149149
expect(message).to_have_text('x=0.500 y=0.500')
150+
151+
152+
@pytest.mark.backend('webagg')
153+
def test_webagg_toolbar_save(page):
154+
from playwright.sync_api import expect
155+
156+
# Listen for all console logs.
157+
page.on('console', lambda msg: print(f'CONSOLE: {msg.text}'))
158+
159+
fig, ax = plt.subplots(facecolor='w')
160+
161+
# Don't start the Tornado event loop, but use the existing event loop
162+
# started by the `page` fixture.
163+
WebAggApplication.initialize()
164+
WebAggApplication.started = True
165+
166+
page.goto(f'http://{WebAggApplication.address}:{WebAggApplication.port}/')
167+
168+
save = page.locator('button.mpl-widget').nth(5)
169+
expect(save).to_be_visible()
170+
171+
with page.context.expect_page() as new_page_info:
172+
save.click()
173+
new_page = new_page_info.value
174+
175+
new_page.wait_for_load_state()
176+
assert new_page.url.endswith('download.png')

0 commit comments

Comments
 (0)