summaryrefslogtreecommitdiffstats
path: root/doc/html/qtuitest-tutorial4.html
blob: f85c69e17fb2be84e33e0085dcf045f1c55fb28b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- ../../doc/src/qtuitest_tutorial.qdoc -->
<head>
  <title>Chapter 4: Putting It All Together</title>
  <link rel="prev" href="qtuitest-tutorial3.html" />
  <link rel="contents" href="qtuitest-tutorial.html" />
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://qt.nokia.com/"><img src="images/qt-logo.png" align="left" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td align="right" valign="top" width="230"></td></tr></table><p>
[Previous: <a href="qtuitest-tutorial3.html">Chapter 3</a>]
[<a href="qtuitest-tutorial.html">Contents</a>]
</p>
<h1 class="title">Chapter 4: Putting It All Together<br /><span class="subtitle"></span>
</h1>
<p>Using the simple building blocks of textual input and output and navigation functions, with the data driven testing approach, a full testcase can be written for creating a new contact. Note that the functions for creating and verifying a contact have been moved out into helper functions; this allows them to be reused for subsequent tests. This is very useful for cases where, for instance, one test's precondition might be that a contact has been successfully created.</p>
<pre> testcase = {
     initTestCase: function() {
         <span class="comment">// Start &quot;Contacts&quot; when the testcase starts.</span>
         startApplication( &quot;Contacts&quot; );
     },

     creating_a_contact: function(name, emails, company, jobTitle, businessPhone) {
         create_contact(name, emails, company, jobTitle, businessPhone);
         verify_contact(name, emails, company, jobTitle, businessPhone);
     },

     creating_a_contact_data: {
         simple:           [ &quot;Billy Jones&quot;,      &quot;billy@example.com&quot;,   &quot;Hotdog Inc.&quot;,     &quot;Hotdog Engineer&quot;,    &quot;12345&quot;   ],
         letters_in_phone: [ &quot;Joan Example&quot;,     &quot;joan@example.com&quot;,    &quot;Example Inc.&quot;,    &quot;Exemplary Engineer&quot;, &quot;555 EXA&quot; ],
         three_names:      [ &quot;Jon John Johnson&quot;, &quot;jjj@example.com&quot;,     &quot;Sillynames Inc.&quot;, &quot;Dog Walker&quot;,         &quot;12345&quot;   ],
         no_job:           [ &quot;William Doe&quot;,      &quot;bill@example.net&quot;,     undefined,         undefined,            undefined ]
     }
 }

<span class="comment"> // Create a contact with the given details.</span>
 function create_contact(name, emails, company, jobTitle, businessPhone) {
     <span class="comment">// Verify that we're on the home screen of the &quot;Contacts&quot; app.</span>
     waitForTitle( &quot;Contacts&quot; );

     <span class="comment">// Select &quot;New contact&quot; from context menu.</span>
     select( &quot;New contact&quot;, optionsMenu() );

     <span class="comment">// Navigate to the &quot;Contact&quot; tab.</span>
     <span class="comment">// This is the default tab, but with this code we ensure the</span>
     <span class="comment">// test will work if it becomes no longer the default.</span>
     select( &quot;Contact&quot;, tabBar() );

     <span class="comment">// Fill in fields on the &quot;Contact&quot; tab.</span>
     <span class="comment">// enter() returns immediately if we try to enter an undefined</span>
     <span class="comment">// value.</span>
     enter( name,   &quot;Name&quot; );
     enter( emails, &quot;Emails&quot; );

     <span class="comment">// Navigate to the &quot;Business&quot; tab.</span>
     select( &quot;Business&quot;, tabBar() );

     <span class="comment">// Fill in fields on the &quot;Business&quot; tab.</span>
     enter( company,       &quot;Company&quot; );
     enter( jobTitle,      &quot;Title&quot; );
     enter( businessPhone, &quot;Phone&quot; );

     <span class="comment">// Press the Back key to commit the new contact</span>
     select( &quot;Back&quot;, softMenu() );
 }

<span class="comment"> // Verify that a contact with the given details exists.</span>
 function verify_contact(name, emails, company, jobTitle, businessPhone) {
     <span class="comment">// Verify that we're on the contacts list.</span>
     waitForTitle( &quot;Contacts&quot; );

     <span class="comment">// Select the contact with the given name.</span>
     select( name );

     <span class="comment">// Navigate to the &quot;Details&quot; tab and get the displayed text.</span>
     select( &quot;Details&quot;, tabBar() );
     var details = getText();

     <span class="comment">// Now verify that the details contains all of the non-null information</span>
     <span class="comment">// for the contact.</span>
     if (name != undefined)          verify( details.contains(name) );
     if (emails != undefined)        verify( details.contains(emails) );
     if (company != undefined)       verify( details.contains(company) );
     if (jobTitle != undefined)      verify( details.contains(jobTitle) );
     if (businessPhone != undefined) verify( details.contains(businessPhone) );
 }</pre>
<p>The above test has been written to be reasonably permissive; it will succeed as long as the text shown by the contacts application contains all of the information for the created contact, and it does not test things such as the formatting of the given text, and does not test every single field. However, this test is well insulated against minor changes to the tested application GUI.</p>
<p><a href="qtuitest.html">QtUiTest</a> allows the tester to decide how strict a test should be. If pixel-perfect accuracy is required for output, a test can be written to test every screen with <a href="qsystemtest.html#verifyImage">verifyImage()</a>. In contrast, a high-level text-based approach as shown above can result in effective tests which remain correct even when significant UI changes occur.</p>
<p>There are many other methods available for use; for further information, refer to the <a href="qsystemtest.html">QSystemTest</a> documentation.</p>
<p>
[Previous: <a href="qtuitest-tutorial3.html">Chapter 3</a>]
[<a href="qtuitest-tutorial.html">Contents</a>]
</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%" align="left">Copyright &copy; 2009 Nokia Corporation and/or its subsidiary(-ies)</td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">QtUiTest</div></td>
</tr></table></div></address></body>
</html>