Heliacorreia (Talk | contribs) |
Heliacorreia (Talk | contribs) |
||
| Line 1: | Line 1: | ||
| - | = Testability Driver | + | = Testability Driver - Tutorial for test creation = |
This page describes how to automate a simple test. | This page describes how to automate a simple test. | ||
| Line 60: | Line 60: | ||
“require” method loads the mentioned file whereas “include” method embeds the specified module into the current module (it can be used to enhance a class). More detail can be found [http://www.tutorialspoint.com/ruby/ruby_modules.htm here], [http://stackoverflow.com/questions/318144/what-is-the-difference-between-include-and-require-in-ruby here] or [http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/ae718697e28e2568?pli=1 here]. | “require” method loads the mentioned file whereas “include” method embeds the specified module into the current module (it can be used to enhance a class). More detail can be found [http://www.tutorialspoint.com/ruby/ruby_modules.htm here], [http://stackoverflow.com/questions/318144/what-is-the-difference-between-include-and-require-in-ruby here] or [http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/ae718697e28e2568?pli=1 here]. | ||
| - | + | ||
| + | The following lines are preceeded by commented lines beginning with # character that help understanding their purpose, and we can see that the structure of a Ruby script basically consists of: | ||
* Defining the SUT (system under test) TDriver should interact with | * Defining the SUT (system under test) TDriver should interact with | ||
* Defining the application to run and test | * Defining the application to run and test | ||
Contents |
This page describes how to automate a simple test.
TDriver and tests/calculator applications are installed.
In file /etc/tdriver/tdriver_parameters.xml , “sut_id” section is empty like below:
<sut id="sut_qt" template="qt"> <!-- use default values --> </sut>
For guidance, see http://wiki.meego.com/Quality/QA-tools/TDriver/Getting_Started.
We should ensure everything is ready for further actions by launching qttasserver, TDriver and calculator applications:
qttasserver & tdriver_visualizer & calculator -testability
Then clicking TDriver's “File > Refresh” menu item should lead to get the same view as below:
We get a copy of the template ruby script available under /etc/tdriver/visualizer to your /home/$USER folder for instance, renaming it as my_script.rb:
cp /etc/tdriver/visualizer/plain_tdriver.rb.template /home/$USER/my_script.rb
And update the file's execution attributes:
chmod ugo+x /home/$USER/my_script.rb
From Tdriver, we click “View > Docks and toolbars > Code Editor” menu item. Code Editor window appears at the bottom of TDriver, we click “File > Open...” menu item and browse to select my_script.rb, we should get the same view as below:
Now let's have a closer look at the script contents.
The first two lines mention:
require 'tdriver' include TDriverVerify
“require” method loads the mentioned file whereas “include” method embeds the specified module into the current module (it can be used to enhance a class). More detail can be found here, here or here.
The following lines are preceeded by commented lines beginning with # character that help understanding their purpose, and we can see that the structure of a Ruby script basically consists of:
So let's say we want to automate a test that clicks calculator's numbered buttons only, and takes a screenshot of the whole application after each click.
First thing to do is update the application name, by completing existing line like below:
@app = @sut.run( :name => "calculator", :arguments => "-testability")
Then from Code Editor (bottom of TDriver), we place the cursor after the "# Add your interaction and verify code here..." like below:
From Image View (right part of TDriver), we drag the mouse over “9” button for instance. A red line displays arount it, and “sut” item unfolds to display selected button:
We right-click and from the contextual menu, we select “Insert into editor” item:
The following line is added to the script, as shown below:
@app.Button( :name => 'nineButton' )
Now we need to append the method corresponding to a button click. From Properties (left part of TDriver), we select “Methods” tab, and browse its contents. To get more detail about an item, we simply drag the mouse over it:
“Tap” method seems to answer our needs, so here again we right-click the desired method and select “Insert to editor”:
Tap method will be appended to our button line:
Now let's save our script and test it so far:
Through this first test, we could quickly see that calculator opened, 9 number displayed in the editor, then the application closed. A new window called Script Console opened along with calculator, it displays traces resulting from our script's execution:
Now to complete the test, we will take a snapshot of the application. From the center part of TDriver, we select “Application Calculator” line, then we browse Methods tab to find the appropriate method to use, that is "capture_screen". Finally, we write below line into Code Editor:
@app.capture_screen("PNG", "./calc_snapshot.png")
The method's arguments are the snapshot's format (i.e. “PNG”), and its path and name.
Seems we are done?! Let's give our script another try and check the snapshot's display.
Well, despite the Script Console not showing any error, instead of displaying number 9 the snapshot may show 0. As a result, this “issue” has more to see with asynchronicity than with a bug since what we observe here is that we kind of took the snapshot too early, and the edit had no time to refresh its display. So before taking the snapshot, we should take some time to verify our input, adding below line right after the call to button 9's tap method:
verify(12, "The taped number should display") {@app.QLineEdit( :"displayText" => @app.Button( :name => 'nineButton' ).attribute("text"))}
We set a timeout (12 seconds) during which the edit's display value is compared with the text value of taped button. If both values correspond, script continues and snapshot is taken. But if values don't match before timeout expires, then script is halted and exits with code 1, and this information is reported into Script Console. 12 seconds is an arbitrary delay and we assume it is enough for the edit to show up correctly.
In order to test every numbered button, we could duplicate the lines we have and just update the buttons and snapshots' name. Or we could take advantage of the functionalities offered by TDriver as well as by Ruby scripting language, and in order to prepare to write a program a bit more abstract, we can try to answer some questions like:
Below is an example of a way to write such a script: