How to change selenium-standalone port number via webdriverio wdio file? - javascript

I need to change the port number of which selenium standalone server is using by default (4444). Port 4444 is currently in use, is there a way to alter the port number via the wdio file?
// Test runner services
// Services take over a specific job you don't want to take care of. They enhance
// your test setup with almost no effort. Unlike plugins, they don't add new
// commands. Instead, they hook themselves up into the test process.
services: ['selenium-standalone'],
Currently I'm starting selenium server via the following command:
./node_modules/.bin/selenium-standalone start
I have also attempting to use the following with no luck:
./node_modules/.bin/selenium-standalone start -port 7777
Running the above command still attempt to run selenium sever on port 4444.

To run the selenium-standalone on the specific port you should use the following syntax:
./node_modules/.bin/selenium-standalone start -- -port 7777
Change the port in the wdi.conf.js:
seleniumArgs: {
seleniumArgs: ["-port", "7777"],
},
Also, read more about the wdio configuration file here and about wdio-cli here
So, your final wdio.conf.js should look like:
exports.config = {
/**
* server configurations
*/
services: ['selenium-standalone'],
port: 7777,
seleniumArgs: {
seleniumArgs: ["-port", "7777"],
},
}

nodejs webdriver-manager start --seleniumPort 5555

Related

How to know from which file/dir(package) nodejs(node.exe) running on windows

Suppose multiple node package/file running multiple node server on windows machine.
So, I need all the information (complete path of the node package/file, port, host, pid, ppid ) of the file from node server is working/running(node.exe) on the machine.
Example: Two node.exe running on the machine. both are running from the different different destination (first from "C:\Users\kuldeep.singh\Desktop\porting\v1\node1\index.js" and another from "C:\Users\kuldeep.singh\Desktop\porting\v2\node2\index.js") with different-different PPID.
I want to filter the only node process with the path of the destinations from the node process got started.
I am getting all the details like :
[ { port: 3400,
pid: 27200,
ppid: 27168,
name: 'node.exe',
cmd: 'node index.js',
bin: 'C:\\Program Files\\nodejs\\node.exe' } ]
But I am unable to get the destination path like ("C:\Users\kuldeep.singh\Desktop\porting\v1\node1\index.js") from which node.exe file got run.
Currently, I am using path and find-process node module.
Please consider the windows machine while providing the solution.
try to check __filename or __dirname
https://nodejs.org/api/modules.html#modules_filename
By using the below code you can find the directory/ file
console.log(__filename);
console.log(__dirname);

keep getting "? Something is already running on port 3000" when I do npm start on react app

