Getting some message while configure the hub in the command prompt - selenium

I am trying to configure hub in the command prompt but getting the following message:
C:\Users\shubham.saraf\Documents\IST\IST\Software>java -jar selenium-server-4.5.0.jar - port 4444 -role hub
Selenium Server commands
A list of all the commands available. To use one, run java -jar selenium.jar commandName.
completion Generate shell autocompletions
distributor Adds this server as the distributor in a selenium grid.
hub A grid hub, composed of sessions, distributor, and router.
info Prints information for commands and topics.
node Adds this server as a Node in the Selenium Grid.
router Creates a router to front the selenium grid.
sessionqueue Adds this server as the new session queue in a selenium grid.
sessions Adds this server as the session map in a selenium grid.
standalone The selenium server, running everything in-process.
For each command, run with --help for command-specific help
Use the --ext flag before the command name to specify an additional classpath
to use with the server (for example, to provide additional commands, or to
provide additional driver implementations). For example:
java -jar selenium.jar --ext example.jar;dir standalone --port 1234
Can anyone suggest me to configure hub?

Related

Host header or origin header is specified and is not localhost for selenium grid

I am trying to set up a selenium grid using the latest chrome and chromedriver. I get the following error when trying to run a test
Message: OpenQA.Selenium.WebDriverException : Unexpected error. Host header or origin header is specified and is not localhost.
On the node machine, I see the chrome browser open, but then it immediately closes and I get this error:
[1557513678.682][SEVERE]: Rejecting request with host: <hub_IP_address>:4444
Has anyone had this issue using the selenium grid? I am using:
selenium-server-standalone-4.0.0-alpha-1.jar and
Chromedriver 74.0.3729.6 for windows
My Chrome browser was running v.74.0.3729.108
JDK 12.0.1.0
Here is my command for starting the hub:
java -jar selenium-server-standalone-4.0.0-alpha-1.jar -role hub -hubConfig config.json
Here is my command to start a node:
java -Dwebdriver.chrome.driver="C:\...\Browsers\ChromeDirectory\chromedriver.exe" -Dwebdriver.ie.driver="C:\...\Browsers\IEDirectory\x86\IEDriverServer.exe" -jar -Dwebdriver.edge.driver="C:\...\Browsers\Edge\MicrosoftWebDriver.exe" -jar "C:\...\selenium-server-standalone-4.0.0-alpha-1.jar" -role node -hub "http://<hub_IP_address>:4444/grid/register/" -nodeConfig "C:\...\config.json"
I tried using a "host" property in the config.jsons. I tried putting the actual IP address and just localhost. But the hub and the node are obviously different machines, so putting localhost makes it so they can't connect. But when I dont have localhost, it says it needs to be specified as localhost? I'm so confused!! What is supposed to go in the host property?
I have seen people talk about a loopback property for protractor but I am not using protractor. I tried putting "loopback":true into both my node and hub config.json files but it doesn't seem to make a difference.
UPDATE:
I was able to get the grid to run successfully using the 4.0 alpha jar for the hub, and the old 3.8 jars for the nodes. All Still on Java 8. Kind of interesting.
You can try to add these switches: --whitelisted-ips --allowed-origins=''*
Try to run your node with command:
java -Dwebdriver.chrome.driver="C:\...\Browsers\ChromeDirectory\chromedriver.exe --whitelisted-ips --allowed-origins='*'" -Dwebdriver.ie.driver="C:\...\Browsers\IEDirectory\x86\IEDriverServer.exe" -jar -Dwebdriver.edge.driver="C:\...\Browsers\Edge\MicrosoftWebDriver.exe" -jar "C:\...\selenium-server-standalone-4.0.0-alpha-1.jar" -role node -hub "http://<hub_IP_address>:4444/grid/register/" -nodeConfig "C:\...\config.json"
I was able to get the selenium grid working by downgrading to 3.8.1 selenium grid jar and installing JDK 8 instead of 12. The reason I needed to get java 8 is answered in this other question. I used the same chrome driver and start up commands

