在量角器和打字稿中使用jasmine框架,即使实际和期望值相等,也会在expect语句中得到错误,请指导哪里出错。
错误我正在
Failures:
1) Protractor Demo App should add correctly
Message:
Expected '3' to equal 3.
Stack:
Error: Failed expectation
at Object.<anonymous> (C:\MyFiles\NewTechonologies\Protractor\TypeScript\Test\calc.ts:27:34)
at C:\Users\skp\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:112:25
at new ManagedPromise (C:\Users\skp\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-we
bdriver\lib\promise.js:1067:7)
at ControlFlow.promise (C:\Users\skp\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-w
ebdriver\lib\promise.js:2396:12)
at schedulerExecute (C:\Users\skp\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\in
dex.js:95:18)
at TaskQueue.execute_ (C:\Users\skp\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-we
bdriver\lib\promise.js:2970:14)
这是我的spec.ts文件
import {browser, element, by, By, $, $$, ExpectedConditions} from 'protractor';
import protractor = require('protractor');
describe('Protractor Demo App', function() {
var firstNumber = element(by.model('first'));
var secondNumber = element(by.model('second'));
var goButton = element(by.id('gobutton'));
let value = element(by.xpath("//*[@class='table']/tbody//tr[1]/td[3]"));
function add(a, b) {
firstNumber.sendKeys(a);
secondNumber.sendKeys(b);
goButton.click();
}
beforeEach(function() {
browser.get('http://juliemr.github.io/protractor-demo/');
});
it('should add correctly', function() {
add(1, 2);
browser.sleep(3000);
expect<any>(value.getText()).toEqual(3);
})
});
答案 0 :(得分:0)
getText()会返回string
,因此您的expect
失败,因为它们具有相同的值,但类型不同。
您可以更改断言以检查字符串值:
expect(value.getText()).toEqual('3');
,或者您可以从getText()
承诺返回值,并使用parseInt()将字符串更改为数字。