我在Windows 8上使用PhantomJS 1.8.1下的CasperJS 1.0.2。網站無法按預期與CasperJS一起工作
試圖編寫網站測試。該網站嚴重依賴JS,編碼原則很不尋常,這可能會造成一些問題,但我不確定。
這裏是我使用的測試登錄和搜索功能的代碼:
var url = 'http://www.testsite.com/';
var casper = require('casper').create();
casper.start();
casper.start(url, function() {
this.echo('Page: ' + this.getTitle());
this.capture('start.png');
if (this.exists('input#TxtUserName')) {
this.sendKeys('input#TxtUserName', 'testlogin');
this.sendKeys('input#TxtPassword', 'testpass');
this.click('input#BtnLogin');
this.capture('loggedin.png');
}
});
casper.then(function() {
this.capture('beforesearch.png');
this.sendKeys("input#txtSearch", '1002');
this.click("input#cmdSubmit");
this.echo('Searching');
this.capture('aftersearch.png');
});
casper.run();
當我運行此代碼,屏幕上的捕捉每一個頁面,不同的是登錄信息被填充相同在login.png上。在點擊事件後,它實際上沒有登錄(使用我的真實登錄憑據)。在點擊被觸發後,搜索結果也不會顯示。
任何線索可能導致這種情況?
這裏提交搜索後,我的WAITFOR代碼:
casper.waitForText("Part:", function() {
this.capture('searchresults.png');
});
沒有關於waitFor編輯。在我進行測試的時候,網站的速度令人難以置信。 – TestyTester 2013-02-21 16:15:38
可能與http://stackoverflow.com/questions/14098483/casperjs-click-event-having-ajax-call/15144137#15144137 看到我的答案那裏,可能會幫助你。 – Leentje 2013-02-28 19:53:06