I keep on getting "? Something is already running on port 3000" message in my terminal when I start up my react server when there is absolutely nothing running on my port 3000
What I have tried to solve with:
Restart the macOS.
checking my "http://localhost:3000" on chrome browser. (Nothing: This site can’t be reached)
Go to chrome://serviceworker-internals and chrome://appcache-internals, search for localhost:3000 (Nothing found)
I also tried almost every command lines I found on Google regarding this issue
I also created another express.js app, and it was successfully launch on port 3000 while React said there is something running on 3000. React on my computer just keeping thinking there is something running on port 3000.
If you are a windows user you can try using
npx kill-port 3000
in your console. I was having the same problem and it worked for me.
Not sure about MAC.
Open cmd and write this
netstat -a -o -n
You will get list of active connections then find 3000 by hitting
Cntrl + f
Copy the PID of that port and hit this command
taskkill /F /PID PID_of_port
Edit
This guide is for windows.
Kill Node.Js process from Task Manager.
Step 1: Open Task Manager by clicking ctrl+shift+delete
Step 2: Open Prcesses tab
Step 3: Search for Node.JS process and right click on that then click on End Task
Step 4: Now you can start again.
As #khurram khan suggested terminating the process may be the best option for you, This work for me on linux:
$ lsof -i tcp:3000
$ kill -9 PID
the first command should give you the PID number to enter in the second command as PID.
I had this problem on Mac and I solved by running:
npx kill-port 3000
I had stuck with this one for few hours, and the end I had found the solution
There was incorrect mapping to the local host in the hosts file and didn't had any relation to the port taken something like
10.2.224.130 localhost
Just Change it back to
127.0.0.1 localhost
Host file locations
https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
In case anyone comes across this and the above solutions didn't help, make sure your /etc/hosts has:
127.0.0.1 localhost
For some reason this was wiped from my hosts file and CRA's dependency for checking ports (detect-port-alt) checks localhost:[PORT] to see if it's available. If it errors out, you'll always get the "Something is already running..." error when checking a specific port but not when using a random port (since that's picked by the dependency).
kill node.js from the background processes. that would soleve the probelem. alterntively, you could restart your system
for window use this in package.json
"start": "set PORT=3006 && react-scripts start"
for Linux and MacOS
"start": "PORT=3006 react-scripts start"
This worked for me on windows pc. This one is for those are not seeing the port when you run this command netstat -a -o -n on your command prompt.
Open your command prompt in administrator mode and run this command
net stop winnat
you'll get this response:
The Windows NAT Driver service was stopped successfully.
Them you run this next:
net start winnat
then you will get this response:
The Windows NAT Driver service was started successfully.
once you do that. Start the react server and it would work. Same too if your backend server doesn't run on 3000
It's very simple. You can fix it in 2 easy steps.
Check your environment variables if there is a key/entry with name "PORT".
If found delete that entry or rename it to something else.
It turns out that some other program is using that variable. Usually when you start react-scripts it will look for an environment variable with that title PORT.
Date: Sat 07, October 2020
Windows: Microsoft Windows 10 Pro Build 19041
Node: 12.16.1
NPM: 6.14.8
Something similar was happening to me on my Windows machine. Tried a lot of things suggested here on StackOverflow and other places.
In my case, I was following a video course that was suggesting adding --script-version 1.1.5 (as illustrated below) when creating a new React app.
create-react-app app-name --scripts-version 1.1.5
Here's the package.json scripts versions:
React: 17.0.1
React DOM: 17.0.1
React Scripts: 1.1.5
After running the command npm start and typing y to try to use a different port, the terminal will stay stucked until it was canceled.
Then I created a new React app without --scripts-version 1.1.5 and after trying to running it, it was still running into Something is already running on port 3000 but after typing y, the app will run with no problem on a different port.
Here's the package.json scripts versions (when it was running successfully):
React: 17.0.1
React-Dom: 17.0.1
React-Scripts: 4.0.0
Starting with the reason you do not see anything on localhost:3000, is because there must be a proper webapp or a website/server running on that port, but the port:3000 is currently running some process, just not of a server/site/app.
This out of the way, depending on your type of OS, it is quite easy to check if there is in-fact a process on port:3000 or not. For MacOS, opening a terminal and running sudo lsof -i ':3000' will list the current process on port 3000.
Note that we need to run command as sudo or root
Once you see what process is running, note the PID and run kill -9 {PID}, which should kill the process with PID (i.e distruptive process on port:3000). Now doing a npm start should get your app built, compiled and served on localhost:3000
Mostly what might've happened is that you had a npm start running which you either interrupted, or closed in the foreground. Doing a fg in your terminal will open any background tasks, so if this opens a npm start instance, it was this process stopping your flow. You can then properly end the session making sure all processes on port:3000 are killed.
Happy coding
If you are on linux you can try
pkill -f node
to terminate the processs
The error occurs when a task is left running on the port properly killing it.
this error can occur on both ports. Your react app and your node server.
To solve this you can run the following commands.
netstat -anp tcp | grep 3000
This command in the terminal will give you the list of activities on port 3000
npx kill-port 3000
This command will kill all the running servers on port 3000.
Now if you have the same problem for your Node server. You can follow the same steps.
netstat -anp tcp | grep 5000
Then
npx kill-port 5000
You don't need the first command. it's just to list out the running activities on the port.
just change the port number for any other port number.
This is the output you get after running the commands.
I am using Git bash on windows.
For me, this works every time (macOS): sudo kill -9 $(sudo lsof -t -i:3000)
Simple and Easy solution
close your current terminal and open a new one.
If you are running it in VS Code just create a new terminal and delete the old one.
On React - you can run an already created React single-page application (SPA) by
npm start command.
That may start your locally hosting development server and runs your app at:
http://localhost:3000/ which is equivalent to: 127.0.0.1:3000 address
127.0.0.1 is the default localhost IP number while the default port number set by
create-react-app package is 3000.
When getting: “Something is already running on port 3000" failure error message you may think that the port captured by another process running on your machine but you’ll find that it is captured permanently as if it runs on 0.0.0.0:3000 address
Solution:
In your project libraries created by create-react-app script navigate to:
node_modules/react-scripts/scripts/start.js
While running npm start command - the start.js script is being called and executed
There at start.js file in you editor find the above line:
const HOST = process.env.HOST || '0.0.0.0';
and change it to:
const HOST = process.env.HOST || '127.0.0.1';
save and run your web app again at: http://localhost:3000/ or http://127.0.0.1:3000

How to execute a Node.js script on the server?

