I want to run the selenium test cases in the remote machine.
These are the steps I have followed:
Steps I did in server machine:
I have downloaded selenium-server-standalone-3.9.1.jar + Chrome Driver & placed it in a folder and added it to $PATH environmental variable.
I have started selenium server using java -jar selenium-server-standalone-3.9.1.jar -role hub in the Terminal.
Steps I did in local machine:
I have installed selenium-webdriver & selenium-server-standalone-3.9.1.jar
I wrote a sample testcase using selenium webdriver.
I have started a node here using command java -jar selenium-server-standalone-3.9.1.ja-role node -hub http://172.24.111.70:4444/grid/register in the terminal. The node got connected to the hub.
I run the command node test.js in the terminal. I expect the chrome instance to open in the remote machine. But it is running in the local machine.
Screenshots:
Hub:(Remote)
Node:(Local)
Can you please explain me the mistake I have did here? Have I understood the concept wrong?
The web browser instance which will run your tests will get created on a node not the hub. The hub is how you can register a number of nodes so you can spread the load between different machines/nodes. From what I can tell, you have a hub on the remote machine which you connect a local node to.
What I think you want is to run the node on the remote machine also, registering to the hub on the same machine (you might have to change the IP address of the hub to localhost when registering the node).
So, the problem is you are wanting the tests to run on the Remote Machine, but they are running locally?
From the sounds of it you have done all the setup correctly, and the Hub/Nodes should be working fine. All you need to do, is instead of running the Node from your local machine, run it from the Remote Machine. You just need to think of the Hub as the Supervisor, who hands out work to the Nodes (their employees) to do. The Hub doesn't run any tests itself, it just sends the data to the Nodes and load balances between multiple Nodes.
We have a set up of 6 Remote Machines. Machine 1 has the Hub and a Node, and the other 5 have Nodes. In our project we are pointing towards the Hub, so when the tests run, they get sent there. The hub does the rest (depending on the nodecfg file and the settings you've got in there)
Related
So I'm trying to setup an automated build and test flow, with Jenkins and Selenium grid on a central EC2-instance and nodes on physical machines located at my office.
I don't have port forwarding available at my office.
So I was thinking that I could use a VPN (not a proxy) to connect the machines, as though they were on the same network.
So my setup is currently:
The hub (EC2) with Wireguard
java -jar selenium-server-4.7.2.jar hub --host 0.0.0.0 --allow-cors true --bind-host false
A linux-laptop node
java -jar selenium-server-4.7.2.jar node --hub http://<wireguard-hub>:4444 --host <wireguard-ip> --port 5555 --bind-host false
A windows desktop node
java -jar selenium-server-4.7.2.jar node --hub http://<wireguard-hub>:4444 --host <wireguard-ip> --port 5555 --bind-host false
The nodes are able to do a GET-request to the hub and get a proper json response and the hub is able to do the opposite. But the Selenium software get stuck on [NodeServer$1.lambda$start$1] - Sending registration event....
I've tried running all parties with --log-level FINEST, but all I see is that the hub isn't receiving the request. Both from linux and windows.
I've tried running both nodes as hubs too and they are able to connect to themselves, but not each other (through WireGuard).
So can anyone tell me why I can, but at the same time can't, connect my grid?
EDIT (4. jan 2022):
I have now tried running the node on the same EC2-instance with docker as the Webdriver and that doesn't work either.
The node starts, connects to docker and gets stuck at the same spot.
This (in my mind) points to it being an issue with the EC2-instance.
For now I'll be running it in standalone mode, to get the rest of the pipeline working.
I am looking for ways to set up like a central 'hub' for Selenium in my work, allowing anyone to access in within the company. For example, Tester A writes test scripts, the Person B can run without having to manually copy over the test scripts to their local workstation)
So far, I've only thought of installing Selenium in a VM which will then execute as per normal. But if I run Selenium Grid, it will run VMs within VM (?). My only concern with VMs is that it'd run slowly.
If anyone can think of a better solution or recommendation please do give me some advice. Thank you in advance.
One idea. You can create an infrastructure combining Jenkins/Selenium/Amazon.
The following is my solution from another post.
You can do it with a grid.
First of all you need to create a Selenium hub with an EC2 ubuntu 14.04 AMI without UI and link it as a jenkins slave to your Jenkins master. Or as directly a master. What you want. Only command line. Download Selenium Server standalone. (be careful on downloading the version. If you Download the Selenium3Beta, things could change). Here you can configure the HUB. You can also add the Selenium Hub as a service and configure to run automatically at server start. its important that you open the Selenium default port (or the one that you configured) so the nodes can connect to it. You can do that on the Amazon EC2 console when you have created your instance. You just need to add a security group with an inbound rule for TCP in the port you want for the IPs you want.
Then, you can create a Windows server 2012 instance server (for example, that's what I did), and do the same process. Download the same version for Selenium and the chromedriver (there is no need to download any firefoxdriver for Selenium versions before Selenium3). Generate a txt file and prepare the Selenium command to link to the HUB as a NODE. And convert it to *.bat in order to execute it. If you want to run the bat at start you can create a service with the task scheduler or use NSSM (https://nssm.cc/). Don't forget to add the rules to the security groups for this machine too!
Next, create the Jenkins server. You can use the Selenium Hub as the Jenkins master or as a slave.
Last step is configuring a job to be run in the Jenkins-Selenium machine. This job needs to be linked to your code repository (git, mercurial...) Using the parametrized build plugion for jenkins you can tell that job to pull the revision you want (where every developer can pull the revision with the new changes and new tests) and run the Selenium tests in that build with the current breanch/revision and against one unique selenium. You can use ANT or Maven to run the Selenium tests in Jenkins.
May be it's complicated to understand because there are so many concepts here but it's robust and it works fine!
If you have doubts, tell me!
If Internet Explorer is not one of the browsers on which you must run your automation tests, I would recommend that you consider docker selenium.
Selenium is providing pre-configured docker images for both Selenium Hub and Node ( refer here for more information ). For making use of docker selenium all you need to do is find a machine (preferably unix machine), install docker on it by following instructions detailed here and then start the hub and node by starting off those containers. In the case of docker you can literally transform a VM (or) a physical machine into a VM farm and yet not have to worry about slowness etc., because I believe docker is optimised for these and it runs your VM as a process.
Resorting to using Amazon cloud for running your selenium nodes is all fine, but if you have corporate policies that prevent in-coming traffic from the internet into your intranet region, then I am not sure how far Amazon cloud would be useful.
Also remember that Jenkins is not something that is absolutely required but is more of a good to have part in the setup because it would let anyone run their tests from a web UI. This will however require that all your tests are checked-in and made available in a central version control system in your organization.
PS : The reason why called out Internet Explorer as an exception is because IE runs only on windows and there are no docker images (yet) for windows. All the docker images are UNIX based images.
I have a Jenkins server running in private cloud and the dev team want to be able to run some selenium tests on their local dev rigs.
I've looked at Selenium Grid and installed the Selenium Grid plugin for Jenkins and whilst I can get nodes to register to the Jenkins server (Selenium Hub) I cannot invoke tests on the node.
The local dev machines are on our corporate network behind a firewall with no option for that to be changed.
Does the Selenium Hub try to make a new connection to the node when it needs to, or does it/can it use the connection initiated by the node as some kind of reverse tunnel?
I would like to check my selenium grid test cases on a server(any machine other than localhost).I need chrome , firefox and IE browsers in the server. Is there any way to do this ? I checked few sites like koding.com , but it is only offering me unix interface,I need full windows/Ubuntu interface.
Please let me know if there is any other method to execute my test cases ?
VirtualBox is good and works well for grid tests, I expect it to be a fairly common solution. Same IP is not a problem as you make it work with port forwarding on your desktop. For example you should manage to build a grid like the following:
-role hub on your Windows host on port 4444
-role node on an Ubuntu VM with port forward 5556 in VirtualBox, for Firefox
-role node on an OSX VM with port forward 5557 in VirtualBox, for Safari
-role node on a Windows VM with port forward 5558 in VirtualBox, for IE and Chrome
node with socat+flynnid.py on an Android emulator with port forward 5559
maybe also iPhone Simulator from inside OSX VM (I don't remember if I made it work with grid)
The Selenium Grid "user interface" as you say, is the same , whether it is Linux or Windows. The only difference is that on Linux you won't have an IE driver.
What you do is run a Grid Hub on your local machine and then register "Node" servers on each remote machine. Each Node server can run any combination of web browsers that you mentioned and it is also capable of running them simultaneously (if your test suite was programmed carefully).
The .jar file that you start the Grid Hub with is the same .jar file you use to start the Nodes. The only difference is that each Node will have a .json config file with it that explains the configuration of that server such as where the IE and Chrome binary files are located at on the remote server, what browsers it supports, and how many threads it can handle.
Look at the documentation I wrote (for Grid hub config) on the GitHub "Selenium documentation" site.
I have implemented Selenium Grid by reading and understanding from the sparse/fragmented online documentation about Grid2.
My current implementation is-
Webdriver node registered and running on EC2 instance
java -jar selenium-server-standalone-2.8.0.jar -role webdriver -hub http://EC2_PUBLIC_IP:5555/grid/register -port 5556
Hub registered and running on same EC2 instance
java -jar selenium-server-standalone-2.8.0.jar -role hub -hubhost EC2_PUBLIC_IP -port 5555
I am running my Webdriver based TestNG tests from Eclipse on my local machine. The driver configuration is
driver = new RemoteWebDriver(new URL("http://EC2_PUBLIC_IP:5556/wd/hub"), capability);
Running the tests launches the browser on my EC2 instance.
I am still looking for a few unanswered questions that may be very basic and would appreciate people's views or understanding on them. I want to have my browsers launched on a machine that has respective Node running on it. e.g- A machine running webdriver+firefox node should launch respective test.
How does the Grid2 implementation works if I need to setup Hub and Node each on separate machines? I believe the implementation would be different if its a EC2Hub-LocalMachineNode combination AND when its an EC2Hub-EC2Node combination.
In either cases, what command/URL do we provide for hub, webdriver/RC node and in the Selenium tests? I ask this because majority of online documentation speaks about "localhost" and port 4444, but I want to make this generic.
Are there any specific settings for the ports/firewall while setting this up?
I was able to achieve this by opening ports 5554-5559 on my EC2 instance from the AWS portal and also the firewall for these ports on my local as well as EC2 machine.
Please let me know if I am unclear, or ambiguous at any point. Would appreciate your explanations.
There's no special considerations for running grid on EC2 versus any other networking environment. Everything is done via HTTP on ports you can configure. Since you almost certainly don't want your grid publicly exposed and everything in the default security group can talk to everything else on the same network, you shouldn't have any problems.
You can either configure things from the command-line or through a JSON configuration file. I prefer the latter. The default configuration file can be found on Google Code. You'll note the "hubPort" value there. Not shown, but valid, is a "hubHost" configuration item. Just set that to the hostname of the hub.
When you launch your node, supply the "-nodeConfig /path/to/my/node_config.json" command-line argument and you'll be good to go.