【问题标题】:NightwatchJS - Can't close browser window automatically after running testNightwatchJS - 运行测试后无法自动关闭浏览器窗口
【发布时间】:2017-08-15 22:56:03
【问题描述】:

我正在运行我的第一次 Nightwatch 测试,如下面的代码所示,一切运行正常,selenium 将“wiki”输入谷歌并提交表单,测试通过。但是我希望它在测试完成后自动关闭浏览器窗口。

我尝试添加以下内容:

driver.closeWindow();

但是它失败了,因为它无法识别“closeWindow()”函数,我发现文档非常缺乏 (http://nightwatchjs.org/api/closeWindow.html),所以如果有人能指出我需要如何实现,我将不胜感激这个。

var webdriver = require('selenium-webdriver'),


By = webdriver.By,
  Until = webdriver.Until;

var driver = new webdriver.Builder()
  .forBrowser('chrome')
  .build();

driver.get('http://www.google.com');
driver.findElement(By.name('q')).sendKeys('wiki');
driver.findElement(By.name('btnK')).submit();
driver.wait(check_title, 1000);

function check_title(){
  var promise = driver.getTitle().then(function(title) {
    if (title === 'wiki - Google Search') {
      console.log('success');
      return true;
    } else {
      console.log('fail, title was ' + title);
    }
  });
  return promise;
}

【问题讨论】:

    标签: javascript node.js selenium testing nightwatch.js


    【解决方案1】:

    您使用的是 selenium-webdriver,而不是 nightwatch 本身。看看the examples.

    还可以查看this github repo,这对于开始设置您的夜间测试测试非常有用。

    要使用 selenium-webdriver 关闭驱动程序,您应该调用 Dispose 方法driver.Dispose()

    【讨论】:

    • 感谢@Frankusky 的澄清,我也会看看这些链接。如果有人对上述 WebDriver 问题有疑问,解决方案是添加 driver.close();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-07
    • 2015-06-29
    • 1970-01-01
    • 2014-01-28
    相关资源
    最近更新 更多