我正在做一些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,属性和可选的子元素。它正在检查该选择器是否为通过的属性 –