是否可以不使用延续来编写这些 Protractor 期望值?
Is it possible to write these Protractor expectations using no continuations?
使用 protractor
和 jasmine(wd)
我们要检查网页上的 table 是否包含预期值。我们使用 CSS 选择器从页面中获取 table:
var table = element(by.css('table#forderungenTable')).all(by.tagName('tr'));
然后我们设定我们的期望:
table.then(function(forderungen){
...
forderungen[2].all(by.tagName('td')).then(function(columns){
expect(columns[1].getText()).toEqual('1');
expect(columns[5].getText()).toEqual('CHF 277.00');
});
});
是否可以更改此代码,以便我们不必将函数传递给 then
,就像使用 jasminewd
意味着我们不必这样做一样?请参阅 this page,其中指出:
Protractor uses jasminewd, which wraps around jasmine's expect so that you can write:
expect(el.getText()).toBe('Hello, World!')
Instead of:
el.getText().then(function(text) {
expect(text).toBe('Hello, World!');
});
我知道我可以用类似于 jasminewd
的方式编写自己的函数,但我想知道是否有更好的方法来使用 [=14] 中已有的结构来构建此类期望=] 或 jasminewd
.
您实际上可以在 ElementArrayFinder
:
上调用 getText()
var texts = element(by.css('table#forderungenTable')).all(by.tagName('tr')).get(2).all(by.tagName('td'));
expect(texts).toEqual(["text1", "text2", "text3"]);
使用 protractor
和 jasmine(wd)
我们要检查网页上的 table 是否包含预期值。我们使用 CSS 选择器从页面中获取 table:
var table = element(by.css('table#forderungenTable')).all(by.tagName('tr'));
然后我们设定我们的期望:
table.then(function(forderungen){
...
forderungen[2].all(by.tagName('td')).then(function(columns){
expect(columns[1].getText()).toEqual('1');
expect(columns[5].getText()).toEqual('CHF 277.00');
});
});
是否可以更改此代码,以便我们不必将函数传递给 then
,就像使用 jasminewd
意味着我们不必这样做一样?请参阅 this page,其中指出:
Protractor uses jasminewd, which wraps around jasmine's expect so that you can write:
expect(el.getText()).toBe('Hello, World!')
Instead of:
el.getText().then(function(text) {
expect(text).toBe('Hello, World!');
});
我知道我可以用类似于 jasminewd
的方式编写自己的函数,但我想知道是否有更好的方法来使用 [=14] 中已有的结构来构建此类期望=] 或 jasminewd
.
您实际上可以在 ElementArrayFinder
:
getText()
var texts = element(by.css('table#forderungenTable')).all(by.tagName('tr')).get(2).all(by.tagName('td'));
expect(texts).toEqual(["text1", "text2", "text3"]);