Session not created Selenium/webdriver when using Safari 12 - javascript

Since upgrading to Safari 12, my automated scripts are now getting this error:
SessionNotCreatedError: Request body does not contain required parameter 'capabilities'.
(The error does not occur for other browsers).
I'm using the javascript webdriver bindings and, when I build webdriver, I use the withCapability key value pairs:
var capabs = {
'browserName' : 'Safari',
'version' : '12.0'
}
browserUnderTest = new webdriver.Builder().
withCapabilities(capabs)
.forBrowser('safari')
.build();
I think the problem is with the safari.js file itself, but I don't know enough about how it operates to pinpoint anything. Here is the full text of the error:
SessionNotCreatedError: Request body does not contain required parameter 'capabilities'.
at Object.throwDecodedError (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/error.js:514:15)
at parseHttpResponse (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/http.js:519:13)
at doSend.then.response (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: WebDriver.createSession()
at Function.createSession (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/lib/webdriver.js:769:24)
at Function.createSession (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/safari.js:253:41)
at createDriver (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/index.js:170:33)
at Builder.build (/Users/qualit/Documents/autotests/node_modules/selenium-webdriver/index.js:660:16)
at Object.<anonymous> (/Users/qualit/Documents/autotests/K8_autotest.js:354:6)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
Does anyone have any ideas about the cause of this or a fix?

This issue happens because Safari 12 uses a new W3C webdriver protocol (source) which appears to be incompatible with the latest stable selenium-webdriver package (v3.6)
safaridriver can be passed a --legacy flag to use the old protocol. Directly on the command line this would be done like: /usr/bin/safaridriver --legacy
This flag can be set on the driver in your node program as follows:
const webdriver = require('selenium-webdriver');
const safari = require('selenium-webdriver/safari');
new webdriver.Builder()
.usingServer(await new safari.ServiceBuilder().addArguments('--legacy').build().start())
.forBrowser('safari')
.build();
Here's documentation on the ServiceBuilder API - https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/safari_exports_ServiceBuilder.html
A couple GitHub tickets cover this as well:
https://github.com/SeleniumHQ/selenium/issues/6431
https://github.com/SeleniumHQ/selenium/issues/6026

This will also work if you get an error for 'await' when trying #mjdease solution above.
new webdriver.Builder()
.usingServer(new safari.ServiceBuilder().addArguments('--legacy').build().start())
.forBrowser('safari')
.build();

Related

node js discord bot is not works

/home/discord/project/bloodmoon/node_modules/discord.js/src/client/Client.js:42
} catch {
^
SyntaxError: Unexpected token {
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/discord/project/bloodmoon/node_modules/discord.js/src/index.js:8:11)
i'm interested in developing discord bot. so i tried it. first, it works.
but, i moved the server and i setted it. and it not works! please give advise to me.
(please understand i can't write a English essay well. sorry)
If you check the discord.js source code, you can see that they're trying to silently ignore if there is an error when their code requires the worker_threads module. They simply omit the usual (error) part after catch:
try {
// Test if worker threads module is present and used
data = require('worker_threads').workerData || data;
} catch {
// Do nothing
}
However, it only works in newer versions of JavaScript and older ones will throw a SyntaxError. So, you must be using an older version of Node, because optional catch binding is only available in Node.js v10+.
The following is an example in Node v8:
// using Node v8
try { error } catch { console.log('oops') }
⬇⬇ result ⬇⬇
try { error } catch { console.log('oops') }
^
SyntaxError: Unexpected token {
While it just works fine in Node v10+:
// using Node v16
try { error } catch { console.log('oops') }
⬇⬇ result ⬇⬇
oops
To solve this, you need to update your Node version to at least v12, as mentioned in the discord.js docs:
v12 requires Node 12.x or higher, so make sure you're up-to-date. To
check your Node version, use node -v in your terminal or command
prompt, and if it's not high enough, update it! There are many
resources online to help you with this step based on your host system.

How to work with Edge browser using Selenium webdriver-js

I am trying to Launch edge using selenium-webdriver-js ( javascript, not Java). i am facing issues in launching the edge browser, all other browsers work fine for me.
var wd = require('selenium-webdriver');
var driver = new wd.Builder().forBrowser('MicrosoftEdge').build();
driver.get('http://www.google.com/ncr');
driver.quit();
I am getting the following error.
WebDriverError: Unknown error
at parseHttpResponse (D:\selenium-js\node_modules\selenium-webdriver\lib\http.js:536:11)
at doSend.then.response (D:\selenium-js\node_modules\selenium-webdriver\lib\http.js:441:30)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
From: Task: WebDriver.createSession()
at Function.createSession (D:\selenium-js\node_modules\selenium-webdriver\lib\webdriver.js:769:24)
at Function.createSession (D:\selenium-js\node_modules\selenium-webdriver\edge.js:281:41)
at createDriver (D:\selenium-js\node_modules\selenium-webdriver\index.js:170:33)
at Builder.build (D:\selenium-js\node_modules\selenium-webdriver\index.js:651:16)
at Object.<anonymous> (D:\selenium-js\sampleScripts\yourProduct\features\stepdefinition\DifferentBrowser.js:23:59)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
Can you help me in getting the solution or working code? I don't know what i am missing
You should make sure to PATH to MicrosoftWebDriver.msi should be valid and your webdriver should support your browser's version.
Your code doesn't contain setup to access to selenium server and webdriver. If selenium server isn't defined, It connects to "localhost:4444" by default.
const { Builder, By, Key } = require("selenium-webdriver");
async function example() {
const driver = await new Builder().forBrowser("MicrosoftEdge").build();
const URL = "https://www.google.com/";
driver.get(URL);
driver.manage().window().maximize();
driver.close();
driver.quit();
}
example();
you can download the edge webdriver fromhttps://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Then you can unzip it and copy the msedgedriver.exe file into your project root
or you can configure it in environment variables.
This should be fine

Plain text SASL authentication in gremlin-javascript

I'm trying to connect to a Gremlin server with the JavaScript driver variant.
Up to package version 2.7.0, this is done easily by passing options to Gremlin.createClient() as in this example for Azure Cosmos DB:
const client = Gremlin.createClient(
config.port,
config.endpoint,
{
"session": false,
"ssl": true,
"user": `/dbs/${config.database}/colls/${config.collection}`,
"password": config.primaryKey
}
);
In newer versions of the package I can't get it done. The official docs suggest using gremlin.driver.auth.PlainTextSaslAuthenticator. However, that method seems to be not implemented in the package and returns TypeError: Cannot read property 'PlainTextSaslAuthenticator' of undefined
My test code (same config.js as in the working example):
const gremlin = require("gremlin");
const config = require("./config");
const Graph = gremlin.structure.Graph;
const DriverRemoteConnection = gremlin.driver.DriverRemoteConnection;
const graph = new Graph();
const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(
`/dbs/${config.database}/colls/${config.collection}`,
config.primaryKey
);
const g = graph.traversal().withRemote(new DriverRemoteConnection(`ws://${config.endpoint}:${config.port}`, { authenticator });
Return:
C:\repos\gremlin-test\index.js:9
const authenticator = new gremlin.driver.auth.PlainTextSaslAuthenticator(
^
TypeError: Cannot read property 'PlainTextSaslAuthenticator' of undefined
at Object.<anonymous> (C:\repos\gremlin-test\index.js:9:47)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
Anyone know a solution to this?
I've not got too much experience with Gremlin.js, but I just downloaded it and have manually searched through all of its files - I can't find any trace of a PlainTextSaslAuthenticator function or its declaration.
This could mean one of two three -
Its function has been (accidentally) removed
It uses a third party package that has been (accidentally) removed
It has not been added to the package yet
Upon a swift Google search, I found this link which seems to show it being added to /lib/driver/auth, but that directory doesn't seem to exist in the package I got through npm install gremlin. Perhaps it is yet to be released?
I would therefore suggest you raise an issue on Github, but it seems that repository you linked doesn't allow for issues to be raised. So perhaps email/contact the author?
EDIT:
Thanks to Stephen for the link - the code hasn't been merged to the package yet. Keep track of it here.

alternative to 'new Image()' of browser implementation into node-webgl javascript implementation?

Currently I am using a webGL based browser implementation code at client end. It is working perfectly. But, I want to use the same code at server end. Yes, this is not browser based, pure javascript code using node-webgl library.
While doing thisI am facing a problem.
new Image() is identified by browser, but at server side I am getting error Image is not defined. Below is the error I have attached. There are also additional two errors I am looking into it.
C:\Users\z003npra\Desktop\node>node exp.js
Status: Using GLEW 1.13.0
Linking ./simple.vert+./simple.frag
------------
Vertex info
-----------
(0) : error C5145: must write to gl_Position
Linking ./raycast.vert+./raycast-color.frag
------------
Vertex info
-----------
(0) : error C5145: must write to gl_Position
undefined:346
gl.tf_img = new Image();
^
ReferenceError: Image is not defined
at initTexture (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp.js:1
5:9), <anonymous>:346:18)
at volumerc_main (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp.js
:15:9), <anonymous>:392:2)
at Object.<anonymous> (C:\Users\z003npra\Desktop\node\exp.js:17:1)
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)
at node.js:974:3
I tried another method installing canvas i.e npm install canvas and access it's Image object element: However, I am getting other error, looks like it is not compatible. At start I have defined
var Canvas1 = require('canvas')
, Image = Canvas1.Image;
The error is below,
C:\Users\z003npra\Desktop\node>node exp.js
Status: Using GLEW 1.13.0
Linking ./simple.vert+./simple.frag
------------
Vertex info
-----------
(0) : error C5145: must write to gl_Position
Linking ./raycast.vert+./raycast-color.frag
------------
Vertex info
-----------
(0) : error C5145: must write to gl_Position
C:\Users\z003npra\Desktop\node\node_modules\node-webgl\lib\webgl.js:806
throw new TypeError('Expected texImage2D(number target, number level, numb
er internalformat, number format, number type, Image pixels)');
^
TypeError: Expected texImage2D(number target, number level, number internalforma
t, number format, number type, Image pixels)
at Object.texImage2D (C:\Users\z003npra\Desktop\node\node_modules\node-webgl
\lib\webgl.js:806:13)
at handleLoadedTexture (eval at <anonymous> (C:\Users\z003npra\Desktop\node\
exp.js:15:9), <anonymous>:330:5)
at gl.tf_img.onload (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp
.js:15:9), <anonymous>:349:3)
at Image.src (C:\Users\z003npra\Desktop\node\node_modules\canvas\lib\image.j
s:30:17)
at initTexture (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp.js:1
5:9), <anonymous>:351:16)
at volumerc_main (eval at <anonymous> (C:\Users\z003npra\Desktop\node\exp.js
:15:9), <anonymous>:392:2)
at Object.<anonymous> (C:\Users\z003npra\Desktop\node\exp.js:17:1)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
Any other alternative to imitate the Image type in node-webgl based implementation?
Use Image from node-webgl library: var Image = require("node-webgl").Image;

Node.js Cannot find module 'tcp'

node is crashing at the following line:
var tcp = require('tcp'),
error text:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'tcp'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at Object.<anonymous> (C:\Program Files\nodejs\websocket\websocket.js:11:11)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Module.require (module.js:357:17)
What is the problem? I found the source on the Internet, and the author, and the visitors also can run it...
Try require('net') instead:
$ node
> var tcp = require('tcp');
The 'tcp' module is now called 'net'. Otherwise it should have a similar interface.
> var tcp = require('net');
> $
Others are able to run, may be because they are using Node module when 'tcp' was there...
Now its called 'net', but its all the same thing no need of checking..
If you want to cross check for your more information, here are the links:
1.http://nodejs.org/api/net.html
2.https://github.com/joyent/node/blob/master/lib/net.js

Categories