How to run the selenium server in the background using robotframework? - selenium

So the concept is like this -
I would like to run the selenium server .jar file on a remote windows machine.
Then connect to it via the default port (:4444), open browser and navigate to a URL of my choosing.
I have everything working except the part of running the selenium server through robot.
This keyword works as far as I can tell (until the open browser keyword) -
Start Selenium Server
&{client} = Return Internal Host
Connect Environment Machine Windows ${client}
start process java -jar ${/}SeleniumServer${/}selenium-server-standalone-3.141.59.jar alias=seleniumserver
process should be running seleniumserver
open browser http://example.com/example.html chrome None http://1.1.1.1:4444/wd/hub
BUT, when I try to connect to the selenium server I get the following error -
"No connection could be made because the target machine actively refused it"
It seems like the process either does not run or runs for a short amount of time then closes.
What am I missing here?
If I manually start the server on the client, everything works. It opens the browser and does whatever I need. (manually running the java -jar selenium*.jar on the cmd)
But when I run this Start process keyword, that should keep the process running in the background, I get connection refused. Any Ideas?
Another piece of information that might be useful - The selenium server should throw an error if trying to run it twice on the same machine (because of the used port bind 4444).
When running the keyword shown above, while there is a selenium server up and running on the target machine, the test still passes for some reason. Not sure if it is even running the process as intended but the "process should be running" keyword seems to pass.
Thanks!

Related

Need to access Firefox browser in remote machine connected using Open Connection in Robot Testcase

Problem statement is:
Execute Robothost Testcase -> used Open Connection keyword to connect to machineX. used Open Browser keyword to open Firefox of machineX.
But instead of opening firefox browser of machineX, browser from Robothost is opening from where testcase is getting executed.
But my testcase execution needs to be done on webpage opened in machineX only.
Since used Open Browser after connecting to remote machine, expecting browser of remote machine to be active. verified that connectivity to remote machine is active.
Below is sample code tried to open browser from machineX
*** Testcases ***
LaunchBrowser
Open Connection ${machineX}
Sleep 5s
Open Browser ${base_url}
Sleep 5s
Input Text //input[#id="normal_login_username"] admin
Input Text //input[#id="normal_login_password"] admin
Click Element //button
Sleep 5s
Capture page screenshot filename=output5g.png
Close Browser
Any suggestions to handle this scenario
This is not how the ssh library works, in order to execute something on the machine x you need to use ssh library keywords. The selenium library will be executed on your machine.
You can install robot framework on machine x and execute the test there. Otherwise you cannot use ssh library. You can trigger the test from your machine if you have to do this remotely.

Open command prompt on remote windows server

I would like to clarify something, when I say open cmd, I mean literally/physically open the cmd on the windows server. For example, if I use RDP to connect to the server then I can see the cmd open on the display.
I have used ssh to connect to a remote server then executed a script but it only executes this script in the background, I have not found a way to literally display the cmd running the script. I am trying to start my selenium grid remotely but IE instance cannot start the test unless the command prompt running the selenium node is displayed. I have found chrome can handle the situation fine, it will run the test on a hidden display. However, IE cannot do the same.

Jenkins - Timed out connecting to Chrome

Odd one here that I have not seen before. I decided to load a local instance of Jenkins on my Win 10 Laptop. The service is up and running and everything is building fine but when it tries to open chrome, I see the below in the log. I can execute it from Visual Studio and Command Line with no issues.
Research has mentioned lowering the chromedriver version so I tried with no luck. I have only run jenkins in master/agent config so maybe this has to do with jenkins being run on local host?
Starting ChromeDriver 77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-
refs/branch-heads/3865#{#442}) on port 7797
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to
prevent access by malicious code.
[1571096148.894][WARNING]: Timed out connecting to Chrome, retrying...
Additional things I have tried....
Creating a new user with all permissions to the jenkins dir
Running the service as the new user
OK I gave up running as a service. I copied the Jenkins.war file to the the directory I wanted. In this case, D:\Jenkins and then I executed:
D:\Jenkins>Java -jar Jenkins.war
This reloaded the Jenkins install. I added msbuild/tfs plugins and I am now running jenkins from the command line vs as a service. Everything is working now.
Just a work around but it may help someone else out.

