標籤:android style blog http color io os 使用 ar
casperJS的測試module
casper.test.begin執行一串完整的測試動作,不過其中的對象this並非capser而是test!
只不過test對象本身具備casper的attribute,另外還有test module提供的attribute(提供了測試相關的諸多API)。
casper對象有很多很多options,下面說說這些options的設定,options允許我們設定一些預設值、userAgent、定製功能、等等。
舉例如下:
casper.options.pageSettings = { loadImages: true, loadPlugins: true, userAgent: ‘Mozilla/5.0 (Linux; U; Android 4.3; en-us; SM-N900T Build/JSS15J) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30‘ };casper.options.verbose = true;casper.options.logLevel = "debug";casper.on("page.error", function(_err, _trace){ this.log(_err, "error");});casper.on("remote.message", function(_msg){ this.log(_msg, "warning");});
比如logLevel用來設定log等級,有4個值:debug,info,warning,error;
比如使用on監聽事件"page.error",可用抓取js指令碼錯誤;
關於Http請求的響應也有辦法處理,而且還有兩個辦法,代碼如下:
casper.on("http.status.400", function(_resource){ this.log("Remote http.status.400 occur.", "error"); this.log(_resource.url, "error");});casper.options.httpStatusHandlers = { 400: function(self, _resource){ this.log(casper._Impor_msg_str1, "error"); this.log("Remote http.status.400 occur.", "error"); this.log(_resource.url, "error"); this.log(casper._Impor_msg_str2, "error"); }};
代碼執行過程中,肯定需要output一下資訊,才好嘛;有三種方式:casper.echo,casper.log,test.info
其中test.info帶一個參數,就是“想說的話”;
而casper.echo可以帶2個參數:“想說的話”和“重要層級”(debug,info,warning,error);
casper.log則可以帶3個參數:“想說的話”、“重要層級”、“來源”(phantom or casper);
好了,感覺自己很慷慨~~~
CasperJS實踐筆記(4)