forked from unknown-horizons/unknown-horizons
-
Notifications
You must be signed in to change notification settings - Fork 0
Writing gui tests
Chris Oelmueller edited this page Mar 29, 2013
·
2 revisions
This page gives a quick overview of how to write gui tests in Unknown Horizons
python run_uh.py --sp-seed=42 --gui-log --start-dev-map
It is important (or at least a good idea) to use the same RNG seed as the tests --sp-seed=42
Enable the logger --gui-log
Use --start-dev-map
or --load-map
to jump directly into the game, this way you can avoid to log menu interactions.
When interacting with the game, code will be printed on stdout
Example:
gui.cursor_click(64, -6, 'left') # selected the ship
gui.cursor_click(60, 0, 'right') # sent ship to (60, 0)
gui.trigger('overview_trade_ship', 'found_settlement') # select the 'build settlement' button
gui.cursor_click(59, 4, 'left') # place a warehouse at (59, 4)
Testcode template:
@gui_test(use_dev_map=True)
def test_example(gui):
# insert your code here
Example:
@gui_test(use_dev_map=True)
def test_example(gui):
# Units cannot be selected right now, you need to do it this way. This is almost
# the same as selecting it with the mouse
ship = get_player_ship(gui.session)
gui.select([ship])
gui.cursor_click(60, 0, 'right') # sent ship to (60, 0)
while (ship.position.x, ship.position.y) != (60, 0): # wait for the ship to arrive at its destination
gui.run()
gui.trigger('overview_trade_ship', 'found_settlement') # click the 'build settlement' button
gui.cursor_click(59, 4, 'left') # place a warehouse at (59, 4)
Documented example: https://github.com/unknown-horizons/unknown-horizons/blob/master/tests/gui/test_example.py
Real tests: https://github.com/unknown-horizons/unknown-horizons/tree/master/tests/gui/ingame
- Selecting units with the mouse does not work, obtain a reference to the instance and use
gui.select([instance])
- Code for handling dialogs is generated, but the generator will fail in some cases, e.g. credits window
- once the test function returns, the game will quit. if you want to see the results of the test, insert a
gui.run(2**10)
for example
Home > Documentation >
- [Design Document] (TODO)
- Read the Docs
- Scenarios
- Packagers
- Multiplayer
- Pychan pitfalls