How exactly does one automate internet explorer tests with selenium grid?

I have a GoCD server that I plan on running my selenium test suite on. This machine is a Linux machine. So.. I set up selenium on a windows machine. The key problem I am having is that when running as a service, or a scheduled task, the selenium hub does not launch IE.
If I remote desktop into the machine, run the jar manually from command line, the browser launches in my RDP session and the tests all pass. If I install it as a service (With permissions to interact with the desktop!) the driver appears to run, but the content never loads.
So if you have an answer, please remember:
The grid works for all browsers with an interactive desktop session open.
Without an interactive desktop session, Chrome and Firefox tests still pass (in headless mode).
I am using no selenium nodes, I am only using the standalone jar (not running as hub or node, just running the tests standalone.
I am using version 3.14 of both selenium standalone and IEDriverServer.exe
I know that tons of people do automated IE tests with selenium, but how do they do it with Hub on windows?
I've tried literally every options setting I can see to try to phinigel a way to get it to work, but it's just not having it.
I also tried running as a scheduled task rather than a service, no dice there either.
This is the precise error the IETests are presenting:
Oct 09, 2018 1:15:12 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
org.openqa.selenium.TimeoutException: Expected condition failed: waiting for value to contain "sign-in.host.com". Current value: "null" (tried for 10 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:113)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:283)
I used to have issues with IE selenium tests on a VM in azure. What i noticed was that while RDP to the machine everything worked fine but when i closed the session all tests failed.
What i ended up doing was leaving a logged in console session after every RDP closing.
After adding a trigger on session log off i run a powershell script with the following:
Tscon 1 /dest:console
This keeps an active desktop session and my tests on IE pass.

Selenium WebDriver tests fail with System.Net.WebException Unable to connect

I'm working on a suite of Selenium WebDriver (not Selenium RC and not using Selenium-Server) tests that are being executed by a command-line call to MSTest. I've broken them into test classes for each browser we plan on testing (Chrome, Firefox and IE9, for now) and each test class has a startup method that logs in to the system under test and then executes the test(s) requested and a TearDown method that closes the browser using WebDriver.Quit().
On my development machine everything is hunky-dory, but on our build machine the class initialization/start-up method executes fine and logs into the site, but as soon as the first actual test starts the test runner closes with the error message:
OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:59982
obviously the port changes depending on which browser's being tested; when I run the whole suite I get errors on different ports for the tests for IE, Firefox, and Chrome - two errors for each browser (as the suite currently has two tests for each browser)
Windows Firewall is off for the build machine, and checking netstat before running the tests shows that the port's not in use; if I debug the tests and stop after the startup code runs but before the test runs, of course the port is in use. 127.0.0.1 and localhost are the same as well.
I get the same error whether or not I call the test via the command line, run/debug it from within Visual Studio using the VS Test tools, or by executing my console app, which calls MSTest via Process.Start(). The exception is thrown on the first FindElement() call.
Where can I start looking to figure out why this is failing on the build machine and not on my dev box?
The issue here was that in trying to implement some more robust error handling during startup I place a call to the Teardown code in the finally block of a try/catch wrapped around the login code, so as soon as the test harness was done logging in I was closing and cleanin up the WebDriver instance, so when the test ran there wasn't a WebDriver there to communicate with.
I suspect when I as looking at the "same" code on my dev machine the libraries that were actually running didn't have that block in them.
When you run an application from Visual Studio it fires up a server listening on a certain port. In your case 59982.
You need to actually have your web application running on its own on the test environments before running your test against it.
On your dev machine your application is running on that port. I'm guessing on your remote machines that is not the case.