Selenium WebDriver Error on Windows: logging.js not found - javascript

I'm automating Chrome on Windows 8.1 with JavaScript using Selenium's WebDriverJS. I downloaded a copy of the ChromeDriver and Selenium Standalone Server jar file and placed in E:\Selenium directory. I started Selenium Standalone Server and tried to run my javascript code written in BrowserTest.js file with Node command prompt as
E:\Selenium> Node BrowserTest.js
the BrowserTest.js:
var driver = require("selenium-webdriver");
function createDriver() {
var driver = new driver.Builder()
.usingServer('http://localhost:4444/wd/hub')
.withCapabilities(driver.Capabilities.chrome())
.build();
driver.manage().timeouts().setScriptTimeout(10000);
return driver;
}
var driver = createDriver();
driver.get("http://www.google.com");
driver.getTitle().then(function (title) {
console.log(title);
});
driver.quit();
But it throws error as:
fs.js:500 return binding.open(pathModule._makeLong(path),
stringToFlags(flags), mode);
^ Error: ENOENT, no such file or directory 'E:\Selenium\webdriver\logging.js'
at Error (native)
at Object.fs.openSync (fs.js:500:18)
at Object.fs.readFileSync (fs.js:352:15)
at Object.Context.closure.goog.retrieveAndExecModule_ (E:\Selenium\node_modules\selenium-webdriver\_base.js:129:23)
at <anonymous>:1:6
at Object.exports.runInContext (vm.js:64:17)
at Context.closure.closure.vm.createContext.CLOSURE_IMPORT_SCRIPT (E:\Selenium\node_modules\selenium-webdriver\_base.js:101:12)
at Object.goog.importScript_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:873:9)
at Object.goog.importModule_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:894:14)
at Object.goog.writeScripts_ (E:\Selenium\node_modules\selenium-webdriver\lib\goog\base.js:1251:16)

Update
try changing the selenium-webdriver version to 2.46.1, it has been pushed to npm and in it, the bug has been fixed.
like #simon said, this bug is already been reported in github,
for now, one hack has been suggested as solution in it's comments,
go to node_modules\selenium-webdriver\_base.js, add below line between line 100 and line 101( as first line of if block):
opt_srcText = opt_srcText.replace(/\\/g,'/');
it fixed the problem for me.

There appears to be a bug in v2.46.0 of Selenium on windows.
It has just been fixed in 2.46.1, so if you update it should solve your problem

Problem was solved by updating to version - 2.46.1

Related

Adding opentelemetry tracing to Node.js app breaks `require("fs").realpathSync.native`

