Difference between revisions of "GUI Testing/Framework"
(→Event Execution) |
(→Class layout) |
||
Line 120: | Line 120: | ||
====Single Test==== | ====Single Test==== | ||
+ | |||
+ | The class text of a single text should look similar to: | ||
+ | <code>[eiffel,N] | ||
+ | class Test | ||
+ | |||
+ | inherit | ||
+ | |||
+ | VISION2_TEST | ||
+ | |||
+ | create | ||
+ | make | ||
+ | |||
+ | feature | ||
+ | |||
+ | application_root: APPLICATION_ROOT_CLASS | ||
+ | -- Root class of application under test | ||
+ | |||
+ | make is | ||
+ | -- Execute test. | ||
+ | do | ||
+ | -- launch application in a separate thread | ||
+ | launch_application_threaded | ||
+ | |||
+ | -- get EV_APPLICATION object | ||
+ | set_ev_application (application_root) | ||
+ | mouse.set_click_delay (100) | ||
+ | keyboard.set_typing_delay (50) | ||
+ | |||
+ | -- run test procedure with rescue clauses | ||
+ | safe_run (agent run_test) | ||
+ | end | ||
+ | |||
+ | launch_application is | ||
+ | -- Launch application under test. | ||
+ | do | ||
+ | create application_root.make | ||
+ | wait (1000) | ||
+ | end | ||
+ | |||
+ | run_test is | ||
+ | -- Run test case. | ||
+ | local | ||
+ | widget: EV_WIDGET | ||
+ | do | ||
+ | widget := widget_by_name ("my widget") | ||
+ | |||
+ | mouse.left_click_on (widget) | ||
+ | keyboard.type ("some text") | ||
+ | keyboard.press (keys.Enter) | ||
+ | |||
+ | -- close application | ||
+ | mouse.left_click_menu ("File.Exit") | ||
+ | -- other way to close application | ||
+ | keyboard.press_modified (modifiers.Control, keys.Enter) | ||
+ | end | ||
+ | |||
+ | </code> | ||
====Framework==== | ====Framework==== |
Revision as of 13:15, 6 November 2006
Contents
Overview
The framework should facilitate retrieval of widgets and sending of events to a known GUI. This can be used to create a GUI test by hand.
Since it is not yet clear how to do the replay of an event sequence, the framework should use an abstraction layer to later change the way this is handled. The first implementation will consist of the simplest way where the executing test is compiled and run together with the application.
Vision2 Changes
In order to find widgets by name, widgets first need to have a name. Vision2 has to be extended accordingly by adding a name feature to the widgets. Proposed as follows:
class EV_WIDGET feature name: STRING -- Name of the widget -- If no specific name is set, the class type will be returned. full_path: STRING -- Full name of widget by prepending names of parent widgets -- Uses '.' as a separator. set_name (a_name: STRING) -- Set `name' to `a_name'. require no_period_in_name: not a_name.has ('.') ensure name_set: name = a_name
It remains to be checked if this should be inserted into EV_WIDGET or EV_ANY. To find widgets when having their name the container class can be extended by searching functionality:
class EV_CONTAINER feature find_widget_by_name (a_name: STRING): EV_WIDGET -- Find a widget in container with `a_name'. -- Sets `last_widget' to the found widget or Void if no widget was found with `a_name'. find_widget_by_name_recursive (a_name: STRING): EV_WIDGET -- Find a widget in container with `a_name' and search recursive. -- Recursive search is a breadth-first. find_widget_by_path (a_path: STRING): EV_WIDGET -- Find a widget which corresponds to `a_path'. -- The path will be split on periods and looked up accordingly. -- Asteriks can be used in the path as placeholders. If a part of the path is a class name -- all widgets which correspond to this class will be used to look further for the widget. -- A breadth-first search is used and the first result which matches `a_path' is returned. find_all_widgets_by_name (a_name: STRING): LIST [EV_WIDGET] -- TODO find_all_widgets_by_name_recursive (a_name: STRING): LIST [EV_WIDGET] -- TODO find_all_widgets_by_path (a_path: STRING): LIST [EV_WIDGET] -- TODO
It remains to be checked if regular expression support should be implemented in the search instead of the simple placeholder '*'.
wel and gtk
Both implementations of Vision2 - wel and gtk - have a support for names on the widget level. Thus it should not be a problem to add this functionality to Vision2.
Framework
Since the framework covers the replay part whose implementation is not yet defined, it should use an abstraction layer so tests can easily be adapted if necessary.
Common Functionality
- Launch the application
- If test and AUT are separate this needs to invoke a program by name
- If test and AUT are compiled together, this needs to instantiate the original root class and call its creation feature. Threads could make a problem since the normal Vision2 application uses the thread for the event loop. So the test either has to create a thread for its actions or somehow be called from the Vision2 event loop.
Widget Retrieval
- Get a widget
- By name or path in the whole application
- this includes searching for windows and dialogs
- By name or path in a specific widget
- this includes searching in a specific window or dialog
- By class
- By name or path and class
- Maybe: By specifying other attributes
- A search for icon, size, position, activation status or other attributes can be imagined
- Maybe: By specifying a prototype
- A widget is created and the attributes like size and icon are set. Then a widget with these properties is searched for.
- By name or path in the whole application
- Get a list of widgets
- (Same as above but always return all widgets which conform to the query)
- Get current focus
- Get menu (easy access on menubar)
Event Execution
- Invoke event
- On the whole application
- mouse events with coordinates relative to application
- keyboard commands issued on current focus
- On specific widget
- mouse events with coordinates relative to widget
- keyboard commands issued on specific widget (maybe focus should change automatically to better simulate behaviour)
- On the whole application
- Keyboard events
- Issue a list of keyboard events by string (no need to issue every single key stroke)
- Implement a way of describing which modifers are pressed
- Mouse events
- Clicks
- Movement
- Dragging
- Mode where some events can be infered
- When two mouse clicks happen on different coordinates, the framework can issue mouse movement events between the positions to better simulate the user behaviour. This can be made as an option which can be activated or deactivated.
Class layout
Single Test
The class text of a single text should look similar to:
class Test inherit VISION2_TEST create make feature application_root: APPLICATION_ROOT_CLASS -- Root class of application under test make is -- Execute test. do -- launch application in a separate thread launch_application_threaded -- get EV_APPLICATION object set_ev_application (application_root) mouse.set_click_delay (100) keyboard.set_typing_delay (50) -- run test procedure with rescue clauses safe_run (agent run_test) end launch_application is -- Launch application under test. do create application_root.make wait (1000) end run_test is -- Run test case. local widget: EV_WIDGET do widget := widget_by_name ("my widget") mouse.left_click_on (widget) keyboard.type ("some text") keyboard.press (keys.Enter) -- close application mouse.left_click_menu ("File.Exit") -- other way to close application keyboard.press_modified (modifiers.Control, keys.Enter) end