在 Sencha 测试中的预期中使用 hasCls 时出错
Error using hasCls within an expect in Sencha Test
煎茶测试 2.1
是否存在关于在 expect 中使用 hasCls 的错误?
假设我有类似的东西:
this.component().gotoButton('[text=See]').gotoComponent('menucheckitem[text=some text]')
.and(function (el) {
el.hasCls('x-menu-item-checked'); //this works correctly, validates the el has the class and returns a timeout if the el doesn't actually have the class
expect(el.hasCls('x-menu-item-checked')).toBe(true); // but doing this throws a nasty error, see the detail below
});
(虽然在这种情况下它是一个组件而不是元素,元素也会发生同样的事情)
所以我尝试引用不同的元素并且我总是尝试这样做:
expect(el.hasClass('some')).toBe(true);
我收到此错误,想知道我是否遗漏了什么或者这是一个错误。
我在文档中看到这应该是可行的。 http://docs.sencha.com/sencha_test/2.1.0/api/ST.future.Element.html?#method-and
Expected constructor({ context: constructor({ breakOnFailure: false,
evaluateTestsOnReady: true, eventDelay: 500, eventTranslation: true,
failOnMultipleMatches: true, globals: Object({ speechSynthesis: true,
caches: true, localStorage: true, sessionStorage: true,
webkitStorageInfo: true, indexedDB: true, webkitIndexedDB: true,
ondeviceorientationabsolute: true, ondeviceorientation: true,
ondevicemotion: true, crypto: true, postMessage: true, blur: true,
focus: true, close: true, stop: true, open: true, alert: true,
applicationCache: true, performance: true, confirm: true, onunload:
true, onunhandledrejection: true, onstorage: true, prompt: true,
onrejectionhandled: true, onpopstate: true, onpageshow: true, print:
true, onpagehide: true, ononline: true, onoffline: true,
requestAnimationFrame: true, onmessage: true, onlanguagechange: true,
onhashchange: true, cancelAnimationFrame: true, onbeforeunload: true,
onwaiting: true, onvolumechange: true, captureEvents: true, ontoggle:
true, ontimeupdate: true, onsuspend: true, releaseEvents: true,
onsubmit: true, onstalled: true, onshow: true, getComputedStyle: true,
onselect: true, onseeking: true, onseeked: true, matchMedia: true,
onscroll: true, onresize: true, moveTo: true, onreset: true,
onratechange: true, onprogress: true, moveBy: true, onplaying: true,
onplay: true, onpause: true, onmousewheel: true, resizeTo: true,
onmouseup: true, onmouseover: true, resizeBy: true, onmouseout: true,
onmousemove: true, onmouseleave: true, onmouseenter: true,
getSelection: true, onmousedown: true, onloadstart: true,
onloadedmetadata: true, find: true, onloadeddata: true, onload: true,
getMatchedCSSRules: true, onkeyup: true, onkeypress: true, onkeydown:
true, webkitRequestAnimationFrame: true, oninvalid: true, oninput:
true, onfocus: true, onerror: true, webkitCancelAnimationFrame: true,
onended: true, onemptied: true, webkitCancelRequestAnimationFrame:
true, onduratio ...
对于浏览器内场景,是的,这绝对有效。但是,我怀疑您使用的是基于 WebDriver 的场景。在这些场景类型中,传递给 and() 的参数不是组件或元素实例(因为您永远无法访问基于 WebDriver 场景的规范中的那些),而是未来本身:
Per the docs for and(): "If the scenario is a WebDriver scenario the arg will >be the current future"
所以在这个例子中,你对 "el.hasCls(...)" 的第一次调用是调用组件未来的 hasCls 方法,return 是未来本身。
这解释了为什么 expect() 失败,因为 ST.future.Component.hasCls() 不是 return 布尔值,而是未来的实例:
http://docs.sencha.com/sencha_test/2.1.0/api/ST.future.Element.html#method-hasCls
在这个特定的用例中,您实际上不需要 expect(),因为未来的 hasCls() 方法起作用作为对未来组件 class 存在的默认断言。
煎茶测试 2.1
是否存在关于在 expect 中使用 hasCls 的错误?
假设我有类似的东西:
this.component().gotoButton('[text=See]').gotoComponent('menucheckitem[text=some text]')
.and(function (el) {
el.hasCls('x-menu-item-checked'); //this works correctly, validates the el has the class and returns a timeout if the el doesn't actually have the class
expect(el.hasCls('x-menu-item-checked')).toBe(true); // but doing this throws a nasty error, see the detail below
});
(虽然在这种情况下它是一个组件而不是元素,元素也会发生同样的事情)
所以我尝试引用不同的元素并且我总是尝试这样做:
expect(el.hasClass('some')).toBe(true);
我收到此错误,想知道我是否遗漏了什么或者这是一个错误。
我在文档中看到这应该是可行的。 http://docs.sencha.com/sencha_test/2.1.0/api/ST.future.Element.html?#method-and
Expected constructor({ context: constructor({ breakOnFailure: false, evaluateTestsOnReady: true, eventDelay: 500, eventTranslation: true, failOnMultipleMatches: true, globals: Object({ speechSynthesis: true, caches: true, localStorage: true, sessionStorage: true, webkitStorageInfo: true, indexedDB: true, webkitIndexedDB: true, ondeviceorientationabsolute: true, ondeviceorientation: true, ondevicemotion: true, crypto: true, postMessage: true, blur: true, focus: true, close: true, stop: true, open: true, alert: true, applicationCache: true, performance: true, confirm: true, onunload: true, onunhandledrejection: true, onstorage: true, prompt: true, onrejectionhandled: true, onpopstate: true, onpageshow: true, print: true, onpagehide: true, ononline: true, onoffline: true, requestAnimationFrame: true, onmessage: true, onlanguagechange: true, onhashchange: true, cancelAnimationFrame: true, onbeforeunload: true, onwaiting: true, onvolumechange: true, captureEvents: true, ontoggle: true, ontimeupdate: true, onsuspend: true, releaseEvents: true, onsubmit: true, onstalled: true, onshow: true, getComputedStyle: true, onselect: true, onseeking: true, onseeked: true, matchMedia: true, onscroll: true, onresize: true, moveTo: true, onreset: true, onratechange: true, onprogress: true, moveBy: true, onplaying: true, onplay: true, onpause: true, onmousewheel: true, resizeTo: true, onmouseup: true, onmouseover: true, resizeBy: true, onmouseout: true, onmousemove: true, onmouseleave: true, onmouseenter: true, getSelection: true, onmousedown: true, onloadstart: true, onloadedmetadata: true, find: true, onloadeddata: true, onload: true, getMatchedCSSRules: true, onkeyup: true, onkeypress: true, onkeydown: true, webkitRequestAnimationFrame: true, oninvalid: true, oninput: true, onfocus: true, onerror: true, webkitCancelAnimationFrame: true, onended: true, onemptied: true, webkitCancelRequestAnimationFrame: true, onduratio ...
对于浏览器内场景,是的,这绝对有效。但是,我怀疑您使用的是基于 WebDriver 的场景。在这些场景类型中,传递给 and() 的参数不是组件或元素实例(因为您永远无法访问基于 WebDriver 场景的规范中的那些),而是未来本身:
Per the docs for and(): "If the scenario is a WebDriver scenario the arg will >be the current future"
所以在这个例子中,你对 "el.hasCls(...)" 的第一次调用是调用组件未来的 hasCls 方法,return 是未来本身。
这解释了为什么 expect() 失败,因为 ST.future.Component.hasCls() 不是 return 布尔值,而是未来的实例:
http://docs.sencha.com/sencha_test/2.1.0/api/ST.future.Element.html#method-hasCls
在这个特定的用例中,您实际上不需要 expect(),因为未来的 hasCls() 方法起作用作为对未来组件 class 存在的默认断言。