gpt4 book ai didi

node.js - 使用 Protractor 作为库时“没有期望的方法”

转载 作者:太空宇宙 更新时间:2023-11-03 22:17:31 25 4
gpt4 key购买 nike

使用 Protractor as a library

无法要求引用 Jasmine。引用 expect 方法返回输出 Cannot call method 'expect' of null.

更新代码以反射(reflect)评论:

var protractor = require('protractor');
require('protractor/node_modules/minijasminenode');
require('protractor/jasminewd'); // output: jasmine is undefined (this error can only be seen if the above line is commented out)
//expect(true).toBe(true); // output: Cannot call method 'expect' of null

var driver = new protractor.Builder()
.usingServer('http://localhost:4444/wd/hub')
.withCapabilities(protractor.Capabilities
.chrome()).build();

var ptor = protractor.wrapDriver(driver);

ptor.get('http://www.angularjs.org').then(function(){
ptor.element(protractor.By.model('yourName')).sendKeys('test')
.then(console.log('success')); // output: success
ptor.getCurrentUrl().then(function(url){
console.log(url); // output: http://www.angularjs.org
expect(url).toContain('angular'); // output: Cannot call method 'expect' of null
});
});

参见https://github.com/angular/protractor/issues/21获取相关信息。

最佳答案

每次您进入 jasmine 的 it 函数上下文时,都会重新生成全局 jasmine Expect 函数。

这对您的代码意味着什么?您不能在it函数之外调用expect。

示例:

...
// somewhere in your code
...
// function expect doesn’t exist here
describe( 'your case', function() {
// expect doesn’t exist here either
it( 'should work', function() {
// horray - the global expect is available !!
// note : the expect function is generated before running your callback
// function to collect the expect'ed results for exactly this 'it' case
expect( true).toBe( true);
});
})

关于node.js - 使用 Protractor 作为库时“没有期望的方法”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20979627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com