How to run selenium on RHEL sever through SSH? - selenium

I have developed a fully working Selenium suite using Java webdriver and firefox and is working perfectly fine. Now our requirement is to run the same test suite in Red Hat server (RHEL ) so that it should run as cron job everyday. The only way we access our server is through Putty ( SSH ). Anyone can guide me how to run my selenium test suite on RHEL sever ? I need a way to kick automation suite through SSH or HTTP request.
Any suggestions??
Thanks
Thanks,
Faiz

I achieved this using :
Install firefox on Linux
Install xorg-x11-xauth
Before executing the automation script just call - "export DISPLAY=:0.0"
This will cause display to be redirected to mail display. Execution will start on Firefox (one could see execution if display is connected ) and will output results back to SSH

Related

Running EdgeDriver in Jenkins

I have Selenium tests that I am running through Jenkins on a build server. The tests all run as expected in Chrome (using ChromeDriver) and Firefox (using FirefoxDriver). However, the tests don't run in Edge using EdgeDriver.
When the tests run it gives an error:
Microsoft Web Driver can't be used with the Built-In Administrator account or while User Account Control is turned off.
I have tried turning UAC on, but that no effect. I tried running the Jenkins service as a different user and that also had no effect. I've tried the suggestions from: MicrosoftWebDriver fails when constructing while running under TeamCity agent's windows service
I can run the tests in the same location from a command prompt, just not through Jenkins.
If you configure jenkins slave agent as a windows services, Will get the issues. Because Edge won't run as a headless browsers.
For avoid those issues. we are not suppose to set a slave agent as window services.
Follow the below steps for setup slave agent and then run your script:
***** Then download the agent.jar and place it under jenkins working directory("D:/Jenkins")
***** Open the command prompt as admin user and execute the commands.
java -jar agent.jar -jnlpUrl http://srv-cbe-com4:8080/computer/T/slave-agent.jnlp -secret 07ba92bb8017901287acb979cf30d40a45c17abd2c0edba5b2b3f17cc94915e8 -workDir "D:/Jenkins"

Jenkins setup for running Selenium test on Ubuntu

I already tried a lot for Jenkins setup on Ubuntu for running selenium test cases. But each time i face problem Like Display error , chrome connection timeout. I tried all the solution on internet (debugging this from last one week). Someone please help in setting up by step by step process (including version compatibility).
Also, test-cases on Ubuntu Jenkins run only on display mode?

Selenium works when started locally, but not remotely