I'm beginning to learn web technologies and programming and I'm setting up my own local webserver. I have HTTPD, PHP, Python, MySQL all up and running on Windows. Now I want to add Node.js to the mix. I installed the Windows 64 bit installer. Now how do I begin? I have a basic Hello World script in a test.js file. But when I access this file in the browser it only displays as plain text. It's not executed. How to execute a Node.js script on the server?
Starting a node script is pretty simple. Just use your command line or terminal and execute the following command.
node /path/to/your/file.js
Doing so you'll start your node script. If you're going to start a server it's pretty much the same. Just keep in mind to define a server in your node file and start it. A simple server using express could look like this (You can also use a fully node way, this is just a simple example using express. You may check google for how to set up a simple node http server).
var express = require('express');
var app = express();
var port = 4000;
app.listen(process.env.port || port);
As you can see the specified port is set to 4000. You can simply adjust this by changing the value itself or passing in a node environment variable. To pass in an environment variable just start your server like this.
node port=3000 /path/to/your/file.js
This will finally pass the value of port to process.env.port which obviously will start your server on the port 3000.
you can use these packages to keep the file running so you won't have to login to server every time :-
forever
and you can just write :-
forever start app.js
nodemon
nodemon app.js
pm2
which is very useful , as it will auto restart your app when it crash or any error happens
pm2 start app.js
Your run your file: node server.js
Then it starts.
There should be specified in code on which port you run your server. Then it is accessible for example at http://localhost:3000/
As Quentin noted, I was thinking about "creating web server". Of course, you can run javascript code with Node.js without server. Then skip the part abot localhost, just use node test.js in console.

MongoDB disabled by default [duplicate]

I have to meteor application in local (admin and client). Applications run on different port 3000 and 3003. I want to use both app should use the same DB. export MONGO_URL=mobgodb://127.0.0.1:3001/meteor will be okay. But I would like to know any argument to pass with meteor command to setup environment variable to use the same DB.
If you are looking for a start script you could do the following:
In the root of your app, create a file called start.sh:
#!/usr/bin/env bash
MONGO_URL=mobgodb://127.0.0.1:3001/meteor meteor --port 3000
Then run chmod +x start.sh
You can then start your app just by typing ./start.sh

Spawning a child process with tty in node.js

I am trying to do some work on a remote server using ssh--and ssh is called on the local machine from node.js
A stripped down version of the script looks like this:
var execSync = require("child_process").execSync;
var command =
'ssh -qt user#remote.machine -- "sudo mv ./this.thing /to/here/;"';
execSync(command,callback);
function callback(error,stdout,stderr) {
if (error) {
console.log(stderr);
throw new Error(error,error.stack);
}
console.log(stdout);
}
I get the requiretty error sudo: sorry, you must have a tty to run sudo.
If I run ssh -qt user#remote.machine -- "sudo mv ./this.thing /to/here/;" directly from the command line--in other words, directly from a tty--I get no error, and this.thing moves /to/there/ just fine.
This is part of a deploy script where it really wouldn't be ideal to add !requiretty to the sudoers file.
Is there anyway to get node.js to run a command in a tty?
There's a few options:
If you don't mind re-using stdin/stdout/stderr of the parent process (assuming it has access to a real tty) for your child process, you can use stdio: 'inherit' (or only inherit individual streams if you want) in your spawn() options.
Create and use a pseudo-tty via the pty module. This allows you to create a "fake" tty that allows you to run programs like sudo without actually hooking them up to a real tty. The benefit to this is that you can programmatically control/access stdin/stdout/stderr.
Use an ssh module like ssh2 that doesn't involve child processes at all (and has greater flexibility). With ssh2 you can simply pass the pty: true option to exec() and sudo will work just fine.
ssh -qt user#remote.machine -- "sudo mv ./this.thing /to/here/;"
Per the ssh man page:
-t
Force pseudo-terminal allocation. This can be used to execute arbitrary
screen-based programs on a remote machine, which can be very
useful, e.g. when implementing menu services. Multiple -t options
force tty allocation, even if ssh has no local tty.
When you run ssh interactively, it has a local tty, so the "-t" option causes it to allocate a remote tty. But when you run ssh within this script, it doesn't have a local tty. The single "-t" causes it to skip allocating a remote tty. Specify "-t" twice, and it should allocate a remote tty:
ssh -qtt user#remote.machine -- "sudo mv ./this.thing /to/here/;"
^^-- Note
Some programs must be running tty. "child_process" library working bad when tty inputs.
I have tried for docker ( docker run command like ssh need tty), with microsoft node-pty library https://github.com/microsoft/node-pty
And this is worked me.
let command = "ssh"
let args = '-qt user#remote.machine -- "sudo mv ./this.thing /to/here/;"'
const pty = require("node-pty");
let ssh = pty.spawn( command , args.split(" ") )
ssh.on('data', (e)=>console.log(e));
ssh.write("any_input_on_runngin_this_program");
It seems that you can use FORCE_COLOR environment variable:
spawn('node', options, {
stdio: 'pipe',
cwd: process.cwd(),
env: {
...{ FORCE_COLOR: 1 },
...process.env
}
})

Categories