@@ -734,6 +734,103 @@ casper.dashboard_test = function (test) {
734
734
} ) ;
735
735
} ;
736
736
737
+ /**
738
+ * Editor Tests
739
+ *
740
+ * The functions below are utilities for setting up an editor and tearing it down
741
+ * after the test is over.
742
+ */
743
+ caspser . open_new_file = function ( ) {
744
+ // load up the jupyter notebook server (it's like running `jupyter notebook` in the shell)
745
+ var baseUrl = this . get_notebook_server ( ) ;
746
+
747
+ // go to the base url, wait for it to load, then make a new file
748
+ this . start ( baseUrl ) ;
749
+ this . waitFor ( this . page_loaded ) ;
750
+ this . waitForSelector ( '#new-file a' ) ;
751
+ this . thenClick ( '#new-file a' ) ;
752
+
753
+ // when the popup loads, go into that popup and wait until the main text box is loaded
754
+ this . withPopup ( 0 , function ( ) { this . waitForSelector ( '.CodeMirror-sizer' ) ; } ) ;
755
+
756
+ // now let's open the window where the file editor is displayed & load
757
+ this . then ( function ( ) {
758
+ this . open ( this . popups [ 0 ] . url ) ;
759
+ } ) ;
760
+ this . waitFor ( this . page_loaded ) ;
761
+
762
+ // Hook the log and error methods of the console, forcing them to
763
+ // serialize their arguments before printing. This allows the
764
+ // Objects to cross into the phantom/slimer regime for display.
765
+ this . thenEvaluate ( function ( ) {
766
+ var serialize_arguments = function ( f , context ) {
767
+ return function ( ) {
768
+ var pretty_arguments = [ ] ;
769
+ for ( var i = 0 ; i < arguments . length ; i ++ ) {
770
+ var value = arguments [ i ] ;
771
+ if ( value instanceof Object ) {
772
+ var name = value . name || 'Object' ;
773
+ // Print a JSON string representation of the object.
774
+ // If we don't do this, [Object object] gets printed
775
+ // by casper, which is useless. The long regular
776
+ // expression reduces the verbosity of the JSON.
777
+ pretty_arguments . push ( name + ' {' + JSON . stringify ( value , null , ' ' )
778
+ . replace ( / ( \s + ) ? ( { ) ? ( \s + ) ? ( } ( \s + ) ? , ? ) ? ( \s + ) ? ( \s + ) ? \n / g, '\n' )
779
+ . replace ( / \n ( \s + ) ? \n / g, '\n' ) ) ;
780
+ } else {
781
+ pretty_arguments . push ( value ) ;
782
+ }
783
+ }
784
+ f . apply ( context , pretty_arguments ) ;
785
+ } ;
786
+ } ;
787
+ console . log = serialize_arguments ( console . log , console ) ;
788
+ console . error = serialize_arguments ( console . error , console ) ;
789
+ } ) ;
790
+
791
+ console . log ( 'Editor loaded.' )
792
+
793
+ }
794
+
795
+ casper . editor_test = function ( test ) {
796
+ // Wrap a notebook test to reduce boilerplate.
797
+ this . open_new_file ( ) ;
798
+
799
+ // Echo whether or not we are running this test using SlimerJS
800
+ if ( this . evaluate ( function ( ) {
801
+ return typeof InstallTrigger !== 'undefined' ; // Firefox 1.0+
802
+ } ) ) {
803
+ console . log ( 'This test is running in SlimerJS.' ) ;
804
+ this . slimerjs = true ;
805
+ }
806
+
807
+ // Make sure to remove the onbeforeunload callback. This callback is
808
+ // responsible for the "Are you sure you want to quit?" type messages.
809
+ // PhantomJS ignores these prompts, SlimerJS does not which causes hangs.
810
+ this . then ( function ( ) {
811
+ this . evaluate ( function ( ) {
812
+ window . onbeforeunload = function ( ) { } ;
813
+ } ) ;
814
+ } ) ;
815
+
816
+ this . then ( test ) ;
817
+
818
+ // This is required to clean up the page we just finished with. If we don't call this
819
+ // casperjs will leak file descriptors of all the open WebSockets in that page. We
820
+ // have to set this.page=null so that next time casper.start runs, it will create a
821
+ // new page from scratch.
822
+ this . then ( function ( ) {
823
+ this . page . close ( ) ;
824
+ this . page = null ;
825
+ } ) ;
826
+
827
+ // Run the browser automation.
828
+ this . run ( function ( ) {
829
+ this . test . done ( ) ;
830
+ } ) ;
831
+ } ;
832
+
833
+
737
834
// note that this will only work for UNIQUE events -- if you want to
738
835
// listen for the same event twice, this will not work!
739
836
casper . event_test = function ( name , events , action , timeout ) {
0 commit comments