-
Notifications
You must be signed in to change notification settings - Fork 95
/
test_button_examples.py
36 lines (31 loc) · 1.4 KB
/
test_button_examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Simple example for utilizing UI Tester on a button editor.
Currently, the clicks happen instantaneously, so visually in the example,
the button will not change color as it normally would while being clicked
manually.
In this example, the Tester simply clicks the button 5 times (which can be
observed by the displayed click counter incrementing).
"""
import os
import pkg_resources
import unittest
from traitsui.testing.tester import command, locator, query
from traitsui.testing.tester.examples.load_demo import load_demo
from traitsui.testing.tester.ui_tester import UITester
DEMO = pkg_resources.resource_filename("traitsui", "examples/demo")
class TestButtonExamples(unittest.TestCase):
def test_button_editor_simple_demo(self):
# Showcase using UI Tester on ButtonEditor_simple_demo.py in
# examples/demo/Standard_Edtiors
filepath = os.path.join(
DEMO, "Standard_Editors", "ButtonEditor_simple_demo.py"
)
demo = load_demo(filepath, "demo")
tester = UITester(delay=500)
with tester.create_ui(demo) as ui:
button = tester.find_by_name(ui, "my_button_trait")
for _ in range(5):
button.perform(command.MouseClick())
click_counter = tester.find_by_name(ui, "click_counter")
displayed_count = click_counter.inspect(query.DisplayedText())
self.assertEqual(displayed_count, '5')