@@ -1097,6 +1097,54 @@ var Protractor = function(webdriverInstance, opt_baseUrl, opt_rootElement) {
1097
1097
this . addBaseMockModules_ ( ) ;
1098
1098
} ;
1099
1099
1100
+ /**
1101
+ * The same as {@code webdriver.WebDriver.prototype.executeScript},
1102
+ * but with a customized description for debugging.
1103
+ *
1104
+ * @private
1105
+ * @param {!(string|Function) } script The script to execute.
1106
+ * @param {string } description A description of the command for debugging.
1107
+ * @param {...* } var_args The arguments to pass to the script.
1108
+ * @return {!webdriver.promise.Promise.<T> } A promise that will resolve to the
1109
+ * scripts return value.
1110
+ * @template T
1111
+ */
1112
+ Protractor . prototype . executeScript_ = function ( script , description ) {
1113
+ if ( typeof script === 'function' ) {
1114
+ script = 'return (' + script + ').apply(null, arguments);' ;
1115
+ }
1116
+
1117
+ return this . driver . schedule (
1118
+ new webdriver . Command ( webdriver . CommandName . EXECUTE_SCRIPT ) .
1119
+ setParameter ( 'script' , script ) .
1120
+ setParameter ( 'args' , Array . prototype . slice . call ( arguments , 2 ) ) ,
1121
+ description ) ;
1122
+ } ;
1123
+
1124
+ /**
1125
+ * The same as {@code webdriver.WebDriver.prototype.executeAsyncScript},
1126
+ * but with a customized description for debugging.
1127
+ *
1128
+ * @private
1129
+ * @param {!(string|Function) } script The script to execute.
1130
+ * @param {string } description A description for debugging purposes.
1131
+ * @param {...* } var_args The arguments to pass to the script.
1132
+ * @return {!webdriver.promise.Promise.<T> } A promise that will resolve to the
1133
+ * scripts return value.
1134
+ * @template T
1135
+ */
1136
+ Protractor . prototype . executeAsyncScript_ =
1137
+ function ( script , description ) {
1138
+ if ( typeof script === 'function' ) {
1139
+ script = 'return (' + script + ').apply(null, arguments);' ;
1140
+ }
1141
+ return this . driver . schedule (
1142
+ new webdriver . Command ( webdriver . CommandName . EXECUTE_ASYNC_SCRIPT ) .
1143
+ setParameter ( 'script' , script ) .
1144
+ setParameter ( 'args' , Array . prototype . slice . call ( arguments , 2 ) ) ,
1145
+ description ) ;
1146
+ } ;
1147
+
1100
1148
/**
1101
1149
* Instruct webdriver to wait until Angular has finished rendering and has
1102
1150
* no outstanding $http calls before continuing.
@@ -1108,12 +1156,14 @@ Protractor.prototype.waitForAngular = function() {
1108
1156
if ( this . ignoreSynchronization ) {
1109
1157
return webdriver . promise . fulfilled ( ) ;
1110
1158
}
1111
- return this . driver . executeAsyncScript (
1112
- clientSideScripts . waitForAngular , this . rootEl ) . then ( function ( browserErr ) {
1113
- if ( browserErr ) {
1114
- throw 'Error while waiting for Protractor to ' +
1115
- 'sync with the page: ' + JSON . stringify ( browserErr ) ;
1116
- }
1159
+ return this . executeAsyncScript_ (
1160
+ clientSideScripts . waitForAngular , 'Protractor.waitForAngular()' ,
1161
+ this . rootEl ) .
1162
+ then ( function ( browserErr ) {
1163
+ if ( browserErr ) {
1164
+ throw 'Error while waiting for Protractor to ' +
1165
+ 'sync with the page: ' + JSON . stringify ( browserErr ) ;
1166
+ }
1117
1167
} ) . then ( null , function ( err ) {
1118
1168
var timeout ;
1119
1169
if ( / a s y n c h r o n o u s s c r i p t t i m e o u t / . test ( err . message ) ) {
@@ -1242,20 +1292,24 @@ Protractor.prototype.get = function(destination, opt_timeout) {
1242
1292
1243
1293
destination = this . baseUrl . indexOf ( 'file://' ) === 0 ?
1244
1294
this . baseUrl + destination : url . resolve ( this . baseUrl , destination ) ;
1295
+ var msg = function ( str ) {
1296
+ return 'Protractor.get(' + destination + ') - ' + str ;
1297
+ } ;
1245
1298
1246
1299
if ( this . ignoreSynchronization ) {
1247
1300
return this . driver . get ( destination ) ;
1248
1301
}
1249
1302
1250
1303
this . driver . get ( this . resetUrl ) ;
1251
- this . driver . executeScript (
1304
+ this . executeScript_ (
1252
1305
'window.name = "' + DEFER_LABEL + '" + window.name;' +
1253
- 'window.location.replace("' + destination + '");' ) ;
1306
+ 'window.location.replace("' + destination + '");' ,
1307
+ msg ( 'reset url' ) ) ;
1254
1308
1255
1309
// We need to make sure the new url has loaded before
1256
1310
// we try to execute any asynchronous scripts.
1257
1311
this . driver . wait ( function ( ) {
1258
- return self . driver . executeScript ( 'return window.location.href;' ) .
1312
+ return self . executeScript_ ( 'return window.location.href;' , msg ( 'get url' ) ) .
1259
1313
then ( function ( url ) {
1260
1314
return url !== self . resetUrl ;
1261
1315
} , function ( err ) {
@@ -1271,11 +1325,12 @@ Protractor.prototype.get = function(destination, opt_timeout) {
1271
1325
}
1272
1326
} ) ;
1273
1327
} , timeout ,
1274
- 'Timed out waiting for page to load after ' + timeout + 'ms' ) ;
1328
+ 'waiting for page to load for ' + timeout + 'ms' ) ;
1275
1329
1276
1330
// Make sure the page is an Angular page.
1277
- self . driver . executeAsyncScript ( clientSideScripts . testForAngular ,
1278
- Math . floor ( timeout / 1000 ) ) .
1331
+ self . executeAsyncScript_ ( clientSideScripts . testForAngular ,
1332
+ msg ( 'test for angular' ) ,
1333
+ Math . floor ( timeout / 1000 ) ) .
1279
1334
then ( function ( angularTestResult ) {
1280
1335
var hasAngular = angularTestResult [ 0 ] ;
1281
1336
if ( ! hasAngular ) {
@@ -1294,16 +1349,18 @@ Protractor.prototype.get = function(destination, opt_timeout) {
1294
1349
var mockModule = this . mockModules_ [ i ] ;
1295
1350
var name = mockModule . name ;
1296
1351
moduleNames . push ( name ) ;
1297
- var executeScriptArgs = [ mockModule . script ] . concat ( mockModule . args ) ;
1298
- this . driver . executeScript . apply ( this , executeScriptArgs ) .
1352
+ var executeScriptArgs = [ mockModule . script , msg ( 'add mock module ' + name ) ] .
1353
+ concat ( mockModule . args ) ;
1354
+ this . executeScript_ . apply ( this , executeScriptArgs ) .
1299
1355
then ( null , function ( err ) {
1300
1356
throw 'Error while running module script ' + name +
1301
1357
': ' + err . message ;
1302
1358
} ) ;
1303
1359
}
1304
1360
1305
- return this . driver . executeScript (
1361
+ return this . executeScript_ (
1306
1362
'angular.resumeBootstrap(arguments[0]);' ,
1363
+ msg ( 'resume bootstrap' ) ,
1307
1364
moduleNames ) ;
1308
1365
} ;
1309
1366
@@ -1325,9 +1382,11 @@ Protractor.prototype.refresh = function(opt_timeout) {
1325
1382
return self . driver . navigate ( ) . refresh ( ) ;
1326
1383
}
1327
1384
1328
- return self . driver . executeScript ( 'return window.location.href' ) . then ( function ( href ) {
1329
- return self . get ( href , timeout ) ;
1330
- } ) ;
1385
+ return self . executeScript_ (
1386
+ 'return window.location.href' ,
1387
+ 'Protractor.refresh() - getUrl' ) . then ( function ( href ) {
1388
+ return self . get ( href , timeout ) ;
1389
+ } ) ;
1331
1390
} ;
1332
1391
1333
1392
/**
@@ -1349,8 +1408,8 @@ Protractor.prototype.navigate = function() {
1349
1408
*/
1350
1409
Protractor . prototype . setLocation = function ( url ) {
1351
1410
this . waitForAngular ( ) ;
1352
- return this . driver . executeScript ( clientSideScripts . setLocation , this . rootEl , url )
1353
- . then ( function ( browserErr ) {
1411
+ return this . executeScript_ ( clientSideScripts . setLocation ,
1412
+ 'Protractor.setLocation()' , this . rootEl , url ) . then ( function ( browserErr ) {
1354
1413
if ( browserErr ) {
1355
1414
throw 'Error while navigating to \'' + url + '\' : ' +
1356
1415
JSON . stringify ( browserErr ) ;
@@ -1363,7 +1422,8 @@ Protractor.prototype.setLocation = function(url) {
1363
1422
*/
1364
1423
Protractor . prototype . getLocationAbsUrl = function ( ) {
1365
1424
this . waitForAngular ( ) ;
1366
- return this . driver . executeScript ( clientSideScripts . getLocationAbsUrl , this . rootEl ) ;
1425
+ return this . executeScript_ ( clientSideScripts . getLocationAbsUrl ,
1426
+ 'Protractor.getLocationBasUrl()' , this . rootEl ) ;
1367
1427
} ;
1368
1428
1369
1429
/**
0 commit comments