早上好亲爱的同事们。
我对 Selenium 方法有疑问。
在我的例子中,我正在使用 Protractor 测试 Angular 应用程序,我想将 getSize
函数的返回值与我的测试中的设置值进行比较。这是下面的代码-
var searchForm = element(by.id('search'));
it('searchForm must have width: 400px and height: 400px', function(){
//expect(browser.driver.manager().window().getSize()).toEqual(400, 400);
searchForm.getSize();
searchForm.width.toEqual(400);
searchForm.height.toEqual(400);
});
麻烦帮我解决一下。我希望你能帮助我。
最佳答案
Protractor getSize()
函数返回一个包含指定元素的 width、height、hcode 和 class
的维度对象的 promise 。等到 promise 被返回,然后 resolve promise 以获取元素的尺寸。方法如下 -
it('searchForm must have width: 400px and height: 400px', function(){
var searchForm = element(by.id('search'));
searchForm.getSize().then(function(eleSize){
console.log('element size: '+eleSize); //eleSize is the element's size object
expect(eleSize.width).toEqual(400);
expect(eleSize.height).toEqual(400);
});
});
此外,不建议使用 jasmine 在自动化中编写规范 it
之外的任何内容。希望对您有所帮助。
关于javascript - 如何使用 Protractor 测试比较具有 getSize() 函数的元素的宽度和高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32964939/