Using the following tracing enabling script from OpenTelemetry docs:
const opentelemetry = require("#opentelemetry/sdk-node");
const { getNodeAutoInstrumentations } = require("#opentelemetry/auto-instrumentations-node");
const { diag, DiagConsoleLogger, DiagLogLevel } = require('#opentelemetry/api');
// For troubleshooting, set the log level to DiagLogLevel.DEBUG
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
const sdk = new opentelemetry.NodeSDK({
traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
instrumentations: [getNodeAutoInstrumentations()]
});
sdk.start()
running my Next.js server as I thought is required, I get an error:
$ node --require './tracing/opentelemetry.js' ./node_modules/next/dist/bin/next start -p 3000
No modules instrumentation has been defined, nothing will be patched
#opentelemetry/instrumentation-grpc Module #grpc/grpc-js has been loaded before #opentelemetry/instrumentation-grpc so it might not work, please initialize it before requiring #grpc/grpc-js
Exporter "otlp" requested through environment variable is unavailable.
/mnt/vol/.local/share/pnpm/global/5/.pnpm/next#12.1.5_zpnidt7m3osuk7shl3s4oenomq/node_modules/next/dist/lib/get-project-dir.js:40
const realDir = _fs.default.realpathSync.native(resolvedDir);
^
TypeError: _fs.default.realpathSync.native is not a function
at Object.getProjectDir (/mnt/vol/.local/share/pnpm/global/5/.pnpm/next#12.1.5_zpnidt7m3osuk7shl3s4oenomq/node_modules/next/dist/lib/get-project-dir.js:40:50)
at nextStart (/mnt/vol/.local/share/pnpm/global/5/.pnpm/next#12.1.5_zpnidt7m3osuk7shl3s4oenomq/node_modules/next/dist/cli/next-start.js:80:37)
at /mnt/vol/.local/share/pnpm/global/5/.pnpm/next#12.1.5_zpnidt7m3osuk7shl3s4oenomq/node_modules/next/dist/bin/next:141:34
at processTicksAndRejections (node:internal/process/task_queues:96:5)
Node.js v17.8.0
Now this can be simplified to a minimal reproduction as follows. This has the fs.realpathSync.native function:
$ node -e 'console.log(require("fs").realpathSync)'
[Function: realpathSync] { native: [Function (anonymous)] }
This doesn't have fs.realpathSync.native:
$ node --require ./tracing/opentelemetry.js -e 'console.log(require("fs").realpathSync)'
No modules instrumentation has been defined, nothing will be patched
#opentelemetry/instrumentation-grpc Module #grpc/grpc-js has been loaded before #opentelemetry/instrumentation-grpc so it might not work, please initialize it before requiring #grpc/grpc-js
[Function (anonymous)]
Exporter "otlp" requested through environment variable is unavailable.
My Node's --require is working correctly (noop.js is an empty file):
$ node --require ./tracing/noop.js -e 'console.log(require("fs").realpathSync)'
[Function: realpathSync] { native: [Function (anonymous)] }
Why would the OpenTelemetry setup script break the fs module?
$ node --version
v17.8.0
//package.json dependencies
"#opentelemetry/api": "^1.3.0",
"#opentelemetry/auto-instrumentations-node": "^0.35.0",
"#opentelemetry/sdk-node": "^0.34.0",
$ uname -a
Linux code-server 5.15.0-1025-oracle #31~20.04.2-Ubuntu SMP Tue Nov 29 13:01:56 UTC 2022 aarch64 aarch64 aarch64 GNU/Linux
Does my ARM machine have something to do with it?
I can reproduce the same on x86_64 on https://replit.com/#JakubKoralewski/opentelemetry-repro with the same behavior.
The reason this error occurs is due to a bug in #opentelemetry/instrumentation-fs introduced as a new dependency to #opentelemetry/auto-instrumentations-node in PR #981 which got released with version 0.34.0. The issue was reported but at the time of writing is still open. However, as also already linked above a PR to address the issue is being reviewed.
Fow now, I see three ways to address the problem:
As suggested in a comment above downgrade #opentelemetry/auto-instrumentations-node to next lower version 0.33.1.
Disable the file system instrumentation when configuring the node instrumentation. For that simply replace getNodeAutoInstrumentations() with getNodeAutoInstrumentations({ '#opentelemetry/instrumentation-fs': { enabled: false } }) in your code. Given that your project is in Next.js and you likely have little file system activity aside from maybe public files this is likely the best option for now.
Remove #opentelemetry/auto-instrumentations-node altogether and simply instrument the libraries you actually use. Using the auto instrumentation for Node.js pulls in a lot of transitive dependencies. Say you have a Next.js app, connect to a Postgres database and use winston for logging your instrumentation setup could look something like this:
const sdk = new opentelemetry.NodeSDK({
traceExporter: new opentelemetry.tracing.ConsoleSpanExporter(),
instrumentations: [
// new FsInstrumentation(), TODO: re-enable once bug is fixed
new HttpInstrumentation(),
new PgInstrumentation(),
new WinstonInstrumentation(),
]
});

Create React App not reusing existing tab

I have been developing a web app (for a few months) that is built on top of CRA. Everything has been working as intended until this morning when I realized that the npm (or yarn) start script is no longer reusing the existing tab I have open in Chrome. It instead opens a new tab at localhost:3000 even if there are existing tabs at localhost:3000. I have been investigating this for a few hours but am yet to find a solution. I added a log statement in the CRA script (within my node modules) that handles the reusing of existing tabs upon startup of the app.
function startBrowserProcess(browser, url) {
// If we're on OS X, the user hasn't specifically
// requested a different browser, we can try opening
// Chrome with AppleScript. This lets us reuse an
// existing tab when possible instead of creating a new one.
const shouldTryOpenChromeWithAppleScript =
process.platform === 'darwin' &&
(typeof browser !== 'string' || browser === OSX_CHROME);
if (shouldTryOpenChromeWithAppleScript) {
try {
// Try our best to reuse existing tab
// on OS X Google Chrome with AppleScript
execSync('ps cax | grep "Google Chrome"');
execSync('osascript openChrome.applescript "' + encodeURI(url) + '"', {
cwd: __dirname,
stdio: 'ignore',
});
return true;
} catch (err) {
console.log(err);
// Ignore errors.
}
}
This is the output of the log statement:
{ Error: Command failed: osascript openChrome.applescript "http://localhost:3000/"
at checkExecSyncError (child_process.js:621:11)
at execSync (child_process.js:658:13)
at startBrowserProcess (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-dev-utils/openBrowser.js:78:7)
at openBrowser (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-dev-utils/openBrowser.js:122:14)
at Server.devServer.listen.err (/Users/***/Desktop/WorkSpace/React/***/node_modules/react-scripts/scripts/start.js:100:7)
at Server.returnValue.listeningApp.listen (/Users/***/Desktop/WorkSpace/React/***/node_modules/webpack-dev-server/lib/Server.js:604:10)
at Object.onceWrapper (events.js:273:13)
at Server.emit (events.js:182:13)
at emitListeningNT (net.js:1328:10)
at process.internalTickCallback (internal/process/next_tick.js:72:19)
status: 1,
signal: null,
output: [ null, null, null ],
pid: 2691,
stdout: null,
stderr: null }
It seems to have an issue running the Applescript command that handles this but I am unsure why. One of the other developers that is working on the same app locally is not having this issue. One change I made recently was upgrading to the new macOS Mojave. But the other developer just upgraded as well and is not having this issue.
Does anyone know what could be wrong?
To avoid opening a new tab,
you'll need to create an .env file in the root of your project and add this line,
BROWSER=none.
As shown here
Turns out after I upgraded Mojave I denied interface access to Google Chrome from my terminal. So it was unable to run the "reuse" tab script.

Selenium building internet explorer driver javascript error

I have my selenium standalone server set up as running with the IEDriver as a parameter using the selenium-standalone start --drivers.ie.arch=ia32 configuration.
I'm getting the following error when I try to run my internet explorer selenium test:
index.js:673
throw new Error('Do not know how to build driver: ' + browser
^
Error: Do not know how to build driver: IE; did you forget to call
usingServer(url)?
Yet I have the correct server listed in my code:
const {Builder, By, Key, until} = require('selenium-webdriver');
driver = await new webdriver.Builder().forBrowser('IE').usingServer('http://localhost:4444/wd/hub').build();
I have also tried this:
let driver = new webdriver.Builder()
.forBrowser('internet explorer')
.usingServer('http://localhost:4444/wd/hub')
.build();
but neither of these work and I get the same error message...
Any help would be appreciated!
https://github.com/SeleniumHQ/selenium/wiki/Grid2 Just read this article, you are missing something. And run your IE tests under administrator for future.
driver = new webdriver.Builder().
usingServer("http://localhost:4444/wd/hub").
withCapabilities(webdriver.Capabilities.ie()).
build();
It works for me.

Local server by PythonJS

I downloaded this
demo server.
I follow the instruction, so
First, git clone this repo, and then run: npm install python-js. Now you are ready to run the server, run: ./run-demo.js and then open your browser to localhost:8080.
Unfortunately I can't run run-demo.js beacuse I have this error
---------------------------
Windows Script Host
---------------------------
Line: 1
Character: 1
Error: Invalid character
Code: 800A03F6
Source: Microsoft JScript - compilation error
I try to run this by node.js console but have only "..." and nothing happend.
This is code of run-demo.js:
#!/usr/bin/env node
var fs = require('fs')
//var pythonjs = require('../PythonJS/pythonjs/python-js')
var pythonjs = require('python-js')
var pycode = fs.readFileSync( './server.py', {'encoding':'utf8'} )
var jscode = pythonjs.translator.to_javascript( pycode )
eval( pythonjs.runtime.javascript + jscode )
Any ideas? I want to run local server and use PythonJS
I don't believe # is a valid character in Javascript. If the run0demo.js file is being delivered to your browser, it certainly won't know what to make of the shebang (#!) line, which is used by the UNIX kernel to determine which executbale should be used to process the file.
If anyone else will be looking for solution, here is it:
node run-demo.js
Simple as... ;)

AppJS --harmony issue?

I'm using msvc and have nodejs tools setup in it. Fairly new to node.js but all the other npm packages i've simply installed via command line or through nodejs tools and they have worked. AppJS however gives me the error when I call require('appjs').
throw new Error('AppJS requires Node is run with the --harmony command
line)
Anyone know how to fix this? I get this error even when calling my script from command line doing
node --harmony app.js
Actual code
var serialPortLib = require("serialport");
var appjs = require('appjs');
var serialPort = new serialPortLib.SerialPort("COM13",{
baudrate : 250000,
parser : serialPortLib.parsers.readline('\n')
});
serialPort.on('open', function () { console.log('open'); serialPort.write("Sup!\n");});
serialPort.on('data',function(data){ console.log(data);})

Categories