1
我有文字我需要執行nightwatch htmlEndcoding上。 我找到了一個解決方案,但它需要使用jQuery。我無法弄清楚如何訪問Nightwatch裏面的jquery。如何使用jQuery的內部Nightwatch
我發現下面的htmlEncode這看起來像是我可以使用,但我不知道怎麼把它列入nightwatch。我得到'$'未定義。我可以看到這是jQuery的,但我不知道如何去夜間jQuery的。
function htmlEncode(value){
// Create a in-memory div, set its inner text (which jQuery automatically encodes)
// Then grab the encoded contents back out. The div never exists on the page.
return $('<div/>').text(value).html();
}
function htmlDecode(value){
return $('<div/>').html(value).text();
}
我還發現How to write a nightwatch custom command using jquery,但它配備了警告:「需要注意的是,你確實需要的jQuery提供您的應用程序在全球範圍這個工作」 ...我不知道該怎麼做。
我是一個Java程序員,我是新來的都nightwatch和JavaScript。似乎我應該能夠通過客戶端或API訪問jquery,但我無法弄清楚如何去做。
試了版本如下:
npm install jQuery
var $ = require('jquery');
var $ = require('jQuery');
var jsdom = require('jsdom').jsdom
, myWindow = jsdom().createWindow()
, $ = require('jQuery')
, jq = require('jQuery').create()
, jQuery = require('jQuery').create(myWindow)
;