javascript – Nightwatch.js:窗口未定义

我正在尝试使用Nightwatch来测试React应用程序.我正在使用React-Router.

使用Nightwatch窗口运行测试时未定义.

React使用以下代码片段来测试DOM是否可用:

var canUseDOM = !!(
  typeof window !== 'undefined' &&
  window.document &&
  window.document.createElement
);

来自React.js来源:ExecutionEnvironment.js#L16

React-Router expects canUseDOM to be true, otherwise it throws an
error.

所以我的测试失败了,因为在运行Nightwatch时窗口未定义.

selenium webdriver不应该出现窗口吗?
如何使窗口可用?

解决方法:

从Nighwatch.js(和更具体地说是selenium-webdriver),您无法直接访问客户端的DOM.
您必须使用execute()函数注入脚本:

 this.demoTest = function (browser) {
   browser.execute(function(data) {

     var canUseDOM = !!(
       typeof window !== 'undefined' &&
       window.document &&
       window.document.createElement
     );
     alert('canUseDOM ?' + canUseDOM); 

     return true;
   }, [], null);
 };

API中的更多信息:http://nightwatchjs.org/api#execute

相关文章

转载地址:https://www.cnblogs.com/mini-monkey/p/12104821...
web自动化测试过程中页面截图相对比较简单,可以直接使用sel...
目录前言一、Selenium简介二、浏览器驱动1.浏览器驱动参考2....
一、iframe的含义:iframe是HTML中框架的一种形式,在对界面...
转载请注明出处❤️作者:测试蔡坨坨原文链接:caituotuo.to...
'''##**认识selenium**​**下载:pipinstall...