我已經在Selenium中挖得夠深了,以獲得一個很好的答案。
裝飾Recorder.prototype.attach
和Recorder.prototype.detach
效果很好;您只需將自己附加到window.onerror
活動上即可瞭解您的網頁上發生了哪些不好的事情。當需要對錯誤採取行動時,問題就會出現。有兩種選擇:
- 創建一個自定義命令,用於檢查自上次調用以來是否存在錯誤;
- 編輯Selenium的源代碼,以檢查每個新命令之前最後一個命令是否有錯誤。
由於需要更改行爲的文件在擴展文件後加載,因此不可能使用擴展來實現後者。
這裏是如何從一個用戶擴展裝點相應的功能:
function decorate(decoratee, decorator) {
var decorated = function() {
decorator.apply(this, arguments);
if (decoratee && decoratee.apply)
decoratee.apply(this, arguments);
}
decorated.base = decoratee;
decorated.decorator = decorator;
return decorated;
}
Recorder.prototype.attach = decorate(Recorder.prototype.attach, function() {
var win = this.getWrappedWindow();
win.onerror = decorate(win.onerror, function(message, file, line) {
// do something with the error
});
});
Recorder.prototype.detach = decorate(Recorder.prototype.detach, function() {
var win = this.getWrappedWindow();
win.onerror = win.onerror.base;
});
您可以添加流量控制很容易:http://51elliot.blogspot.com/2008/02/selenium-ide-goto .html – 2011-01-12 15:35:47
@Martin Jespersen謝謝,我不知道。儘管如此,我們使用Selenium IDE來記錄內容,而Selenium RC可以滿足我們所有的流量控制需求。 – zneak 2011-01-12 15:42:10