CasperJS實踐筆記(1)

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   使用   ar   for   art   

CasperJS的執行workflow的一個問題(如果可以的話,請不要認為這是一個bug):


虛擬碼如下:

var casper = require("casper").create();casper.start("http://xx.xx.com");casper.then(function(){    this.echo("AAAA");    this.wait(1000, function(){        this.echo("BBB");    })    this.echo("CCCC");});casper.run(){    this.echo("...");};

預期運行結果可以應該是這樣吧:

AAAABBBCCCC...

 

實際運行結果其實這樣:

AAAACCCCBBB...

 

CasperJS本身是一個使用python語言封裝的PhantomJS測試架構,沒有看過它的workflow具體實現;所以只能猜想:

方法casper.then和方法casper.wait組成workflow的邏輯,或者說是workflow執行單元;

而其他代碼不被當作執行單元,所以必須封裝在casper.then或者casper.wait內。

 

casper.wait是一個系列的API,另外還有waitForSelector、waitFor、waitWhileSelector、waitUntilVisible等等;

用的最多的就是this.waitForSelector,設定一個逾時時間等待一個元素(Html element),如果找到了就怎樣/如果逾時就怎樣。

 

所以實際項目中的代碼大約如下:

this.then(function(){    this.echo("start...");    this.waitFor(    /// ...        )    this.waitForSelector(    //    ...        )})this.then(function(){    this.echo("start...");    this.waitFor(    /// ...        this.waitForSelector(    //    ...            )        )})

 

(我的小項目自己一個人寫,很多東西都在摸索階段)

希望有經驗的同仁不吝賜教!

 

CasperJS實踐筆記(1)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.