migrated evaluate() calls to use phantomjs ones
Showing
2 changed files
with
16 additions
and
29 deletions
... | @@ -222,7 +222,7 @@ Casper.prototype.base64encode = function base64encode(url, method, data) { | ... | @@ -222,7 +222,7 @@ Casper.prototype.base64encode = function base64encode(url, method, data) { |
222 | "use strict"; | 222 | "use strict"; |
223 | return this.evaluate(function _evaluate(url, method, data) { | 223 | return this.evaluate(function _evaluate(url, method, data) { |
224 | return window.__utils__.getBase64(url, method, data); | 224 | return window.__utils__.getBase64(url, method, data); |
225 | }, { url: url, method: method, data: data }); | 225 | }, url, method, data); |
226 | }; | 226 | }; |
227 | 227 | ||
228 | /** | 228 | /** |
... | @@ -579,13 +579,7 @@ Casper.prototype.echo = function echo(text, style, pad) { | ... | @@ -579,13 +579,7 @@ Casper.prototype.echo = function echo(text, style, pad) { |
579 | * document.querySelector('#username').value = username; | 579 | * document.querySelector('#username').value = username; |
580 | * document.querySelector('#password').value = password; | 580 | * document.querySelector('#password').value = password; |
581 | * document.querySelector('#submit').click(); | 581 | * document.querySelector('#submit').click(); |
582 | * }, { | 582 | * }, 'Bazoonga', 'baz00nga'); |
583 | * username: 'Bazoonga', | ||
584 | * password: 'baz00nga' | ||
585 | * }) | ||
586 | * | ||
587 | * FIXME: waiting for a patch of PhantomJS to allow direct passing of | ||
588 | * arguments to the function. | ||
589 | * | 583 | * |
590 | * @param Function fn The function to be evaluated within current page DOM | 584 | * @param Function fn The function to be evaluated within current page DOM |
591 | * @param Object context Object containing the parameters to inject into the function | 585 | * @param Object context Object containing the parameters to inject into the function |
... | @@ -649,7 +643,7 @@ Casper.prototype.exists = function exists(selector) { | ... | @@ -649,7 +643,7 @@ Casper.prototype.exists = function exists(selector) { |
649 | this.checkStarted(); | 643 | this.checkStarted(); |
650 | return this.evaluate(function _evaluate(selector) { | 644 | return this.evaluate(function _evaluate(selector) { |
651 | return window.__utils__.exists(selector); | 645 | return window.__utils__.exists(selector); |
652 | }, { selector: selector }); | 646 | }, selector); |
653 | }; | 647 | }; |
654 | 648 | ||
655 | /** | 649 | /** |
... | @@ -676,7 +670,7 @@ Casper.prototype.fetchText = function fetchText(selector) { | ... | @@ -676,7 +670,7 @@ Casper.prototype.fetchText = function fetchText(selector) { |
676 | this.checkStarted(); | 670 | this.checkStarted(); |
677 | return this.evaluate(function _evaluate(selector) { | 671 | return this.evaluate(function _evaluate(selector) { |
678 | return window.__utils__.fetchText(selector); | 672 | return window.__utils__.fetchText(selector); |
679 | }, { selector: selector }); | 673 | }, selector); |
680 | }; | 674 | }; |
681 | 675 | ||
682 | /** | 676 | /** |
... | @@ -696,10 +690,7 @@ Casper.prototype.fill = function fill(selector, vals, submit) { | ... | @@ -696,10 +690,7 @@ Casper.prototype.fill = function fill(selector, vals, submit) { |
696 | this.emit('fill', selector, vals, submit); | 690 | this.emit('fill', selector, vals, submit); |
697 | var fillResults = this.evaluate(function _evaluate(selector, values) { | 691 | var fillResults = this.evaluate(function _evaluate(selector, values) { |
698 | return window.__utils__.fill(selector, values); | 692 | return window.__utils__.fill(selector, values); |
699 | }, { | 693 | }, selector, vals); |
700 | selector: selector, | ||
701 | values: vals | ||
702 | }); | ||
703 | if (!fillResults) { | 694 | if (!fillResults) { |
704 | throw new CasperError("Unable to fill form"); | 695 | throw new CasperError("Unable to fill form"); |
705 | } else if (fillResults.errors.length > 0) { | 696 | } else if (fillResults.errors.length > 0) { |
... | @@ -733,7 +724,7 @@ Casper.prototype.fill = function fill(selector, vals, submit) { | ... | @@ -733,7 +724,7 @@ Casper.prototype.fill = function fill(selector, vals, submit) { |
733 | // http://www.spiration.co.uk/post/1232/Submit-is-not-a-function | 724 | // http://www.spiration.co.uk/post/1232/Submit-is-not-a-function |
734 | form.submit.click(); | 725 | form.submit.click(); |
735 | } | 726 | } |
736 | }, { selector: selector }); | 727 | }, selector); |
737 | } | 728 | } |
738 | }; | 729 | }; |
739 | 730 | ||
... | @@ -819,7 +810,7 @@ Casper.prototype.getElementAttribute = Casper.prototype.getElementAttr = functio | ... | @@ -819,7 +810,7 @@ Casper.prototype.getElementAttribute = Casper.prototype.getElementAttr = functio |
819 | this.checkStarted(); | 810 | this.checkStarted(); |
820 | return this.evaluate(function _evaluate(selector, attribute) { | 811 | return this.evaluate(function _evaluate(selector, attribute) { |
821 | return document.querySelector(selector).getAttribute(attribute); | 812 | return document.querySelector(selector).getAttribute(attribute); |
822 | }, { selector: selector, attribute: attribute }); | 813 | }, selector, attribute); |
823 | }; | 814 | }; |
824 | 815 | ||
825 | /** | 816 | /** |
... | @@ -836,7 +827,7 @@ Casper.prototype.getElementBounds = function getElementBounds(selector) { | ... | @@ -836,7 +827,7 @@ Casper.prototype.getElementBounds = function getElementBounds(selector) { |
836 | } | 827 | } |
837 | var clipRect = this.evaluate(function _evaluate(selector) { | 828 | var clipRect = this.evaluate(function _evaluate(selector) { |
838 | return window.__utils__.getElementBounds(selector); | 829 | return window.__utils__.getElementBounds(selector); |
839 | }, { selector: selector }); | 830 | }, selector); |
840 | if (!utils.isClipRect(clipRect)) { | 831 | if (!utils.isClipRect(clipRect)) { |
841 | throw new CasperError('Could not fetch boundaries for element matching selector: ' + selector); | 832 | throw new CasperError('Could not fetch boundaries for element matching selector: ' + selector); |
842 | } | 833 | } |
... | @@ -857,7 +848,7 @@ Casper.prototype.getElementsBounds = function getElementBounds(selector) { | ... | @@ -857,7 +848,7 @@ Casper.prototype.getElementsBounds = function getElementBounds(selector) { |
857 | } | 848 | } |
858 | return this.evaluate(function _evaluate(selector) { | 849 | return this.evaluate(function _evaluate(selector) { |
859 | return window.__utils__.getElementsBounds(selector); | 850 | return window.__utils__.getElementsBounds(selector); |
860 | }, { selector: selector }); | 851 | }, selector); |
861 | }; | 852 | }; |
862 | 853 | ||
863 | /** | 854 | /** |
... | @@ -879,16 +870,15 @@ Casper.prototype.getGlobal = function getGlobal(name) { | ... | @@ -879,16 +870,15 @@ Casper.prototype.getGlobal = function getGlobal(name) { |
879 | result.error = message; | 870 | result.error = message; |
880 | } | 871 | } |
881 | return result; | 872 | return result; |
882 | }, {'name': name}); | 873 | }, name); |
883 | if (typeof result !== "object") { | 874 | if (typeof result !== "object") { |
884 | throw new CasperError(f('Could not retrieve global value for "%s"', name)); | 875 | throw new CasperError(f('Could not retrieve global value for "%s"', name)); |
885 | } else if ('error' in result) { | 876 | } else if ('error' in result) { |
886 | throw new CasperError(result.error); | 877 | throw new CasperError(result.error); |
887 | } else if (utils.isString(result.value)) { | 878 | } else if (utils.isString(result.value)) { |
888 | return JSON.parse(result.value); | 879 | return JSON.parse(result.value); |
889 | } else { | ||
890 | return undefined; | ||
891 | } | 880 | } |
881 | return undefined; | ||
892 | }; | 882 | }; |
893 | 883 | ||
894 | /** | 884 | /** |
... | @@ -911,7 +901,7 @@ Casper.prototype.getHTML = function getHTML(selector, outer) { | ... | @@ -911,7 +901,7 @@ Casper.prototype.getHTML = function getHTML(selector, outer) { |
911 | return this.evaluate(function getSelectorHTML(selector, outer) { | 901 | return this.evaluate(function getSelectorHTML(selector, outer) { |
912 | var element = __utils__.findOne(selector); | 902 | var element = __utils__.findOne(selector); |
913 | return outer ? element.outerHTML : element.innerHTML; | 903 | return outer ? element.outerHTML : element.innerHTML; |
914 | }, { selector: selector, outer: !!outer }); | 904 | }, selector, !!outer); |
915 | }; | 905 | }; |
916 | 906 | ||
917 | /** | 907 | /** |
... | @@ -1113,10 +1103,7 @@ Casper.prototype.mouseEvent = function mouseEvent(type, selector) { | ... | @@ -1113,10 +1103,7 @@ Casper.prototype.mouseEvent = function mouseEvent(type, selector) { |
1113 | } | 1103 | } |
1114 | var eventSuccess = this.evaluate(function(type, selector) { | 1104 | var eventSuccess = this.evaluate(function(type, selector) { |
1115 | return window.__utils__.mouseEvent(type, selector); | 1105 | return window.__utils__.mouseEvent(type, selector); |
1116 | }, { | 1106 | }, type, selector); |
1117 | type: type, | ||
1118 | selector: selector | ||
1119 | }); | ||
1120 | if (!eventSuccess) { | 1107 | if (!eventSuccess) { |
1121 | // fallback onto native QtWebKit mouse events | 1108 | // fallback onto native QtWebKit mouse events |
1122 | try { | 1109 | try { |
... | @@ -1561,7 +1548,7 @@ Casper.prototype.visible = function visible(selector) { | ... | @@ -1561,7 +1548,7 @@ Casper.prototype.visible = function visible(selector) { |
1561 | this.checkStarted(); | 1548 | this.checkStarted(); |
1562 | return this.evaluate(function _evaluate(selector) { | 1549 | return this.evaluate(function _evaluate(selector) { |
1563 | return window.__utils__.visible(selector); | 1550 | return window.__utils__.visible(selector); |
1564 | }, { selector: selector }); | 1551 | }, selector); |
1565 | }; | 1552 | }; |
1566 | 1553 | ||
1567 | /** | 1554 | /** | ... | ... |
... | @@ -198,7 +198,7 @@ Tester.prototype.assertNotEquals = function assertNotEquals(subject, shouldnt, m | ... | @@ -198,7 +198,7 @@ Tester.prototype.assertNotEquals = function assertNotEquals(subject, shouldnt, m |
198 | * | 198 | * |
199 | * @param Function fn A function to be evaluated in remote DOM | 199 | * @param Function fn A function to be evaluated in remote DOM |
200 | * @param String message Test description | 200 | * @param String message Test description |
201 | * @param Object params Object containing the parameters to inject into the function (optional) | 201 | * @param Object params Object/Array containing the parameters to inject into the function (optional) |
202 | * @return Object An assertion result object | 202 | * @return Object An assertion result object |
203 | */ | 203 | */ |
204 | Tester.prototype.assertEval = Tester.prototype.assertEvaluate = function assertEval(fn, message, params) { | 204 | Tester.prototype.assertEval = Tester.prototype.assertEvaluate = function assertEval(fn, message, params) { |
... | @@ -250,7 +250,7 @@ Tester.prototype.assertField = function assertField(inputName, expected, messag | ... | @@ -250,7 +250,7 @@ Tester.prototype.assertField = function assertField(inputName, expected, messag |
250 | "use strict"; | 250 | "use strict"; |
251 | var actual = this.casper.evaluate(function(inputName) { | 251 | var actual = this.casper.evaluate(function(inputName) { |
252 | return __utils__.getFieldValue(inputName); | 252 | return __utils__.getFieldValue(inputName); |
253 | }, { inputName: inputName }); | 253 | }, inputName); |
254 | return this.assert(this.testEquals(actual, expected), message, { | 254 | return this.assert(this.testEquals(actual, expected), message, { |
255 | type: 'assertField', | 255 | type: 'assertField', |
256 | standard: f('"%s" input field has the value "%s"', inputName, expected), | 256 | standard: f('"%s" input field has the value "%s"', inputName, expected), | ... | ... |
-
Please register or sign in to post a comment