我在conf.js文件中定义了Jasmine的使用
exports.config = {
framework: 'jasmine',
// Capabilities to be passed to the webdriver instance.
capabilities: {
'browserName': 'chrome',
},
我使用以下代码点击页面上的按钮并检查文字。
element(by.css('.btn.btn-success.btn-lg')).click();
console.log('Wait 2 seconds');
browser.sleep(2000);
console.log('After wait');
// question 1
var expectedString = "Step 1 of 10";
var actualString = element(by.xpath('/html[1]/body[1]/section[1]/app-root[1]/app-pay-only[1]/div[1]/div[1]/h2[1]')).getText().then(function(actualString) {
return actualString;
});
console.log('here\'s the expect');
expect(actualString).toContain(expectedString);
然而,我得到一个失败说“期望不是一个功能”,当我看着测试运行时,我可以看到按钮没有被按下(所以页面不会导航。)如果我注释掉期望,然后页面将正常导航。我看不出为什么点击事件会失败的原因(我甚至会睡觉看看发生了什么)
堆栈跟踪将在下面 - 任何人都可以看到任何有关它的内容吗?
Message:
Failed: expect is not a function
Stack:
TypeError: expect is not a function
at UserContext.<anonymous> (C:\Users\Joseph.Adams\Desktop\protractor\LA1-311\end_to_end.js:78:9)
at C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:112:25
at new ManagedPromise (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:1077:7)
at ControlFlow.promise (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2505:12)
at schedulerExecute (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:95:18)
at TaskQueue.execute_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
at TaskQueue.executeNext_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
at asyncRun (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2974:25)
at C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
at <anonymous>
From: Task: Run it("Must allow working end to end") in control flow
at UserContext.<anonymous> (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:94:19)
at C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:64:48
at ControlFlow.emit (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\events.js:62:21)
at ControlFlow.shutdown_ (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2674:10)
at shutdownTask_.MicroTask (C:\Users\Joseph.Adams\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\promise.js:2599:53)
From asynchronous test:
Error
at Suite.<anonymous> (C:\Users\Joseph.Adams\Desktop\protractor\LA1-311\end_to_end.js:63:5)
at Object.<anonymous> (C:\Users\Joseph.Adams\Desktop\protractor\LA1-311\end_to_end.js:14:1)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
答案 0 :(得分:0)
你获得期望变量的方式是非常不同的。我不确定这是不是问题,但我从未见过这样做过。试试这个:
var expectedString = "Step 1 of 10";
var elem = element(by.xpath('/html[1]/body[1]/section[1]/app-root[1]/app-pay-only[1]/div[1]/div[1]/h2[1]'));
expect(elem.getText()).toContain(expectedString);
答案 1 :(得分:0)
首先,快速尝试如下:
1.在console.log('After wait');
之后评论所有行
2.在最后添加一个新行expect('Test abc').toContain('abc')
,
如果仍然出现同样的错误,
检查整个脚本,找到是否将其他值分配给expect
。
(如expect = xxx或global.expect = xxxx)
如果你没有得到同样的错误,也许你的量角器版本大于3.0(我不记得确切的版本),你必须使用jasmine2,高量角器不支持jasmine1。
通过配置文件中的更改框架轻松验证它jasmine2
exports.config = {
framework: 'jasmine2',
请提供您的package.json,以便我们知道您使用的依赖性及其版本。