-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
While loading Oracle db within Cypress (plugins/index.js), getting error - NJS-045: cannot load the oracledb add-on binary for Node.js 8.2.1 (win32, x64) #2914
Comments
Any update on this defect ? |
Hey @Sanj2005, have you tried troubleshooting the installation via oracledb's github issues? I do see quite a few people have encountered this error. When you use OracleDB outside of Cypress, are you using the same |
also a suggestion - if oracle native extensions cannot be loaded inside the Electron environment (which seems to be the case here when using |
Hi @jennifer-shehane Since this is working fine outside of Cypress, I don't think this is related to OracleDB side. @bahmutov - Are you saying that Cypress has known issue that we can't load oracleDB using cy.task ? |
Any news on that since we are having the same problem here ?! BTW: on Mac it works on Windows it doesn't. |
I've discussed this issue with the developers of the Oracle NodeJS plug-in. The issue sounds like incompatibility due to Cypress using quite an old version of Electron. Cypress are targeting an Electron upgrade for their next major release, so fingers crossed. |
Even better - when this PR lands #4436 and is released, Cypress will be able to use your system Node version, ensuring that you no longer rely on the Electron inside Cypress to match what you need. |
Awesome! Look forward to testing this one. Will it land in a forthcoming minor release? |
yes, it probably will be released in 3.5.0 |
Any update on this issue? |
I believe this is fixed from 3.5.0 onwards with the ability to run tasks using NodeJS present on the host machine rather than the one bundled with Cypress. See Cypress config docs for details. |
Closing as resolved. If you're experiencing a bug similar to this in Cypress, please open a new issue with a fully reproducible example that we can run. There may be a specific edge case with the issue that we need more detail to fix. |
@Sanj2005 did it work for you? |
Since people are still commenting on this and I ran across this in my own struggles, here is the solution I came up with for this. let _connection;
// https://www.sitepoint.com/javascript-design-patterns-singleton/
const DbPluginUtil = {
async setupDb(config) {
// has to be in this method or even importing this file will break stuff in cypress
const oracledb = require('oracledb');
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
oracledb.autoCommit = true;
oracledb.initOracleClient({configDir: config['TNS_ADMIN_LOCATION']});
_connection = await oracledb.getConnection({
user: config['DB_USER'],
password: config['DB_PASSWORD'],
connectString: config['DB_CONNECT_STRING'],
});
return null;
},
async testConnection(config) {
if (!_connection) {
await this.setupDb(config);
}
},
async executeDbStatement(statement, config) {
await this.testConnection(config);
try {
return await _connection.execute(statement);
} catch (e) {
throw new Error('failed to execute: ' + statement + '\n' + e.message);
}
},
}
Object.freeze(DbPluginUtil);
function loadDBPlugin(config) {
return {
async executeDbStatement({statement}) {
return await DbPluginUtil.executeDbStatement(statement, config);
},
}
}
module.exports = {
loadDBPlugin
} Then in cypress/plugins/index.js: const {loadDBPlugin} = require("../../src/plugins/dbPlugin");
...
// in the module.exports function:
on('task', loadDBPlugin(config)); Then usage in your cypress tests looks like this:
Hope this helps someone in the future. I sure could have used it before going through all the trouble of figuring this out. |
@ice1080 : Thanks for the details. However, using the above it is throwing error as below. Message: The plugins file is missing or invalid. Your Or you might have renamed the extension of your Please fix this, or set |
How does your package.json look like? It seems that you can't just do 'npm install oracledb' with latest on Mac, you need to manual configure something to get it working. |
"devDependencies": {
"@babel/plugin-transform-async-to-generator": "^7.12.13",
"@babel/plugin-transform-modules-commonjs": "^7.12.13",
"@cypress/webpack-preprocessor": "^5.5.0",
"cypress": "^6.3.0",
"cypress-sql-server": "^1.0.0",
"jest": "^26.6.3",
"jest-junit": "^12.0.0",
"mockdate": "^3.0.2",
"webpack": "^5.21.0"
},
"dependencies": {
"@babel/core": "^7.12.13",
"@babel/preset-env": "^7.12.13",
"@babel/register": "^7.12.13",
"dateformat": "^4.5.1",
"node": "^15.7.0",
"oracledb": "^5.1.0"
}, @kbaala88 I did have to add some babel stuff to get some of my unit tests to work, but I didn't think it was needed to get it to work. Looks like I was wrong. Here is my .babelrc file at the top level next to package.json {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"esmodules": true
}
}
]
],
"plugins": [
"@babel/transform-async-to-generator",
"@babel/transform-modules-commonjs"
]
} There is probably also a way to get it to work without needing babel, but I would guess it's the async/await stuff that is causing the plugins file to not load properly without babel. |
Current behavior:
I am trying to load oracledb using
cy.task
.For that I am trying to load oracledb inside the
plugins/index.js
.But whenever I am adding statement -
I am getting error as shown in below screenshot.
Desired behavior:
I would like to load the oracle db using node processor (nodejs)
Steps to reproduce: (app code and test code)
a) Install Python 2.7.14
b) Install Visual Studio 2013
c) Download Oracle Instant Client on local machine & give that to PATH
npm install github:oracle/node-oracledb#v3.0.1
plugins/index.js
add statement -const oracledb = require('oracledb');
and try launching Cypress. User is getting above error (shown in above screenshot) in the Cypress Window and user is blocked from performing any actions.Note :
plugin/index.js
and found that its working fine but only for oracle its not workingVersions
Cypress 3.1.3
nodejs - 8.2.1
Os - Windows 7 or Windows 8.1
oracledb - "github:oracle/node-oracledb#v3.0.1",
========================
I am feeling that most likely, it's issue from Cypress only, as we are able to load & make a successful connection to Oracle DB outside the Cypress. Kindly fix this so that we can perform the Oracle DB validations as part of our test execution
The text was updated successfully, but these errors were encountered: