Protractor 我们如何在每个描述块中使用之前和之后的量角器钩子来打开和关闭浏览器
我已经使用了以下内容,但我发现此驱动程序实例没有有效的会话ID(您是否调用了WebDriver.quit()?),可能不再使用。有人能帮忙吗 Sample.js文件,其代码如下:Protractor 我们如何在每个描述块中使用之前和之后的量角器钩子来打开和关闭浏览器,protractor,Protractor,我已经使用了以下内容,但我发现此驱动程序实例没有有效的会话ID(您是否调用了WebDriver.quit()?),可能不再使用。有人能帮忙吗 Sample.js文件,其代码如下: describe('angularjs homepage', function() { beforeAll(function(){ browser.get('https://xxxx/'); console.log('calling before all'); })
describe('angularjs homepage', function() {
beforeAll(function(){
browser.get('https://xxxx/');
console.log('calling before all');
});
afterAll(function(done){
console.log('calling after all');
browser.quit();
process.nextTick(done);
});
describe('angularjs homepage', function() {
beforeAll(function(){
browser.get('https://xxxx/');
console.log('calling before all');
});
afterAll(function(done){
console.log('calling after all');
browser.quit();
process.nextTick(done);
});
另一个代码相同的文件:
describe('angularjs homepage', function() {
beforeAll(function(){
browser.get('https://xxxx/');
console.log('calling before all');
});
afterAll(function(done){
console.log('calling after all');
browser.quit();
process.nextTick(done);
});
describe('angularjs homepage', function() {
beforeAll(function(){
browser.get('https://xxxx/');
console.log('calling before all');
});
afterAll(function(done){
console.log('calling after all');
browser.quit();
process.nextTick(done);
});
现在我想使用beforeAll和AfterAll函数,通过这些函数,浏览器应该在每次js文件执行时打开和关闭。当我采用这种方法时,会出现错误,因为此驱动程序实例没有有效的会话ID(您是否调用了WebDriver.quit()?)而且可能不再使用。很难准确理解您的要求,因为您只发布了一个
描述,但在我看到的评论中,您说您希望在每次描述之前打开浏览器。假设您有嵌套的descripe
块,您可以使用beforeach()
和afterEach()
来执行此操作
describe('some test', () => {
beforeAll(() => {
//some setup code
}
beforeEach(() => {
browser.get('https://xxxx/');
}
afterEach(() => {
browser.restart();
}
afterAll(() => {
//some tear down code
}
describe('something', () => {
it('should test something', () => {
//test code
}
}
describe('another thing', () => {
it('should test another thing', () => {
//test code
}
}
}
在上述示例中,执行顺序为:
describe
beforeAll
beforeEach (open browser)
describe - something
it - should test something
afterEach (close browser)
beforeEach (open browser)
describe - another thing
it - should test another thing
afterEach (close browser)
afterAll
还有一个量角器配置选项,可以在每次测试之前重新启动浏览器,但我认为这不是您所要求的 我认为您需要:
前后
之后
它们将在“描述”中的每个“it”块之前执行 使用browser.close()
。我也使用了相同的方法,但问题仍然是一样的。我想打开和关闭每个描述块的浏览器。您可以尝试:beforeAll(异步函数(){wait browser.get('h.ttp…);})
。也许量角器不知道您正在执行beforeAll()
中的异步函数。我已经编辑了原始问题。如果是clearOK,请告诉我,尝试将浏览器。退出()
更改为浏览器。重新启动()
,看看是否有帮助。