webdriverIO-未处理的承诺拒绝:NoSuchSessionError:无效的会话ID

时间:2019-05-24 14:39:02

标签: javascript node.js jasmine webdriver-io

我正在使用Jasmine和WebdriverIO学习UI测试。我将其与NodeJS一起使用。 我有下一个测试代码:

const projectsPage = require('../../lib/pages/projects.page');
const by = require('selenium-webdriver').By;

describe('Projects page', () => {
  it('Search google', async() => {
    await projectsPage.navigateTo();
    driver.getTitle().then(function(title) {
      expect(title).toBe('Google');
    });
    driver.findElement(by.name('q')).sendKeys('test');
  })
});

运行它时,我收到错误消息:

Unhandled promise rejection: NoSuchSessionError: invalid session id
      (Driver info: chromedriver=2.46.628411 (3324f4c8be9ff2f70a05a30ebc72ffb013e1a71e),platform=Mac OS X 10.14.5 x86_64)

但是下面的代码执行成功:

describe('Projects page', () => {
  it('Search google', async() => {
    await projectsPage.navigateTo();
    driver.getTitle().then(function(title) {
      expect(title).toBe('Google');
    });
    driver.findElement(by.name('q'))
  })
});

哪里错了?

2 个答案:

答案 0 :(得分:1)

由于findElementsendKeys也返回了Promise,因此您还必须等待这些方法:

await driver.findElement(by.name('q')).then(element => element.sendKeys('test'));

答案 1 :(得分:0)

您的测试在代码真正运行之前结束,您应该等待每个异步语句

2019-05-28 10:29:13.515 4764-4764/com.ashwin.imagefromweb I/Choreographer: Skipped 53 frames!  The application may be doing too much work on its main thread.