File tree 3 files changed +39
-1
lines changed
3 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -248,6 +248,7 @@ public static class Builder {
248
248
private final List <String > excludes = new ArrayList <String >();
249
249
private String options = "{}" ;
250
250
private Boolean skipFrames = false ;
251
+ private int timeout = 30 ;
251
252
252
253
/**
253
254
* Initializes the Builder class to chain configuration before analyzing pages.
@@ -259,6 +260,15 @@ public Builder(final WebDriver driver, final URL script) {
259
260
this .script = script ;
260
261
}
261
262
263
+ /**
264
+ * Set the script timeout.
265
+ * @param timeout
266
+ */
267
+ public Builder setTimeout (int timeout ) {
268
+ this .timeout = timeout ;
269
+ return this ;
270
+ }
271
+
262
272
/**
263
273
* Skips iframe checks
264
274
*/
@@ -357,7 +367,7 @@ public JSONObject analyze(final WebElement context) {
357
367
private JSONObject execute (final String command , final Object ... args ) {
358
368
AXE .inject (this .driver , this .script , this .skipFrames );
359
369
360
- this .driver .manage ().timeouts ().setScriptTimeout (30 , TimeUnit .SECONDS );
370
+ this .driver .manage ().timeouts ().setScriptTimeout (this . timeout , TimeUnit .SECONDS );
361
371
362
372
Object response = ((JavascriptExecutor ) this .driver ).executeAsyncScript (command , args );
363
373
JSONObject result = new JSONObject ((Map ) response );
Original file line number Diff line number Diff line change @@ -111,6 +111,26 @@ public void testAccessibilityWithOptions() {
111
111
}
112
112
}
113
113
114
+ @ Test
115
+ public void testCustomTimeout () {
116
+ driver .get ("http://localhost:5005" );
117
+
118
+ boolean didTimeout = false ;
119
+ try {
120
+ new AXE .Builder (driver , ExampleTest .class .getResource ("/timeout.js" ))
121
+ .setTimeout (1 )
122
+ .analyze ();
123
+ } catch (Exception e ) {
124
+ String msg = e .getMessage ();
125
+ if (msg .indexOf ("1 seconds" ) == -1 ) {
126
+ assertTrue ("Did not error with timeout message" , msg .indexOf ("1 seconds" ) != -1 );
127
+ }
128
+ didTimeout = true ;
129
+ }
130
+
131
+ assertTrue ("Did set custom timeout" , didTimeout );
132
+ }
133
+
114
134
/**
115
135
* Test a specific selector or selectors
116
136
*/
Original file line number Diff line number Diff line change
1
+ // A fake axe-core that takes 5 minutes to finish
2
+ window . axe = {
3
+ run : function ( context , options , callback ) {
4
+ setTimeout ( function ( ) {
5
+ callback ( )
6
+ } , 1000 * 60 * 5 )
7
+ }
8
+ }
You can’t perform that action at this time.
0 commit comments