最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to compare width and height of element with getSize() function with Protractor test? - Stack Overflow

programmeradmin3浏览0评论

Good morning dear colleagues. I have a question about Selenium methods. In my case I'm testing angular application with protractor and I want to pare returns value from getSize function with set values in the my test. Here is code below -

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);

});

please help me to solve trouble. I hope you will help me.

Good morning dear colleagues. I have a question about Selenium methods. In my case I'm testing angular application with protractor and I want to pare returns value from getSize function with set values in the my test. Here is code below -

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);

});

please help me to solve trouble. I hope you will help me.

Share Improve this question edited Oct 6, 2015 at 8:55 giri-sh 6,9622 gold badges27 silver badges50 bronze badges asked Oct 6, 2015 at 8:16 MaksimMaksim 1551 gold badge2 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 12

Protractor getSize() function returns a promise with the dimensions object containing width, height, hcode and class of the element specified. Wait until the promise is returned and then resolve the promise to get the dimensions of the element. Here's how -

 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);
    });
});

Also it is not remended to write anything outside a spec it in automation using jasmine. Hope it helps.

There's a usefull method for all kind of element attributes:

var elemHeight = element.getAttribute('height')

it returns a promise for the element's attribute, so you can use

elemHeight.then(function (height) {...

or just expect(elemHeight).toEqual(400); in your case

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论