我正在使用量角器为AngularJS编写的应用程序编写一些e2e测试,我想执行以下任务:
element(by.id('btn1')).click().then(function() {
// I want to get the element that I just clicked, and check its label
// How I can pass (if possible) the element to the then() function?
});
目前我所做的是:
element(by.id('btn1')).click().then(function() {
expect(element(by.id('btn1')).getText()).toBe('cancel');
});
提前致谢, 启
答案 0 :(得分:1)
问题是,click()
承诺的类型为webdriver.promise.Promise.<void>
,因此没有任何内容传递给解析器。
只需将元素引用存储在变量中即可重复使用
var btn = element(by.id('btn1'));
btn.click().then(function() {
expect(btn.getText()).toEqual('cancel');
});