简体   繁体   English

带有Jquery集成的Nightwatch失败,并显示以下错误:jQuery需要带有文档的窗口

[英]Nightwatch with Jquery integration fails with the error jQuery requires a window with a document

i am using nightwatch for end to end testing, i am facing one issue while using jQuery with night-watch. 我正在使用睡表进行端到端测试,而在将jQuery与睡表一起使用时遇到一个问题。

While running this test case i am getting error like: 在运行此测试用例时,出现如下错误:

jQuery requires a window with a document jQuery需要带有文档的窗口

Could you please let me know the reason .ad also i have included the JQquery library like this: 您能否让我知道原因.ad,我也包括了JQquery库,如下所示:

var $ = require('jquery').
browser.perform(function(dir)){
var flag = `$`('span').hasClass('red'); //throws error 
}

Just going from your code snibbit, and what seems to be relavent: 仅仅从您的代码snibbit出发,似乎可以避免的是:

I don't think you need the back ticks. 我认为您不需要回声。 If you load in jquery correctly you should be able to just use the $ or jquery variables normally: 如果正确加载了jquery,则应该可以正常使用$或jquery变量:

var flag = $('span').hasClass('red');

If you are unsure that you are loading jQuery correctly, check out requireJS's awesome documentation here 如果您不确定是否正确加载jQuery,请在此处查看requireJS的出色文档

The documentation does use a config file, and you don't have it listed, so I'm otherwise assuming you have this set up correctly. 该文档确实使用了一个配置文件,但是您没有列出它,因此我假设您已经正确设置了该文件。

Otherwise, I'm looking through my learn-nightwatch project (test simple Nightwatch setup), and I don't see any of the tests needing to specifically include jquery. 否则,我将浏览我的Learn-nightwatch项目(测试简单的Nightwatch设置),并且看不到需要专门包含jquery的任何测试。 I would check with this, because I have never seen the "quickstart" Nightwatch tests to include jquery, and I'm able to use jquery fine (It defines it in the html). 我会检查一下,因为我从未见过“快速启动” Nightwatch测试包含jquery,而且我能够很好地使用jquery(它在html中定义)。

The other possibility is that Nightwatch is attempting to test the page before it has actually loaded, Although there would be more information needed about your setup to see if this is possible. 另一种可能性是Nightwatch试图在页面实际加载之前对其进行测试,尽管可能需要更多有关您的设置的信息以查看是否可行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:jQuery 需要一个带有文档的窗口 - Error: jQuery requires a window with a document 如何解决“jQuery需要一个带文档的窗口”错误? - How to solve “jQuery requires a window with a document” error? “ jQuery需要带有文档的窗口” Webpack 2错误 - “jQuery requires a window with a document” webpack 2 error 错误:“ jQuery需要带有文档的窗口”以及Mocha和Typescript? - Error: “jQuery requires a window with a document” with mocha and typescript? Webpack添加jQuery插件:错误:jQuery需要带有文档的窗口 - Webpack adding jQuery plugin: Error: jQuery requires a window with a document 操作 jQuery 得到一个错误:“jQuery 需要一个窗口和一个文档” - Manipulating jQuery to get an error: "jQuery requires a window and a document" Browserify with jQuery> = 2产生“jQuery需要一个带文档的窗口” - Browserify with jQuery >= 2 produces “jQuery requires a window with a document” jQuery 需要一个 window 和 vue native 中的文档 - jQuery requires a window with a document in vue native 错误:jQuery需要一个window带证件。 使用ejs和javascript创建刽子手web app - Error : jQuery requires a window with a document. Using ejs and javascript to create a hangman web app 窗口和文档作为jQuery选择器 - Window and document as jQuery selectors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM