forked from joel-costigliola/assertj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassertj-swing-running.html
283 lines (243 loc) · 14.1 KB
/
assertj-swing-running.html
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="AssertJ site">
<meta name="author" content="Joel Costigliola">
<title>AssertJ / Fluent assertions for java</title>
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Inconsolata|Source+Code+Pro|Open+Sans|Ubuntu|Varela+Round|Karla">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet">
<script src="highlight/highlight.pack.js"></script>
<link rel="stylesheet" href="highlight/styles/railscasts.css">
<script>hljs.initHighlightingOnLoad();</script>
<link href="css/assertj.min.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.png" />
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- You'll want to use a responsive image option so this logo looks good on devices - I recommend using something like retina.js (do a quick Google search for it and you'll find it) -->
<a class="navbar-brand" href="index.html">AssertJ</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="assertj-core-quick-start.html">Quick start</a></li>
<li><a href="assertj-news.html">News</a></li>
<li><a href="assertj-core.html">Core</a></li>
<li><a href="assertj-assertions-generator.html">Assertions generator</a></li>
<li><a href="assertj-guava.html">Guava</a></li>
<li><a href="assertj-joda-time.html">Joda-Time</a></li>
<li><a href="assertj-db.html">DB</a></li>
<li><a href="assertj-neo4j.html">Neo4j</a></li>
<li><a href="assertj-swing.html">Swing</a></li>
<li><a href="assertj-help.html">Help</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row" >
<div class="col-md-2 assertj-sidebar-menu">
<div class="bs-sidebar hidden-print affix-top" role="complementary">
<ul class="bs-sidenav nav ">
<li class="sidenav-header">About</li>
<li><a href="assertj-swing.html">Overview</a></li>
<li><a href="assertj-swing-quick-start.html">Quick start</a></li>
<li><a href="assertj-swing-news.html">News & releases</a></li>
<li><a href="swing/api/index.html">Javadoc</a></li>
<li><a href="assertj-swing.html#code">Code & issues <i class="fa fa-github"></i></a></li>
<li><a href="assertj-swing.html#contributing">Contributing</a></li>
<li class="sidenav-header">Working with it</li>
<li><a href="assertj-swing-getting-started.html">Getting started</a></li>
<li><a href="assertj-swing-basics.html">Basics</a></li>
<li><a href="assertj-swing-edt.html">EDT</a></li>
<li><a href="assertj-swing-lookup.html">Component lookup</a></li>
<li><a href="assertj-swing-launch.html">Launching</a></li>
<li><a href="assertj-swing-input.html">Input simulation</a></li>
<li><a href="assertj-swing-running.html">Running tests</a></li>
<li><a href="assertj-swing-troubleshooting.html">Troubleshooting</a></li>
<li><a href="assertj-swing-advanced.html">Advanced features</a></li>
<li class="sidenav-header">Migrating</li>
<li><a href="assertj-swing-migrating.html">From Fest</a></li>
</ul>
</div>
</div>
<div class="col-lg-10 col-md-10 col-sm-10 text-left" >
<h1 class="page-header">Running tests</h1>
<p>GUI tests, by nature, are slower and more intrusive than regular unit tests. This section provides
some practical advices.</p>
<h2>Interrupting running tests</h2>
<p>AssertJ Swing provides support for killing an already running test suite.</p>
<div class="panel panel-info">
<div class="panel-heading"><a href="http://www.mseedsoft.com/" target="_blank">Simeon H. K. Fitch</a>
- inventor of this feature</div>
<div class="panel-body">
<em>
Let's say you're running a pretty big FEST-Swing test, one that takes a couple minutes to run. In the
middle of it, a Skype call comes in. You need to answer the call, but you currently don't own the mouse!
Eventually, some frantic combination of Alt, Ctrl, Cmd, Tab, Esc, F1-12, gets the window buried, and you
can accept the call, but you want something more "decisive" to kill the test run.
</em>
</div>
</div>
<p>The <code>EmergencyAbortListener</code> implements this feature. After registering this listener in your
test, you can terminate your test using the key combination <kbd>Ctrl</kbd> + <kbd>Shift</kbd> +
<kbd>A</kbd>.</p>
<pre><code class="language-java">private EmergencyAbortListener listener;
@BeforeMethod public void setUp() {
listener = EmergencyAbortListener.registerInToolkit();
// set up your test fixture.
}
@AfterMethod public void tearDown() {
listener.unregister();
// clean up resources.
}</code></pre>
<p>The key combination can be configured too:</p>
<pre><code class="language-java">listener = EmergencyAbortListener.registerInToolkit()
.keyCombination(key(VK_C).modifiers(SHIFT_MASK));
</code></pre>
<h2><span id="dont-disrupt-desktop"></span>Running tests without (disrupting the) desktop</h2>
<p>AssertJ Swing tests can be executed in a Continuous Integration (CI) server. The following are
tips to run and troubleshoot AssertJ Swing tests in CI servers, in different environments.</p>
<h3>Running AssertJ Swing under a vnc server</h3>
<div class="panel panel-info">
<div class="panel-heading"><a href="http://ineffable.us/" target="_blank">Jason Goodwin</a></div>
<div class="panel-body">
<em>
<p>
In order to get the most value from an automated GUI testing tool like FEST-Swing [or
AssertJ Swing], you'll want to have the ability to run your full suite of tests frequently.
Doing so on your personal desktop can be very time consuming, as you must largely sit and watch
while the tests run. If everything goes as planned, your tests will all pass and you need not have
been watching it at all. If you're already running a CI (Continuous Integration) server like me
(Hudson is my favorite), then the natural thing to do is run your GUI tests as part of your CI
process. Even if you're not running a CI server, you would stand to benefit from not being forced t
o watch your tests run every time.
</p><p>
If you're running Linux, BSD, or any *NIX style operating system chances are that CI server probably
doesn't even have X running, so how are you to run your GUI tests?
</p>
</em>
</div>
</div>
<p>
<a href="http://www.tightvnc.com/" target="_blank">TightVNC</a> is the answer (or any other vnc server
you could think of). It creates a desktop that you can access via a vnc viewer locally and even
remotely. We are using TightVNC for running the tests of AssertJ Swing, too. If you're running Ubuntu
or Debian, simply <code>sudo apt-get (or aptitude) install tightvncserver</code>. For other distributions
(or OS) follow their normal process for installing packages.</p>
<p>
Once installed, the process is to start the vnc server, run the tests and then kill the vnc server. Since
this could be done by an ape, we're using a
<a href="https://github.com/croesch/beefiles/blob/master/src/execute-on-vnc.sh" target="_blank">script</a>
to perform all these steps automatically:
</p>
<pre><code class="language-bash">execute-on-vnc.sh mvn test</code></pre>
<p>
This
<ol>
<li>starts a local vnc server at display 42</li>
<li>sets the <code>DISPLAY</code> variable</li>
<li>executes <code>mvn test</code></li>
<li>restores the previous <code>DISPLAY</code> value</li>
<li>stops the vnc server</li>
</ol>
The script makes it easy to start an application (e.g. tests) <em>in the background</em>, without
disrupting your desktop. If you need to access it remotely or to run multiple applications (e.g. tests),
you'll have to adapt the script to your needs.
</p>
<div class="panel panel-info">
<div class="panel-heading"><strong>Important</strong></div>
<div class="panel-body">
Why don't we just use <code>xvfb-run</code>? Our tests maximize windows and do other stuff the default
window manager of <code>xvfb</code> doesn't support. TightVNC makes it easy to use another window
manager. Just add <code>gnome-wm &</code> (or the window manager of your choice) to
<code>~/.vnc/xstartup</code> and you're ready to run.
</div>
</div>
<p>Hopefully this simple idea will help free your desktop (and you) from spending time watching
AssertJ Swing work its magic.</p>
<h3>Hudson under Windows</h3>
<p><em>by Uli Schrempp (written for FEST)</em></p>
<p>As we develop software with the target platform Windows, we need to run the tests on Windows platform too.
So the X-Server approach does not fit. Here are two solutions:</p>
<h4>Running Hudson service in interactive mode</h4>
<p>Open the service properties dialog of the Hudson service. Select in the <em>Log On</em> tab <em>Run as
Local System account</em> and check the <em>Allow service to interact with desktop</em>.</p>
<p>This works fine, but when the Hudson system needs to access some shares in the network, then the Local
System account might not have the appropriate permissions.</p>
<h4>Running Hudson as application via JNLP</h4>
<p>Here is the challenge to automatically start the Hudson agent via command-line after a restart. Here's a
short recipe:</p>
<ol>
<li>Configure auto-logon in Windows registry. Set the following keys<ul>
<li><code>HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon=1</code></li>
<li><code>HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName=testuser</code></li>
<li><code>HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword=secret</code></li>
</ul></li>
<li>Start Hudson agent on start-up<ul>
<li>Create a batch file to start Hudson
<pre><code class="language-bash">javaws http://HUDSON_MASTER/computer/COMPUTERNAME/slave-agent.jnlp</code></pre>
</li>
<li>Add this batch file to the start-up folder</li>
</ul></li>
<li>Add remote control support for this machine<ul>
<li>Create some scheduled tasks to start and stop Hudson and disable them</li>
<li>So the Hudson master node can call trigger the agent node remotely via command-line</li>
</ul></li>
</ol>
<h4>Remote Desktop Issue</h4>
<p>Sometimes when there was a remote-desktop connection to this machine running Hudson in application mode,
the Windows session seems to be closed and then the tests could not start the application. Solution for
that is using VNC.</p>
<h3>Troubleshooting TeamCity under Windows</h3>
<p>The following tips are the result of <a
href="http://groups.google.com/group/easytesting/browse_frm/thread/923077e05f4fec63" target="_blank">this
thread</a> in the mailing list. Many thanks to (in alphabetical order)</p>
<ul>
<li>Olivier DOREMIEUX</li>
<li>Eric Kolotyluk</li>
<li>Peter Murray</li>
</ul>
<p>During automated builds</p>
<ol>
<li>Make sure there is a desktop running for the build agent</li>
<li>On Windows, disable Remote Desktop because it can kill the desktop the build agent is using - use VNC
instead because it won't log you out (if you configure it that way)</li>
<li>On Windows, use a local user account for the build agent, not a service account</li>
<li>On Windows, if you launch the build agent with the <code>cmd</code> command use the <code>/k</code>
option not the <code>/c</code> option - this prevents the command window from closing and orphaning
the build agent</li>
</ol>
</div>
</div>
</div>
<br>
<!--
<div class="container">
<footer>
<div class="row">
<div class="col-lg-12">
<p>AssertJ - Licensed under the Apache License, Version 2.0.</p>
</div>
</div>
</footer>
</div>
-->
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/modern-business.js"></script>
<script src="js/assertj.js"></script>
</body>
</html>