Heliacorreia (Talk | contribs) |
Heliacorreia (Talk | contribs) |
||
| Line 61: | Line 61: | ||
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: | 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 application to run and test | |
| - | + | * Defining the tests to be performed within the application | |
| - | + | * Finally closing the application | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| Line 119: | Line 115: | ||
Now let's save our script and test it so far: | Now let's save our script and test it so far: | ||
| + | * We don't forget to close calculator as our script will launch and stop it itself. | ||
| + | * From Code Editor, we click “File > Save” menu item. | ||
| + | * Then we click “Run > Run with Ruby” menu item. | ||
| - | |||
| - | + | 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: | |
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
| - | + | ||
[[File:TDriver_Tutorial_for_test_creation_10.png|800px|Writing a test from TDriver UI - 8 (click to enlarge)]] | [[File:TDriver_Tutorial_for_test_creation_10.png|800px|Writing a test from TDriver UI - 8 (click to enlarge)]] | ||
| Line 139: | Line 132: | ||
| - | Seems we are done?! Let's give our script another try | + | Seems we are done?! Let's give our script another try and check the snapshot's display. |
| Line 155: | Line 148: | ||
== Improving a test based on TDriver's features and Ruby syntax == | == Improving a test based on TDriver's features and Ruby syntax == | ||
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: | 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: | ||
| - | + | * Is there a way to list every buttons at once? | |
| - | + | * Do numbered buttons have something in common? | |
| - | + | * Do numbered buttons have differences? | |
| - | + | ||
| - | + | ||
| - | + | ||
| Line 169: | Line 159: | ||
== Sources and useful links == | == Sources and useful links == | ||
| - | https://projects.forum.nokia.com/Testabilitydriver/wiki/FeatureVisualizerCodeEditor#WritingaScriptwithCodeEditor | + | * https://projects.forum.nokia.com/Testabilitydriver/wiki/FeatureVisualizerCodeEditor#WritingaScriptwithCodeEditor |
| - | https://projects.forum.nokia.com/Testabilitydriver/wiki | + | * https://projects.forum.nokia.com/Testabilitydriver/wiki |
| - | http://www.rubyist.net/~slagell/ruby/ | + | * http://www.rubyist.net/~slagell/ruby/ |
| - | http://www.tutorialspoint.com/ruby/index.htm | + | * http://www.tutorialspoint.com/ruby/index.htm |
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.
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: