PHPUnit Selenium tests fail on Docker localhost and pass using public IP - selenium

I'm trying to setup an automated testing platform with Docker and Selenium Grid.
In the diagram below you can see the structure that I'm using.
On top is the ubuntu server running on Compute Engine.
On the left is a docker container running ubuntu 14.04.
The container runs our project on localhost:8080 with Google App Engine.
On the right is the Selenium Hub with two nodes running on port 4444.
There is portforwarding from the host to the docker aswell as to the selenium hub. On 32772 and 32768 respectively.
When running my Selenium tests I send them to the hub, which in its turn will run the tests on the localhost of the docker.
My problem is that when I tell the hub to run the tests on 172.17.0.2:8080 it opens the startup screens, but it can't submit any forms.
When I submit the form the text areas get cleared. Like the page is refreshed in some way. The strange thing is that when I tell the hub to use the external ip of the host and the port of the docker like this xx.xx.xx.xx:32772, it does work.
And it has all the functionality. However for performance and automation reasons I'd like to run it on the internal ip adress.
Any help would be appreciated.
Tijn

The problem was in my .env file. The Session Domain was set to the host ip instead of the internal ip adress. By changing it, the website worked like it should.

Related

How to launch chrome driver on any remote machine

I have a requirement where i need to launch the chrome browser on a remote machine. I have explored selenium grid but it requires some static configuration on the remote machine. In my case the remote machine vary and the IP is taken from a properties file hence it is not possible to create all those machines as hub.
Could anyone help me with a more generic way by which i can dynamically launch the chrome driver on the machine for which i read the IP from properties file?
Option 1 :
Check with the team provisioned IP address for the machine. It is possible that IP you are using is public IP (public IP address may change when machine is restarted) . Team can provide you with a private IP(it remains static) and a VPN to access the machine. If you are able to access the machine using this solution , setup selenium grid ,and you will be able to run your tests
Option 2 :
If you get a new machine for every run, request the machine with docker enabled, so you can spin up a selenium grid infrastructure using docker and run your tests there

How to launch the browser on client side using selenium webdriver

I am new to selenium. I am developed one application using a selenium web driver for doing some actions on the webpage. It's perfectly working when I am running locally i.e., it launches a browser in my machine. I deployed this application on a VM server so the script runs on the server(launched browser in VM Ware Machine), not on the client-side. Can anyone help me with how can I launch the browser on the client-side?
You have to create Hub and Nodes using selenium grid
You can refer this link to see step by step
http://www.seleniumeasy.com/selenium-tutorials/how-to-configure-selenium-grid
Your server will be hub and your client machine will be node
If you trigger from one machine, you can launch a browser on another machine using the selenium-grid concept
But both machines are under the same LAN.
Here you want to execute on the client machine. It is not possible, because your machine and client machine won't be under the same network

How can anyone run access Selenium test scripts without having to install/run it locally?

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.

Jenkins, running selenium tests on local dev machine

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?

How can I run Selenium tests when my site is in Vagrant?

I use Vagrant for my local development. Now I want to use Selenium for automated browser testing. When I setup Selenium in my VM, it works like a charm (great stuff by the way).
But now I want to move the Selenium testing out of the box. I tried to run the Java server on my host machine, forward port 4444 to port 4444 in virtualbox, and then fire the phpunit-command in VirtualBox, hoping to trigger the server on my host machine.
But instead I get a CURL-message that phpunit can't connect to 127.0.0.1:4444, so obviously there is no connection to my host machine on this port.
Can anyone tell me what I'm doing wrong?
Edit: I figured out that when I'm running the server on the host, I cannot access 127.0.0.1:4444 in my browser, however, I am able to access localhost:4444. Which is weird, because my hosts-file has the correct line (although it shouldn't matter since phpunit is trying to access a numeric address).
I think the best solution for this is to setup a "private network" this way you'll be able to use internal address to access your vm and host separately...
Depending of your vm provider different solution are possible (for example, Virtualbox support internal netowrk only)
Have a look at : http://docs.vagrantup.com/v2/networking/private_network.html