envjs

用Java(JUnit4)对JavaScript(含Ajax)脚本进行单元测试

僤鯓⒐⒋嵵緔 提交于 2020-04-07 08:40:16
一、背景 因为原来采用过Rhino(JS解析引擎,新版JDK中也默认包含另外一个解析引擎)来在Java环境中解析JavaScript并运行其中的方法。最近看到有人在问题里提问,模拟Ajax请求的问题。所以就想看看有没有方法通过Rhino来实现Ajax请求的模拟。 二、分析 通过上网检索,发现可以采用Envjs,一个纯js方式在无浏览器环境下模拟浏览器的行为,并且与Rhino有集成。这样我就可以实现用Java来处理孤立js中的Ajax请求。 三、开发 1、项目目录结构 main中my.js为要测试的JavaScript,jquery-1.9.1.js为依赖。 test中AjaxTest.java为单元测试类,test.html为测试页面,env.rhino.1.2.js为Envjs依赖。 2、my.js(Jquery的ajax) function myFunction(id) { $.ajax({ url:"/ajaxservice", type:"POST", data:{id:id}, dataType:"json", success:function (msg) { $("#log").text(msg.name); } }); } 这个myFunction实际上就是调用了Jquery的ajax来请求ajaxservice

Anchor element's pathname returns undefined in Rhino with env.js

拥有回忆 提交于 2019-12-06 11:10:56
问题 I have run into an issue that I believe is rooted in the implementation of anchor tags in Rhino. Although I am utilizing env.js, I suspect perhaps I am not configuring something correctly. In particular, my issue occurs while I am attempting to write unit tests against code written for an angularjs application. When I include angular.js (versions 1.2.1 to present), I get the following error: TypeError: Cannot call method "charAt" of undefined I am convinced the error is the result of this

Anchor element's pathname returns undefined in Rhino with env.js

心不动则不痛 提交于 2019-12-04 17:16:31
I have run into an issue that I believe is rooted in the implementation of anchor tags in Rhino. Although I am utilizing env.js , I suspect perhaps I am not configuring something correctly. In particular, my issue occurs while I am attempting to write unit tests against code written for an angularjs application. When I include angular.js (versions 1.2.1 to present), I get the following error: TypeError: Cannot call method "charAt" of undefined I am convinced the error is the result of this call to urlParsingNode.pathname since a console.log call reveals that the pathname object is undefined. I

Python httplib and POST

元气小坏坏 提交于 2019-12-04 11:44:38
问题 I am currently working with a piece of code that has been written by somebody else. It uses httplib to make requests to server. It has all the data supplied in a correct format - for example message body, header values, etc. The problem is that each time it attempts to send a POST requests, the data is there - I can see it on the client side, however nothing arrives to the server. I've read through the library specification and the usage seems to be correct. The extracted library calls go as

EnvJS/Rhino, setTimeout() not working

我怕爱的太早我们不能终老 提交于 2019-12-02 15:21:55
问题 I currently set up EnvJS on my system (installed from here). My end goal is to load a page let it's javascript process for a few seconds, and then read the dom to get the information of interest. However I can not get setTimeout() to work to save my life (Or JQuery for that matter). I have a php script that starts the process: ... $ENVJS_PATH = "/var/www/project/src/envjs"; $RHINO_JAR = "rhino/js.jar"; $INIT_SCRIPT = "init.js"; $output = shell_exec("java -jar $ENVJS_PATH/$RHINO_JAR -opt -1

Load a DOM and Execute javascript, server side, with .Net

烈酒焚心 提交于 2019-11-27 04:42:08
I would like to load a DOM using a document (in string form) or a URL, and then Execute javascript functions (including jquery selectors) against it. This would be totally server side, in process, no client/browser. Basically I need to load the dom and then use jquery selectors and text() & type val() functions to extract strings from it. I don't really need to manipulate the dom. I have looked at .Net javascript engines such as Jurassic and Jint, but neither support loading a DOM, and so therefore can't do what I need. I would be willing to consider non .Net solutions (node.js, ruby, etc) if

Load a DOM and Execute javascript, server side, with .Net

我怕爱的太早我们不能终老 提交于 2019-11-26 11:19:01
问题 I would like to load a DOM using a document (in string form) or a URL, and then Execute javascript functions (including jquery selectors) against it. This would be totally server side, in process, no client/browser. Basically I need to load the dom and then use jquery selectors and text() & type val() functions to extract strings from it. I don\'t really need to manipulate the dom. I have looked at .Net javascript engines such as Jurassic and Jint, but neither support loading a DOM, and so