Unavailable Selenium node for Internet Explorer

This problem is making me crazy. I'll try to explain it.
I have a Selenium grid environment with two machines (HUB & NODE). I use .bat files to start the hub and the nodes, something like the code below:
HUB:
Here I start the hub:
start java -jar C:\workspace\selenium-server-standalone-2.45.0.jar -role hub -port 4444
Here I start a .bat on the node machine that will start the node.
psexec.exe \\XXX.XXX.XX.XXX -s -e -u USER -p PASSWORD -i 2 C:\Selenium\StartNode.bat
NODE:
To register the node:
java -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role node -hub http://XXX.XXX.XX.XXX:4444/grid/register
I have this from the beginning (more or less 6 moths) and was fine and simple, but now I see very weird (for me) things but only in Internet Explorer. Basically, the node starts, IE opens to correct page but nothing happens. I just have "object not found errors..." Firefox and Chrome are just fine.
But, if I start the node directly on it (NODE machine, so not from HUB via psexec), it works fine for IE as well?
Do you guys have any logical explanation? I really have no idea.
I suppose you need to provide IEDriver exe when starting the node like below.
java -jar selenium-server-standalone-2.45.0.jar -role webdriver -hub http://192.168.1.100:4444/grid/register -browser browserName="internet explorer",version=10.0,platform=WINDOWS -Dwebdriver.internetexplorer.driver=c:\Selenium\InternetExplorerDriver.exe
Try to create node using such command:
java -Dwebdriver.ie.driver=C:\selenium\IEDriverServer.exe -jar C:\selenium\selenium-server-standalone-2.45.0.jar -role node -nodeConfig C:\selenium\nodeIE1.json
I used node instead webdriver (the last one is used for backward compatibility) and latest version of IEDriverServer
It works great for me. And you may try nssm to run your hub and node as win services instead using .bat files.

Jenkins & TestNG start browsers

Is it possible to make Jenkins use actual browser instead of headless browser? I a running some tests written in TestNG (using Selenium webdriver). When I run the testng.xml file in Eclipse, the browser starts and the tests run. But when I use Jenkins and run the tests with maven, it doesn't start any browsers.
If your jenkins is hosted in a Windows machine, there are some special configurations you should know about services that are allow to use the interface.
By the way, the easiest way to see the browsers running is starting jenkins using the command line:
java -jar jenkins.war
In linux you could use the same command or use xvfb plugin to run browsers in background.
Hope helps
In addition to this, the main reason for not launching the browser is JNLP (java network launch protocol) , when we execute the war we can interact with the desktop applications.
Using Selenium Grid will allow you to execute the test on Jenkins but open the browser on a remote slave.
To achieve this you need to create an instance RemoteWebdriver than ChromeDriver, IEDriver etc I
For linux. If jenkins is running as a daemon, you could specify active display to connect to and run your browser on it. Check what display you could connect to:
ps e | grep -Po " DISPLAY=[\.0-9A-Za-z:]* " | sort -u
My output is:
DISPLAY=:10.0
DISPLAY=:2
DISPLAY=:2.0
Then go to your jenkins project -> Configure -> Build and add the next string above your main build configuration through "Add build step -> Execute shell"
/bin/bash -c "export DISPLAY=:10"
Edited: I've encountered the issue again recently. To resolve it:
I've given for the jenkins' user ability to interact with the desktop of my current user:
xhost +si:localuser:jenkins
so if I connect to my linux system through ssh using jenkins' user credentials, export display of my current user (export DISPLAY=:10) and run, for example google-chrome or firefox inside of putty's terminal, they are launching on my current user's desktop.
After this I've checked If I could start "mvn test" command inside of workspace/MyTests folder from my putty so it will start browser and execute tests.
At the end I've created simple script in the root of my current user:
vi ~/.startup.sh
#!/bin/bash
xhost +si:localuser:jenkins
and added it to my Xfce4 GUI: Application -> Settings -> Session and Startup -> Application Autostart, specifying command field as:
sh -c $HOME/.startup.sh
It's because of this script should work only when desktop is loaded to share my current user's display with jenkins' user. After reboot and connecting to this server through RDC desktop loads with xhost command applied. And after this jenkins could interract with desktop even when I close the RDP connection but leaving current user's session alive.
I've removed Build step in my jenkins' project configuration that was stated "Invoke top-level Maven targets". It could not start my browsers.
I've changed my "Add build step -> Execute shell" to:
export DISPLAY=:10
cd /var/lib/jenkins/workspace/MyTests
mvn test
I've tried grid also, turning selenium-server-standalone -hub and -node into daemons. But it was slower than launching browsers with WebDriver in the such way.

