This repository was archived by the owner on Jul 29, 2024. It is now read-only.
File tree 3 files changed +91
-0
lines changed
3 files changed +91
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Examples of tests to show how debugging works with Protractor. Tests
2
+ // should be run against the testapp.
3
+
4
+ exports . config = {
5
+ seleniumAddress : 'http://localhost:4444/wd/hub' ,
6
+
7
+ // Spec patterns are relative to the current working directly when
8
+ // protractor is called.
9
+ specs : [
10
+ 'debugging/failure_spec.js' ,
11
+ ] ,
12
+
13
+ capabilities : {
14
+ 'browserName' : 'chrome'
15
+ } ,
16
+
17
+ baseUrl : 'http://localhost:8000' ,
18
+
19
+ // ----- Options to be passed to minijasminenode.
20
+ jasmineNodeOpts : {
21
+ onComplete : null ,
22
+ isVerbose : false ,
23
+ showColors : true ,
24
+ includeStackTrace : true
25
+ }
26
+ } ;
Original file line number Diff line number Diff line change
1
+ var webdriver = require ( 'selenium-webdriver' ) ;
2
+
3
+
4
+ describe ( 'modes of failure' , function ( ) {
5
+ ptor = protractor . getInstance ( ) ;
6
+
7
+ it ( 'should fail to find a non-existent element' , function ( ) {
8
+ ptor . get ( 'app/index.html#/form' ) ;
9
+
10
+ // Run this statement before the line which fails. If protractor is run
11
+ // with the debugger (protractor debug debugging/conf.js), the test
12
+ // will pause after loading the webpage but before trying to find the
13
+ // element.
14
+ ptor . debugger ( ) ;
15
+
16
+ // This element doesn't exist, so this fails.
17
+ var nonExistant = ptor . findElement ( protractor . By . binding ( 'nopenopenope' ) ) ;
18
+ } ) ;
19
+
20
+ it ( 'should fail to use protractor on a non-Angular site' , function ( ) {
21
+ ptor . get ( 'http://www.google.com' ) ;
22
+ } ) ;
23
+
24
+ it ( 'should fail an assertion' , function ( ) {
25
+ ptor . get ( 'app/index.html#/form' ) ;
26
+
27
+ var greeting = ptor . findElement ( protractor . By . binding ( '{{greeting}}' ) ) ;
28
+
29
+ expect ( greeting . getText ( ) ) . toEqual ( 'This is not what it equals' ) ;
30
+ } ) ;
31
+ } ) ;
Original file line number Diff line number Diff line change @@ -401,6 +401,40 @@ Protractor.prototype.get = function(destination) {
401
401
} , this . moduleNames_ ) ;
402
402
} ;
403
403
404
+ /**
405
+ * Pauses the test and injects some helper functions into the browser, so that
406
+ * debugging may be done in the browser console.
407
+ *
408
+ * This should be used under node in debug mode, i.e. with
409
+ * protractor debug <configuration.js>
410
+ *
411
+ * While in the debugger, commands can be scheduled through webdriver by
412
+ * entering the repl:
413
+ * debug> repl
414
+ * Press Ctrl + C to leave rdebug repl
415
+ * > ptor.findElement(protractor.By.input('user').sendKeys('Laura'));
416
+ * > ptor.debugger();
417
+ * debug> c
418
+ *
419
+ * This will run the sendKeys command as the next task, then re-enter the
420
+ * debugger.
421
+ */
422
+ Protractor . prototype . debugger = function ( ) {
423
+ var clientSideScriptsList = [ ] ;
424
+ for ( script in clientSideScripts ) {
425
+ clientSideScriptsList . push (
426
+ script + ': ' + clientSideScripts [ script ] . toString ( ) ) ;
427
+ }
428
+
429
+ this . driver . executeScript (
430
+ 'window.clientSideScripts = {' + clientSideScriptsList . join ( ', ' ) + '}' )
431
+
432
+ var flow = webdriver . promise . controlFlow ( ) ;
433
+ flow . execute ( function ( ) {
434
+ debugger ;
435
+ } ) ;
436
+ } ;
437
+
404
438
/**
405
439
* Create a new instance of Protractor by wrapping a webdriver instance.
406
440
*
You can’t perform that action at this time.
0 commit comments