I'm hoping this is a simple issue to solve:
I have a dedicated machine that runs selenium with chromedriver. I can physically walk to the machine and type the following in a local terminal:
java -Dwebdriver.chrome.driver=chromedriver238 -jar selenium-server-3.11.jar
I can then go to any other machine on the network and kick off testing (in my case, codeception on jenkins) and it will sucessfully run my tests in chrome without a hitch.
However, if I try to run the above command without physically being at the selenium machine (ex, trying to ssh into the machine to run the command or making this command run as part of a supervisor process) then selenium has trouble starting the instance of chrome.
Has anyone run into this scenario before? Is there a way I can give 'interactive' access to the background script to allow it to open stuff on my screen?
Because when you physically walk to the machine and run the command. the selenium can get the desktop/window interface.
When use SSH, selenium lost the desktop/window interface, selenium have to start chrome under headless model, but your code not config to run as headless model. So the conflict come out.
you need to config your code to run with headless model.
I'm to getting the same scenario, when i try to start the selenium code on the machine A it works yet when i try to start selenium and run the scripts from machine B
(remotely connecting to machine A using ssh [ssh test#machine-a]) chrome instance doesn't start/launch and driver is getting null.
logs :
2020-02-27 12:04:27,319 INFO [LogWritter] Exception in beforeclass chrome driver instantiation , driver is null
2020-02-27 12:04:27,493 INFO [LogWritter] Exception in getting screenshot---java.awt.AWTException: headless environment
Any help/suggestion would be great !

How to setup webdiver to perform actions in background?

I am currently working in Automation QA. Our project using Java: jbehave, thucydides, selenium. We are working in Ubuntu OS.
Every time I run my tests, I have to stop doing everything(coding, browsing the web), because every click or any action of selenium is taking driver window(we are using chrome driver) in focus(makes window active) and if i do something i mess up the test. Our team is wasting a lot of time because of this.
We have tried Phantomjs, it doesn't work correctly, cannot find elements etc... And also to run tests in virtual machine using vagrant isn't working for us(for company specific reasons).
It is fine if Chrome driver will take over active window when it starts, as long as it would continue performing different actions in background. Strange, but in my previous project(windows, c#, mstest) chromedriver would behave exactly like this without any additional setup.
Please help, I know few other teams having this issue. Seems like this issue only on Mac and linux.
After having this issue for a long time I have finally found a good solution. This issue still remains on ChromeDriver level, so if there are any updates on this side let me know.
The easiest way to run tests in Ubuntu in a background is using VNC Server. Here are the steps you should follow:
Install vnc server from ubuntu terminal:
sudo apt-get install vnc4server
Start server with any number(I use 7). First time doing it enter password for vnc server(Remember it!).
vncserver :7
To start server in full screen add "geometry" to last command with your screen resolution for example:
vncserver :7 -geometry 1920x1080
Download some VNC Viewer. I use Real VNC.
Go to Real vnc viewer, start new connection and enter:
VNC Server: localhost:7
Encryption: Let VNC Server choose
Press connect and enter your vnc server password(the one from step 2).
New window should be opened, open new terminal in it.
Run your test from terminal. I use java maven project so for me it works like this. Navigate to project folder and run: mvn clean install
If you want simply to run test in hidden mode using only terminal(without opening vncviewer) use this command:
cd path/to/project
xterm -display localhost:7 -e mvn clean install
If you want to stop server:
vncserver -kill :7
Hope this will help many of you.
For me (I had the same problem in my Grails project's functional test using Chrome; not with Firefox) works this set up:
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized --disable-popup-blocking");
new ChromeDriver(options);
Regards

How to use Selenium Grid to run some commands on the node and system commands locally

I'm trying to solve a problem and I was hoping I could do it with Selenium Grid but I'm not entirely sure that it's possible. Here's my problem...I'm developing test cases using Selenium WebDriver and I need my tests to run on a Windows machine however the AUT runs on a Linux server. I have several tools that only run on Linux and I would like to be able to run some commands/tests on the Windows machine and others in the Linux server. For instance
Test Starts -> Firefox launches (Windows machine)
Login to site (Windows machine)
Run command in Linux server
Return running commands/tests on the Windows box.
Alternatively I could figure out how to run those commands remotely from a Windows machine but I'm not looking forward to doing that.
Out of the box, you cannot use selenium to run commands on your local machine. Selenium/Webdriver is a browser testing tool and can interact only with browser.
Updated Answer based on your comments
Common part to both ways (which I think you already know)
In your java code you should have the code for webdriver/selenium commands that will do step 1 and 2. Your java code should also the contain the logic/code to execute the linux commands as step 3. Step 4 should again be your webdriver command.
This test code should run from the linux server so that the java command execution will happen in the linux box.
Now the only pending part is the execution of test in remote machine.
Method 1 without using grid
Start the selenium server in the windows machine. Point your java tests to the selenium server running in this machine. If your windows machine IP is 10.0.0.1, you should initialize the webdriver object as
WebDriver wd = new RemoteWebDriver(new URL("http://10.0.0.1:4444/wd/hub"),DesiredCapabilities.Firefox());
This will send all your webdriver commands to the selenium server running in 10.0.0.1 on port 4444. Your tests will then get executed in the windows machine. For this to work, your linux server and windows machine should be in same network.
Method 2 using grid.
Its all the same as above, but instead of giving the ip/dns name of windows machine, you should give the ip/dns name of the hub machine. You should also have windows machine registered as an RC to that hub.
I think with AutoIT kind of windows frameworks, we can invoke C:\Windows\System32\cmd.exe to open a command prompt and run some .bat files. If it is Linux /bin/csh or /bin/bash myscript.sh.