UI test with mocha and coffee script - javascript

I am setting up test case environment with the help of Getting started with Selenium WebDriver for node.js
I have installed all dependencies but still unable to run sample test case given in above blog:
selenium = require 'selenium-webdriver'
chai = require 'chai'
chai.use require 'chai-as-promised'
expect = chai.expect
before ->
#timeout 10000
#driver = new selenium.Builder()
.withCapabilities(selenium.Capabilities.chrome())
.build()
#driver.getWindowHandle()
after ->
#driver.quit()
describe 'Webdriver tutorial', ->
beforeEach ->
#driver.get 'http://bites.goodeggs.com/posts/selenium-webdriver-nodejs-tutorial/'
it 'has the title of the post in the window\'s title', ->
expect(#driver.getTitle()).to.eventually.contain
'Getting started with Selenium Webdriver for node.js'
it 'has publication date', ->
text = #driver.findElement(css: '.post .meta time').getText()
expect(text).to.eventually.equal 'December 30th, 2014'
it 'links back to the homepage', ->
#driver.findElement(linkText: 'Bites').click()
expect(#driver.getCurrentUrl()).to.eventually.equal 'http://bites.goodeggs.com/'
Running above test case with:
mocha JavaScript_test.coffee --compilers coffee:coffee-script/register
I get following error:
module.js:471
throw err;
^
Error: Cannot find module 'coffee-script/register'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at /usr/local/lib/node_modules/mocha/bin/_mocha:337:3
at Array.forEach (native)
at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:329:19)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:509:3

I had the same problem, and I don't know when it change but the module coffee-script doesn't exist anymore.
The right package is coffeescript so the right command is :
mocha JavaScript_test.coffee --compilers coffee:coffeescript/register
But --compilers is deprecated so the new right syntaxe is :
mocha JavaScript_test.coffee --require coffeescript/register

Related

NPM is giving me an Error with every command

Whenever I'm running a command with npm. it's giving an Error. A few days ago, It was totally fine. I used it in some of my projects but now it is can't do nothing.
node:internal/modules/cjs/loader:941
const err = new Error(message);
^
Error: Cannot find module '../../package.json'
Require stack:
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\cli.js
- C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15)
at Function.Module._load (node:internal/modules/cjs/loader:774:27)
at Module.require (node:internal/modules/cjs/loader:1013:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (C:\Users\nuur hassan\AppData\Roaming\npm\node_modules\npm\lib\utils\unsupported.js:2:19)
at Module._compile (node:internal/modules/cjs/loader:1109:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)
at Module.load (node:internal/modules/cjs/loader:989:32)
at Function.Module._load (node:internal/modules/cjs/loader:829:14)
at Module.require (node:internal/modules/cjs/loader:1013:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\utils\\unsupported.js',
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\lib\\cli.js',
'C:\\Users\\nuur hassan\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js'
]
}
The error says that npm can't find the package.json file. Make sure you haven't deleted it. If you want to create one you can use npm init to initialize one in the current directory. Even if that fails I'd reinstall node js and double check the NODE_PATH.

Cannot find module

internal/modules/cjs/loader.js:883
throw err;
^
Error: Cannot find module 'better-sqlite3'
Require stack:
- D:\UserProfile\Users\Administrator\Desktop\rosbot\src\utils\db.js
- D:\UserProfile\Users\Administrator\Desktop\rosbot\src\Client.js
- D:\UserProfile\Users\Administrator\Desktop\rosbot\app.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (D:\UserProfile\Users\Administrator\Desktop\rosbot\src\utils\db.js:1:18)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'D:\\UserProfile\\Users\\Administrator\\Desktop\\rosbot\\src\\utils\\db.js',
'D:\\UserProfile\\Users\\Administrator\\Desktop\\rosbot\\src\\Client.js',
'D:\\UserProfile\\Users\\Administrator\\Desktop\\rosbot\\app.js'
]
}
I am getting this error when I am trying to run the discord bot with vscode by the command "node ." and I don't know how to solve this
Looks like you haven't Imported the module or named it wrong or installed
example to fix importing error:
const <name> = require("better-sqlite3");
example to fix name error:
const <name> = require("better-sqlite3");
example to fix installing error:
in cmd type: npm i better-sqlite3
after that type
const <name> = require("better-sqlite3")
change name with what you want it to be as.

"TypeError: jsdom.jsdom is not a function" with paper-node.js in npm paper module

