Skip to content

Using behavior trees to simulate user interaction with Selenium

Notifications You must be signed in to change notification settings

fohara/treedriver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Behavior Trees to Simulate User Interaction

Concept

Creating a UI test automation agent can roughly be likened to creating an NPC for the app under test. Since behavior trees are a powerful and flexible way to model NPCs, why not use them to model UI automation tests?

Note

This is an early proof of concept; all code is provisional.

Dependencies

  • Install pip dependencies: pip install -r requirements.txt
  • Firefox (used by Selenium)

Usage

  • Start the small app-under-test server process
  • Run the tests via py.test

Caution: The server process will intentionally kill any Firefox processes to demonstrate the fault tolerance of the behavior tree tests. Be careful if Firefox is your default browser otherwise you might lose work!

Illustration

Here's an example of a behavior tree test:

def test_level_three():
    tree = py_trees.composites.Sequence("Level Three")
    sub_tree = py_trees.composites.Selector("Destroy Dark Patterns")
    dismiss_modal_if_any = py_trees.decorators.Inverter(child=DismissModal())
    sub_tree.add_children([DestroyDarkPatterns(), dismiss_modal_if_any])
    destroy_darkness = py_trees.decorators.Condition(child=sub_tree)

    tree.add_children([
        Driver(),
        NavigateToHome(),
        SelectLevelThree(),
        destroy_darkness,
        CloseDriver()])
    tree.setup_with_descendants()
    run_tree(tree)

    assert tree.status == Status.SUCCESS
    diagram_tree(tree)

Here's the corresponding diagram generated from the diagram_tree(tree) call:

Behavior tree diagram

Todo

  • Better explanation of concept
  • Better explanation of implementation and test cases
  • Provide containerized execution environment
  • Experiment with asyncio implementation?

About

Using behavior trees to simulate user interaction with Selenium

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published