Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium getSize()属性无法使用角度2 Go量角器访问_Selenium_Angular_Protractor - Fatal编程技术网

Selenium getSize()属性无法使用角度2 Go量角器访问

Selenium getSize()属性无法使用角度2 Go量角器访问,selenium,angular,protractor,Selenium,Angular,Protractor,我一直在使用配置来尝试在Angular 2上运行端到端测试 当尝试获取元素的大小时,其属性是不可遍历的。例如: var myElement = element(by.css('.my-element')).getSize(); 在browser.pause调试控制台中,将显示: { ceil: {}, clone: {}, floor: {}, height: 52, round: {}, scale: {}, toString: {}, width: 612 }

我一直在使用配置来尝试在Angular 2上运行端到端测试

当尝试获取元素的大小时,其属性是不可遍历的。例如:

var myElement = element(by.css('.my-element')).getSize();
在browser.pause调试控制台中,将显示:

{ ceil: {},
  clone: {},
  floor: {},
  height: 52,
  round: {},
  scale: {},
  toString: {},
  width: 612 }
但当我尝试执行myElementWidth=elementby.css'.my element'.getSize.width时,它将显示为未定义。myElementWidth=elementby.css'.my element'.getSize.getWidth类似地抱怨getWidth不是函数。对getSize返回的对象执行console.log似乎会返回原始元素,而不是我试图检索的size对象。

因为所有特定于WebDriver的方法都会返回承诺。要获得实际大小对象,请首先解析承诺:

element(by.css('.my-element')).getSize().then(function (size) {
    console.log(size);
    console.log(size.width);
});
但是,如果您需要做出期望,expect能够理解承诺并明确地解决它们。换句话说,你可以写:

expect(element(by.css('.my-element')).getSize()).toEqual(jasmine.objectContaining({
    width: 50,
    height: 20
});