I have installed webppl-agents library (along with webppl and webppl-dp) and am trying to run the command line test, but I'm running into some trouble. It appears there is a dependency issue with jsdom from the npm paper module (1) (2) (3) (4), but I haven't been able to get a complete handle on the issue at this point.
Does anybody know what's going on here? Do I just need to use a newer version of paper?
PS C:\Users\user\.webppl\node_modules\webppl-agents> webppl --require webppl-dp --require . tests/tests.wppl
C:\Users\user\.webppl\node_modules\webppl-agents\node_modules\paper\dist\paper-node.js:10835
document = jsdom.jsdom('<html><body></body></html>'),
^
TypeError: jsdom.jsdom is not a function
at new <anonymous> (C:\Users\user\.webppl\node_modules\webppl-agents\node_modules\paper\dist\paper-node.js:10835:19)
at Object.<anonymous> (C:\Users\user\.webppl\node_modules\webppl-agents\node_modules\paper\dist\paper-node.js:33:13)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\user\.webppl\node_modules\webppl-agents\src\visualization\gridworld.js:1:75)
There has been some breaking changes recently. The following way of initializing jsodm, document and window fixed it for me:
import jsdom from 'jsdom';
const {JSDOM} = jsdom;
const {document} = (new JSDOM('<!doctype html><html><body></body></html>')).window;
global.document = document;
global.window = document.defaultView;

Unable to launch Firefox in selenium 3.0-beta3 with geckodriver 0.10 using Javascript with selenium's own sample

just want to learn Selenium testing beginning with it's own sample.
However, after everything is set up(Node.js, Selenium), when I want to use selenium-webdriver's own sample, it is not working:
This is the official code(name is google_search.js) provided by selenium:
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
This code is within example folder, in Node.js cmd, I cd to node_modules\selenium-webdriver\example, and put geckodriver in this folder, then run node google_search.js
Here's the result:
C:\Users\username\node_modules\selenium-webdriver\lib\promise.js:2291
throw error;
^
WebDriverError: Unable to parse new session response: {"error":"unknown error","
message":"Expected browser binary location, but unable to find binary in default
location, no 'firefox_binary' capability provided, and no binary flag set on th
e command line"}
at WebDriverError (C:\Users\username\node_modules\selenium-webdriver\lib\err
or.js:27:10)
at C:\Users\username\node_modules\selenium-webdriver\lib\http.js:335:17
at process._tickCallback (node.js:369:9)
From: Task: WebDriver.createSession()
at Function.createSession (C:\Users\username\node_modules\selenium-webdriver
\lib\webdriver.js:366:24)
at createGeckoDriver (C:\Users\username\node_modules\selenium-webdriver\fire
fox\index.js:497:27)
at Driver (C:\Users\username\node_modules\selenium-webdriver\firefox\index.j
s:605:14)
at Builder.build (C:\Users\username\node_modules\selenium-webdriver\index.js
:557:16)
at Object.<anonymous> (C:\Users\username\node_modules\selenium-webdriver\exa
mple\google_search.js:44:6)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
From: Task: WebDriver.navigate().to(http://www.google.com/ncr)
at Driver.schedule (C:\Users\username\node_modules\selenium-webdriver\lib\we
bdriver.js:414:17)
at Navigation.to (C:\Users\username\node_modules\selenium-webdriver\lib\webd
river.js:1042:25)
at Driver.get (C:\Users\username\node_modules\selenium-webdriver\lib\webdriv
er.js:832:28)
at Object.<anonymous> (C:\Users\username\node_modules\selenium-webdriver\exa
mple\google_search.js:46:8)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
Did I do anything wrong? Can anyone tell me why the offical sample is not launching firefox? Thanks!
I had the same error-message when trying to run a C#-application with Selenium 3.0.0.
The problem was that I was using the x64 Geckodriver.exe. After downloading and copying the 32bit version to my bin-folder, everything worked well.
-Robert

Jasmine with Coffeescript Unexpected string Syntax error

I'm trying Jasmine in Coffeescript but when i call jasmine in the terminal, I get this error:
/home/luca/tries/sourcemaps-demo/spec/mainSpec.coffee:1
nction (exports, require, module, __filename, __dirname) { describe 'A suite',
^^^^^^^^^
SyntaxError: Unexpected string
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /home/luca/.nvm/v0.10.35/lib/node_modules/jasmine/lib/jasmine.js:63:5
at Array.forEach (native)
at Jasmine.loadSpecs (/home/luca/.nvm/v0.10.35/lib/node_modules/jasmine/lib/jasmine.js:62:18)
at Jasmine.execute (/home/luca/.nvm/v0.10.35/lib/node_modules/jasmine/lib/jasmine.js:145:8)
This is my spec/support/jasmine.json:
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.coffee"
],
"helpers": [
"helpers/**/*.coffee"
]
}
And this is my spec/mainSpec.coffee:
describe 'A suite', ->
it 'should return true', ->
expect(true).toBe true
I'm missing something?
jasmine does not support coffee-script. If You want to write tests in coffee-script, use jasmine-node
$npm install -g jasmine-node
$jasmine-node --coffee spec/
.
Finished in 0.01 seconds
1 test, 1 assertion, 0 failures, 0 skipped

Categories

Resources