我正在做一些AngularJS應用程序的測試,我不認爲測試框架在這裏一定很重要,但我想通過一個可選變量。這個變量將指定如果我想要抓住傳遞給函數的ID的子元素通過JavaScript元素作爲變量
commonFunctions.elementDoesNotHaveAttribute('register-0', 'disabled', 'children[0].children[0]');
的children[0].children[0]
是不是一個真正的字符串,如果我刪除引號函數調用失敗,因爲它找不到.children[0]
這裏的子對象是功能
function elementDoesNotHaveAttribute(id, attribute, child) {
var hasElement = false;
hasElement = casper.evaluate(function (id, attribute, child) {
var element = document.getElementById(id);
if (child) {
element = element.child;
}
return element.hasAttribute(attribute);
}, id, attribute, child);
if (hasElement) {
casper.test.fail('element has' + attribute + ' but shouldn\'t');
} else {
casper.test.pass('element didn\'t have ' + attribute + ' and shouldn\'t');
}
}
我怎樣才能改變這些等式的兩邊來結束我的函數中評估element.children[0].children[0]
工作,我過去沒有使用eval() –
@ T.J.Crowder,它採用一個ID,屬性和可選的子元素。它正在檢查該選擇器是否爲通過的屬性 –