How do I set a Selenium node's id with Selenium Grid Extras/json config files? - selenium

I'm in the process of converting our Selenium Grid to use Selenium Grid Extras, which so far is looking great! But I'm having an issue where, before, our nodes would be represented by their machine name in the grid console (e.g. id : http://SELENIUMXX:5555, OS : WINDOWS), but now are only represented by their IP address (e.g. id : http://x.x.x.x:5556, OS : WINDOWS). Since the former are much easier to read, I'd like to know how to set the node ID attribute using SGE/json config files. The bat files for opening the nodes themselves are all dynamically constructed from the config files by SGE, so I can't set ID there.
I have a "friendlyHostName" parameter that it passes in, but that's only displayed in the console if you click over to the configuration tab.

You should find a node configuration file in the directory wherein you downloaded the Selenium Grid Extras jar. Open up that JSON file and add an attribute
"host": "MyMachineNameGoesHere"
under the key "configuration"
I decided to give Selenium Grid extras a whirl and here's how my complete node configuration file looks like
{
"capabilities": [
{
"seleniumProtocol": "WebDriver",
"browserName": "chrome",
"maxInstances": 3,
"version": "52",
"platform": "MAC"
}
],
"configuration": {
"proxy": "com.groupon.seleniumgridextras.grid.proxies.SetupTeardownProxy",
"maxSession": 3,
"port": 5555,
"register": true,
"unregisterIfStillDownAfter": 10000,
"hubPort": 4444,
"hubHost": "127.0.0.1",
"host": "dragonlair.local",
"nodeStatusCheckTimeout": 10000,
"downPollingLimit": 0
},
"loadedFromFile": "node_5555.json"
}

Went round and round on this with Selenium 3.141, trying to get json file to work. Then stumbled on solution...
Problem: My Selenium 3.x "Grid Console" is not displaying the "id" (unique node name) that I specify in the json config file.
Solution: Don't use the json config file. Instead, place "-id nodeName" in the commandline.
Example:
java.exe -jar /pathToJar/selenium-server-standalone-3.141.59.jar -id
MyNodeName -role node -nodeConfig /pathToMyConfig/nodeConfig.json
Where "MyNodeName" is whatever unique name you want the Grid Console (website) to show your Selenium node as (instead of the default IP address).
Summary: In your command line, use "-id EnterNodeNameHere".
Don't know whether order matters...but I put -id before -role parm.

I found a general way to do it so you don't have to change each one manually. In your config directory, set up a master node config file, with a "host": "HOSTNAME", line in the configuration per Krishnan Mahadevan's answer, and then run this batch file:
#echo off
set str1= "host": "HOSTNAME",
set str2= "host":
set inputfile=node_master.json
set outputfile=[YOUR OUTPUT FILE]
for /d %%v in ("*") do (
COPY %inputfile% %%v
cd %%v
>"%outputfile%" (
for /f "usebackq delims=" %%A in (%inputfile%) do (
if "%%A" equ "%str1%" (echo %str2% "%%v",) else (echo %%A)
)
)
del %inputfile%
cd ..
)

Related

Opening a new WSL2 tab in Windows terminal and executing command

I'm using WSL2 on Windows terminal. I have an app that needs front end and backend booted before it can be used, so every time I nave to open a terminal window, navigate to a folder and run a command.
I would like to set an alias that would open a new tab, navigate to a folder and do go run .
I saw suggestions for linux, but none of those work on Windows Terminal with WSL2. Anyone have experience with this setup?
You could create a profile for this. Something like
{
"commandline": "wsl.exe -d Ubuntu ping 8.8.8.8",
"name": "backend",
"startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\project",
},
(of course, replace ping 8.8.8.8 with the actual command you want to run, replace Ubuntu with the name of the distro you're using, and replace home\\zadjii\\path\\to\\project with your actual path, delimited by double-backslashes.)
Now, if you wanted to get really crazy, you could create an action in the Command Palette which opened up multiple commands all at once:
{
"name": "Run my project",
"command": {
"action": "multipleActions",
"actions": [
// Create a new tab with two panes
{ "action": "newTab", "tabTitle": "backend", "commandline": "wsl.exe -d Ubuntu run_my_backend", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\backend" },
{ "action": "splitPane", "tabTitle": "frontend", "commandline": "wsl.exe -d Ubuntu run_my_frontend", "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\zadjii\\path\\to\\frontend" },
]
}
}
see multipleActions

Windows Terminal profile not showing up

I've just installed WSL2 and am using the Windows Terminal on Win10 1909 (18363.1256). I'm trying to set up 2 different profiles, one that launches a local WSL2 Ubuntu shell, and one that launches another WSL2 shell that will automatically ssh to a specific host.
The local one works great, shows up without an issue, however I can't seem to get my 2nd profile to show up in the list of profiles.
My settings.json looks like this:
"profiles":
{
"defaults":
{
// Put settings here that you want to apply to all profiles.
"colorScheme": "One Half Dark",
"fontFace": "JetbrainsMono NF",
"fontSize": 11
},
"list":
[
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu/home/sensanaty",
"tabTitle": "WSL2"
},
{
"guid": "{15c5814b-7ed1-4cec-bc64-d165274958fa}",
"hidden": false,
"name": "External Host",
"source": "Windows.Terminal.Wsl",
"commandline": "ssh example#123.456.7.89",
"tabTitle": "External Host"
},
]
},
With the above, I only get the Ubuntu profile in my list
I thought maybe it was the guid generated or something, but I just did a simple uuidgen and pasted it into the json so it shouldn't really be causing any issues there. I've also obviously tried restarting my system, to no avail. The default profiles show up fine if I disable the option to stop auto-generating them, as well.
Any clue as to what might help me out?
The 'source' attribute is for dynamically generated profiles, for which WSL will create one for each instance installed. You can't control the command line for these dynamically generated profiles. What you need is for your new profile to extend the command line to tell Terminal to use WSL. Remove the 'source' attribute entirely, so that your new profile is static.
In your case, that should be ...
{
"guid": "{15c5814b-7ed1-4cec-bc64-d165274958fa}",
"hidden": false,
"name": "External Host",
//"source": "Windows.Terminal.Wsl",
"commandline": "wsl.exe ssh example#123.456.7.89",
"tabTitle": "External Host"
}//,
As bwolfbarn mentioned, you should also ditch that trailing comma if it really comes at the end of the "list" block.
Here are a few lines from mine as additional examples as well ...
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu 20.04 WSL2 tmux",
//"source": "Windows.Terminal.Wsl",
"commandline": "wsl.exe -d Ubuntu -e sh -c \"/usr/bin/tmux has-session -t main 2>/dev/null && /usr/bin/tmux attach-session -d -t main || /usr/bin/tmux -2 new-session -t main -s main -c ${HOME}\"",
"cursorShape": "filledBox"
},
{
"guid": "{4e04fa7e-76c7-4746-a322-a227e70dde6c}",
"hidden": false,
"name": "Ubuntu 20.04 WSL1 tmux",
//"commandline": "wsl.exe -d Ubuntu20.04_WSL1",
"commandline": "wsl.exe -d Ubuntu20.04_WSL1 -e sh -c \"/usr/bin/tmux has-session -t main 2>/dev/null && /usr/bin/tmux attach-session -d -t main || /usr/bin/tmux -2 new-session -t main -s main -c ${HOME}\"",
"cursorShape": "filledBox"
}
Note that you could, I believe, use "wsl.exe -e" (a.k.a. --execute), but it's not really necessary in your case.
If you want to see your "source": "Windows.Terminal.Wsl" in Windows Terminal Menu it must exist in the registry
[HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Lxss\{UUID}]
(The registry UUID is not related to Windows Terminal UUID).
This registry entry can be created by running "wsl --import" or by cloning existing entry (if you are comfortable messing with the registry).
If you still don't see your profile after confirming that the registry entry exists, remove all entries for "generatedProfiles" in state.json file located in the same folder as settings.json. This will force Windows Terminal to update state.json. If you generated Windows Terminal profile UUID yourself, it may ignore it and create its own one. In this case you will see duplicate entries for the profile in settings.json. Remove the ones that were generated manually, and leave the one generated by the terminal.
At least the last comma should be removed (I commented it in your example) as the element "External Host" is the last of the list.
[
{
"guid": "{2c4de342-38b7-51cf-b940-2309a097f518}",
"hidden": false,
"name": "Ubuntu",
"source": "Windows.Terminal.Wsl",
"startingDirectory": "//wsl$/Ubuntu/home/sensanaty",
"tabTitle": "WSL2"
},
{
"guid": "{15c5814b-7ed1-4cec-bc64-d165274958fa}",
"hidden": false,
"name": "External Host",
"source": "Windows.Terminal.Wsl",
"commandline": "ssh example#123.456.7.89",
"tabTitle": "External Host"
}//,
]

Selenium Grid 3 node startup ignoring -nodeconfig node.json

I'm just setting up a new Selenium Grid, and have just one node to register to my hub at the moment. Both hub and node running on CentOS 7. I have two different versions of Firefox on my node, and no other browser, as I will be setting up different nodes for different browser types.
If I start the node completely from the command line, specifying the different Firefox versions and locations, it all registers and starts properly. On the Grid console page I see my node with the two versions of Firefox, 3 instances of each, correctly detailed with the version numbers I'm specifying. This is the command line I use:
java -jar selenium-server-standalone.jar -role node -hub http://xx.xx.xx.xx:4444/grid/register -browser browserName=firefox,version=50.1.0,maxInsfirefox_binary=/opt/firefox-50.1.0/firefox,maxInstances=3,platform=LINUX -browser browserName=firefox,version=51.0.1,firefox_binary=/opt/firefox-51.0.1/firefox,maxInstances=3,platform=LINUX
If however I try using a .json config file to specify my parameters, the java startup completely ignores the config file and starts up using defaults; on the Grid console page it shows 5 Firefox sessions, 1 IE and 5 Chrome, and none of the Firefox sessions show the versions I'm specifying. This is the command line invoking the json file:
java -jar selenium-server-standalone.jar -role node -hub http://xx.xx.xx.xx:4444/grid/register -nodeConfig /opt/selenium/node.json
... and this is the node.json file itself:
{
“capabilities”:
[
{
"browserName": firefox,
"firefox_binary": "/opt/firefox-50.1.0/firefox",
"maxInstances": 3,
"platform": LINUX,
"version": 50,
"seleniumProtocol": WebDriver
},
{
"browserName": firefox,
"firefox_binary": "/opt/firefox-51.0.1/firefox",
"maxInstances": 3,
"platform": LINUX,
"version": 51,
"seleniumProtocol": WebDriver
},
],
“maxSession”: 5,
“port”: 5555,
"hub": "http://xx.xx.xx.xx:4444",
“register”: true,
"registerCycle": 5000,
"nodeStatusCheckTimeout": 5000,
"role": node,
"cleanUpCycle": 2000
}
I have tried putting all parameters encased in double quotation marks, in case that was the issue; made no difference.
Any clues why the parameters in my node.json file are being ignored, please?

Setting the Firefox profile when using Selenium and Firefox Portable

I'm in a setup, in which I need to use Firefox Portable 38.7.1 for my Selenium tests (version 2.53.0). Everything works fine, but now I need to configure a proxy.
I configured it in the default profile (it gets saved in ${FF_PORTABLE_PATH}/Data/profile/prefs.js)
user_pref("network.proxy.http", "proxyHost");
user_pref("network.proxy.http_port", proxyPort);
user_pref("network.proxy.share_proxy_settings", true);
user_pref("network.proxy.ssl", "proxyHost");
user_pref("network.proxy.ssl_port", 51854);
user_pref("network.proxy.type", 1);
...
When starting the browser manually, this works fine. However, when triggered by Selenium an anonymous profile is created and used, which doesn't have my proxy settings.
I tried to specify the profile when starting the node.
At first I tried using -Dwebdriver.firefox.profile:
java -jar selenium-server-standalone-2.53.0.jar -role node -Dwebdriver.firefox.profile=default
Then I tried to use the default profile as a template using -firefoxProfileTemplate:
java -jar selenium-server-standalone-2.53.0.jar -role node -firefoxProfileTemplate "${FF_PORTABLE_PATH}/Data" -nodeConfig ...
I also created a new profile (using the ProfilistPortable plugin) and specified it on startup of the node (with the webdriver.firefox.profile-parameter).
In all cases the Selenium node opens up Firefox Portable with a "clean" anonymous profile without my proxy settings.
Can anyone help me how to get this setup working with Firefox Portable? I don't really need separate profiles. As long as I can force Selenium to use a profile, which has the proxy configured, I'm fine.
Here's my nodeConfig:
{
"capabilities": [
{
"browserName": "firefox",
"version": "38.7.1",
"firefox_binary": "${FF_PORTABLE_PATH}\\FirefoxPortable.exe",
"platform": "WINDOWS",
"maxInstances": 1,
"seleniumProtocol": "WebDriver"
}
],
"configuration": {
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 1,
"port": 5550,
"host": "ip",
"register": true,
"registerCycle": 5000,
"hubHost": "localhost",
"hubPort": 4440
}
}
I use ${FF_PORTABLE_PATH} in the examples above. In reality this (fully qualified) path is hardcoded in all my settings.
I had the same issue. Digging into selenium code I was able to find a solution.
FirefoxBinary binary = new FirefoxBinary(new File(portablePath.trim()));
File profile_dir = new File(portablePath.trim().replace("FirefoxPortable.exe", "/Data/profile"));
fp = new FirefoxProfile(profile_dir);
dc.setCapability(FirefoxDriver.PROFILE, fp);
driver = new FirefoxDriver( binary , fp, dc);

Sublime Text, SublimeREPL, Clojure & Windows 8

I've got both Leiningen & Clojure working on Windows 8 separately from Sublime Text (e.g. I can get a repl working in Windows PowerShell).
My problem is that I can't get the SublimeREPL working in SublimeText (the REPL loads up but doesn't then do anything). Are there any simple traps that I might be missing or, failing that, are there a series of steps I could follow to troubleshoot?
Please see this SublimeREPL issue for instructions on how I got a Clojure REPL to work, at least on XP (I haven't tried it on Win7 or 8 yet). Basically, I edited the menu file for Clojure, and changed the command from lein repl to lein trampoline run -m clojure.main, which for some reason did the trick. I also changed the path to $file so you can open up a REPL while your project.clj is the current tab in Sublime, and the REPL should inherit the project's settings.
For reference, the complete Packages/User/SublimeREPL/config/Clojure/Main.sublime-menu file (Packages is accessible via Preferences -> Browse Packages...) is as follows:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "r",
"id": "SublimeREPL",
"children":
[
{"caption": "Clojure",
"id": "Clojure",
"children":[
{"command": "repl_open",
"caption": "Clojure Trampoline",
"id": "repl_clojure",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": {"windows": ["lein.bat", "trampoline", "run", "-m", "clojure.main"],
"linux": ["lein", "repl"],
"osx": ["lein", "repl"]},
"soft_quit": "\n(. System exit 0)\n",
"cwd": {"windows":"$file_path",
"linux": "$file_path",
"osx": "$file_path"},
"syntax": "Packages/Clojure/Clojure.tmLanguage",
"external_id": "clojure",
"extend_env": {"INSIDE_EMACS": "1"}
}
},
{"command": "clojure_auto_telnet_repl",
"id": "repl_clojure_telnet",
"caption": "Clojure-Telnet"}]}
]
}]
}
]
I solved this problem with Git Bash Shell. I have used the shell script version of leiningen instead of lein.bat
This is the command I use:
["C:\\Program Files\\Git\\bin\\sh.exe", "-l", "--", "/d/lein.sh", "repl"]
assuming lein.sh is in d:\
lein trampoline command sometimes behaves differently from lein repl and could fail due to unknown reasons.