Show More
@@ -93,6 +93,88 b' casper.get_cells_length = function () {' | |||
|
93 | 93 | return result; |
|
94 | 94 | }; |
|
95 | 95 | |
|
96 | // Set the text content of a cell. | |
|
97 | casper.set_cell_text = function(index, text){ | |
|
98 | this.evaluate(function (index, text) { | |
|
99 | var cell = IPython.notebook.get_cell(index); | |
|
100 | cell.set_text(text); | |
|
101 | }, index, text); | |
|
102 | }; | |
|
103 | ||
|
104 | // Inserts a cell at the bottom of the notebook | |
|
105 | // Returns the new cell's index. | |
|
106 | casper.insert_cell_at_bottom = function(cell_type){ | |
|
107 | if (cell_type===undefined) { | |
|
108 | cell_type = 'code'; | |
|
109 | } | |
|
110 | ||
|
111 | return this.evaluate(function (cell_type) { | |
|
112 | var cell = IPython.notebook.insert_cell_at_bottom(cell_type); | |
|
113 | return IPython.notebook.find_cell_index(cell); | |
|
114 | }, cell_type); | |
|
115 | }; | |
|
116 | ||
|
117 | // Insert a cell at the bottom of the notebook and set the cells text. | |
|
118 | // Returns the new cell's index. | |
|
119 | casper.append_cell = function(text, cell_type) { | |
|
120 | var index = this.insert_cell_at_bottom(cell_type); | |
|
121 | if (text !== undefined) { | |
|
122 | this.set_cell_text(index, text); | |
|
123 | } | |
|
124 | return index; | |
|
125 | }; | |
|
126 | ||
|
127 | // Asynchronously executes a cell by index. | |
|
128 | // Returns the cell's index. | |
|
129 | casper.execute_cell = function(index){ | |
|
130 | var that = this; | |
|
131 | this.then(function(){ | |
|
132 | that.evaluate(function (index) { | |
|
133 | var cell = IPython.notebook.get_cell(index); | |
|
134 | cell.execute(); | |
|
135 | }, index); | |
|
136 | }); | |
|
137 | return index; | |
|
138 | }; | |
|
139 | ||
|
140 | // Synchronously executes a cell by index. | |
|
141 | // Optionally accepts a then_callback parameter. then_callback will get called | |
|
142 | // when the cell has finished executing. | |
|
143 | // Returns the cell's index. | |
|
144 | casper.execute_cell_then = function(index, then_callback) { | |
|
145 | var return_val = this.execute_cell(index); | |
|
146 | ||
|
147 | this.wait_for_output(index); | |
|
148 | ||
|
149 | var that = this; | |
|
150 | this.then(function(){ | |
|
151 | if (then_callback!==undefined) { | |
|
152 | then_callback.apply(that, [index]); | |
|
153 | } | |
|
154 | }); | |
|
155 | ||
|
156 | return return_val; | |
|
157 | }; | |
|
158 | ||
|
159 | // Utility function that allows us to easily check if an element exists | |
|
160 | // within a cell. Uses JQuery selector to look for the element. | |
|
161 | casper.cell_element_exists = function(index, selector){ | |
|
162 | return casper.evaluate(function (index, selector) { | |
|
163 | var $cell = IPython.notebook.get_cell(index).element; | |
|
164 | return $cell.find(selector).length > 0; | |
|
165 | }, index, selector); | |
|
166 | }; | |
|
167 | ||
|
168 | // Utility function that allows us to execute a jQuery function on an | |
|
169 | // element within a cell. | |
|
170 | casper.cell_element_function = function(index, selector, function_name, function_args){ | |
|
171 | return casper.evaluate(function (index, selector, function_name, function_args) { | |
|
172 | var $cell = IPython.notebook.get_cell(index).element; | |
|
173 | var $el = $cell.find(selector); | |
|
174 | return $el[function_name].apply($el, function_args); | |
|
175 | }, index, selector, function_name, function_args); | |
|
176 | }; | |
|
177 | ||
|
96 | 178 | // Wrap a notebook test to reduce boilerplate. |
|
97 | 179 | casper.notebook_test = function(test) { |
|
98 | 180 | this.open_new_notebook(); |
General Comments 0
You need to be logged in to leave comments.
Login now