Jenkins stops at Launching Internet Explorer

we are using Jenkins as CI in our project. We were running the CI from the command line using the following command
java -jar C:\\jenkins\\jenkins.war --httpPort=8085 --ajp13Port=8009
As the system needs to restart frequently, we change CI to start as a windows service.
Now we are facing the issues for Selenium test cases. Selenium test cases are not running after we make Jenkins as service. We are getting the following log and no more progress from that point
18:36:30,718 INFO [org.openqa.selenium.server.SeleniumDriverResourceHandler] Command request: getNewBrowserSession[*iexploreproxy, http://192.168.132.105:8080/, ] on session null
18:36:30,718 INFO [org.openqa.selenium.server.BrowserSessionFactory] creating new remote session
18:36:30,796 INFO [org.openqa.selenium.server.BrowserSessionFactory] Allocated session 80b95d0273ac4ea4a82860c79438f071 for http://192.168.132.105:8080/, launching...
18:36:30,796 INFO [org.openqa.selenium.server.browserlaunchers.WindowsProxyManager] Modifying registry settings...
18:36:31,781 INFO [org.openqa.selenium.server.browserlaunchers.InternetExplorerCustomProxyLauncher] Launching Internet Explorer...
Per hudson wiki, you should be running Hudson (or jenkins) as tasks rather than service for GUI testing. Check here. Look at the section GUI Testing in Windows
Following changes will resolve the problem
Update the selenium version.
Use *iexploreproxy or *piiexplore for IE instead of *iehta/*iexplore

Selenium - When running builds via the grid, how do you get the console output?

We've been running Selenium tests via local RC for a few years, and are starting to migrate to the grid. We have been redirecting the console output of the server to our own test logs. It is quite useful for debugging. The console output looks suspiciously like Log4J - so it should be reconfigurable.
10:31:51.894 INFO - Command request: open[http://websiteundertest/IsSiteUpUp.aspx, ] on session 46c211b412474429957dbf6bebccd64d
10:31:55.323 INFO - Got result: OK on session 46c211b412474429957dbf6bebccd64d
10:31:56.330 INFO - Command request: isElementPresent[xpath=//h2, ] on session 46c211b412474429957dbf6bebccd64d
10:31:56.343 INFO - Got result: OK,true on session 46c211b412474429957dbf6bebccd64d
When re run via the hub, the console output appears only on the remote RC. The simple console redirection won't work. In scope of this question, we need to capture the remote console output someplace where the computer executing the test can get to it. We run our tests from a number of build agents via C#. We are trying grid 1 and 2. We intend to go directly to Grid 2.x.
What he meant was that this:
java -jar selenium-server-standalone-2.15.0.jar -role webdriver -hub http://127.0.0.1:4444/grid/register > mylog.txt
does not work. It will create a new file but it will be empty. I suggest using -log mylog.txt
argument when starting node or server to store log files
In the latest version of Grid, you can redirect the output when you start each of your client nodes:
java -jar selenium-server-standalone-2.15.0.jar -role webdriver -hub http://127.0.0.1:4444/grid/register > mylog.txt
This is a Windows example. You can also centralize log files on some remote server by referencing a \\serverName\mylog.txt in your redirect.
When you say:
The simple console redirection won't work...
I'm not sure I understand.