Java Robot class not working from Jenkins - java

I am automating a scenario(selenium) where i need to enter credentials in Authentication Pop up, which is generated by the APP. I am using java Robot class to perform this function, it runs fine when i run it from my local machine which is a Windows Platform, but it doesn't seem to work when i trigger the build from jenkins. It hangs at a point where you need to enter the Credentials in Authentication Pop up. I think This is because the jenkins slave is an Unix Platform and this has something to do with the cross platform issue. As i am not sure if Unix Supports the Robot class.
Can somebody suggest me a workaround for this problem ?
Thanks in advance!!

The problem might be that you are testing on a headless server? Make sure your are not using firefox or chrome driver. Try to use the HtmlUnitWebDriver driver instead.

Related

Restricting browser drivers in selenium

I am a newbie to selenium. Just wanted to know how do I restrict the script to take only one version of a browser. I dont want to update my browser driver again and again. please help
Selenium usually takes the browser that is installed on your machine. So, I didn't understand this - 'restrict the script to take only one version of a browser'. Do you have multiple browser versions installed in your system?
You may follow the following approach:
Install the required version of browser alone in your local machine and don't update it.
Use Bonigarcia WebDriverManager - https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager with your Browser Version. Say, if you want to use chromedriver v88, you may set it to:
WebDriverManager.chromedriver().driverVersion("88").setup();
This will always use the same browser and driver version.

Applications/processes ran using Java 8 on Windows are not visible

This has been making me work overtime and I still don't have much clues. I have a web application that is locally installed (pseudo-desktop app) that does the following:
Starts an SSH tunnel
directly runs ssh if on Mac OS X
uses PuTTy executable if on Windows
Opens Firefox or Chrome configured to use Socks5 proxy using the tunnel (localhost:port) via Selenium webdrivers.
For 1:
I have used both Runtime.getRuntime().exec(command); and Process proc = new ProcessBuilder(arguments).start();, and even gave Desktop dt = Desktop.getDesktop(); dt.open(f); a try. But nothing happens, no command prompt opens.
For 2:
I have tried using both Firefox:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.socks", "localhost");
profile.setPreference("network.proxy.socks_port", 8088);
driver = new FirefoxDriver(profile);
And Chrome:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--proxy-server=socks5://localhost:8088"));
driver = new ChromeDriver(capabilities);
But similar to 1, no firefox or chrome windows open.
Note that this application works perfectly on Mac OS X Mavericks.
After several hours of debugging, I noticed that the processes are there. All the processes, from PuTTy, to Chrome, to Firefox. There were a lot of those already running in the background. The odd thing is that the user column of these processes is set to SYSTEM, while the normal browser sessions, for example, the user is set to "IT", which is my current Windows user account.
I have been trying to manually change the user in which these processes are invoked, but no luck so far.
So apparently, my application works in Windows as well, just not as I intended. All the processes, regardless if it's a command line script or a desktop application like firefox or chrome, they just don't appear but they run in the background under the user "SYSTEM". And I don't have any idea why. It sure doesn't look like it's supposed to be the default behavior. So if anyone have any idea, I'd really appreciate it.
Thanks.
Finally I was able to fix this! Thanks to this article (from a seemingly not related case):
Most Windows services -- including those run with the option "Allow
service to interact with desktop" in Windows XP and Vista -- do not
have access to many of the computer's resources, including the console
display. This may cause Automated GUI Tests to fail if you are
running Apache Tomcat as a Windows Service and are doing any GUI
testing. This is true at least for AWT and Abbot frameworks.
This limitation can be resolved by not running Tomcat as a Windows
Service, but instead through a "Scheduled Task" as an Application that
runs at logon. There are several options for doing this, an example
would be to run "$TOMCAT_HOME\bin\tomcat5.exe". When setting up the
scheduled task in Windows Vista consider choosing the check-box for
"Run with highest privileges" from the general tab, as this removes
the need to always provide administrator privileges and may resolve
other issues as well.
What I did was to NOT run tomcat7 as a Windows service, but instead just directly execute C:\Program Files\Apache Software Foundation\Tomcat 7.0\bin\Tomcat7.exe and everything worked perfectly. I can simply just put this as a scheduled task so it can still start automatically (or perhaps just put it on startup).

Cannot get Java Applets to work in any browser

We are trying to download something from GE that uses Java to download when logging into the site. This is a windows 7 Professional PC. I have other computers that are able to do this successfully. Here is my order of operations:
Log into the site and select the file I want to download
Click download
It takes me to the page that says it will start in a few seconds but nothing happens. It is supposed to have a box that asks for Java to run.
I have reinstalled Java fresh and still nothing. Tried with multiple user accounts. Added the site to the list of exceptions in the firewalls and Java configuration. I have tried an earlier version of Java. This happens in Mozilla, Chrome and IE. I have made sure that the Java plugin shows up and is enabled. I just cant think of what I am missing. And since we are a contractor GE is not going to help us. Can anyone here think of anything?
Are you sure you have the Java plugin enabled? e.g. in Firefox, go to Settings, Plugins, and change Java Platform SE8 'Next Generation Java Plugin' to 'always activate'?
This sounds similar to the issues I had with Cisco WebVPN, Java-style. Once you have Java installed correctly and set as a plugin for any of the browsers you would like to use, see below.
Before you even start looking at browsers - if you think it is already set up correctly
Look at your Anti-Virus programs or anything else that could prevent it from working. McAfee Host Intrusion Protection is known to cause many Java programs to fail. Kapersky had issues, a while back, with Java on Windows (Java Applets not loading in Windows 8 ).
You must have a 64-bit browser to use 64-bit Java (also mentioned in the Chrome link below).
See below for any specific things that can be modified in the browser.
Chrome 43 is the more complicated browser to set up. They have a dedicated page with instructions.
How do I use Java with the Google Chrome browser?
Firefox 38 will prompt you.
In Internet Explorer 11, it's under Internet Options->Security. I recommend adding the hostname the applet is on as a Trusted Site (Select Trusted Sites and click the Sites button, then add the first part of the url). Click the Custom level button and make sure that Scripting of Java applets is not disabled.
If you still have problems with the applet:
Verify your Java version will work with the applet you are accessing
Verify the plugin is enabled for the browser through the Java Control Panel, which is available in Windows Control Panel, or on Mac/Linux, execute it from the JDK directory ($JAVA_HOME/ControlPanel ).
I ended up fixing the issue. I had to allow their UK site on the list for Java and enable the SSL 2.0 for HTTP in Java config as well

Selenium iPhone Simulator Alternative for doing a Test Run

I am using iPhone Simulator in MAC with Xcode to run my tests which I wrote, even if I code first time and if I want to test the code works or not I need to run in simulator is there is any alternative way to do it ? instead of running in simulator even to test a code before the actual Test runs ?
I use Google Chrome with User Agent as iPhone to identify components as my application renders based on the Browser agent.
My initial plan is to call Chrome with pre-defined Profiles and user agent extensions.
Kindly give your suggestions.
There are many emulators out there for the iPhone. Configuring Chrome with User Agents is one of the quickest and easiest.
Maybe implementing your tests with a slicker tool may help reduce this burden? I suggest you take a look at iOS Driver.

How to capture a screenshot when not actually logged into the machine during running Selenium tests with Jenkins on Windows?

We have a CI environment with Jenkins running a test suite of Selenium Tests in a Windows (XP and/or Windows 7) VM. If I am not physically logged into the VM running these tests via RDP, all I see are black (blank) PNGs. I've tried all of the 'capture' methods available (both Base 64 encoded and file based) for multiple Selenium RC 2ish releases (e.g 2.0b2, 2.0rc3, 2.0.0, 2.1.0) and I get the same results for everything I've tried. Is anyone else running Selenium in a Windows CI deployment and able to capture screens? Or better stated, can anyone shed light on how I can capture screens in Windows, using the Selenium API without having to be physically on the box"?
If you are not logged onto the box, or you either closed or minimized the RDP connection, there is no desktop, and screen captures will be blank.
What you need to do is use a VNC server/viewer, so that the machine/vm in question has a visible desktop session.
We are also doing something very similar. We have a windows VM setup which is running Hudson and Selenium Grid.
When our test cases fail we capture a screenshot of the browser so we get more detail of why a test case failed.
We are using the #captureEntirePageScreenshotToString method
We're doing it, and it works for us. We're using JetBrains' TeamCity instead of Jenkins, running on Windows Server 2003. We run the Selenium RC server as a Windows service, using the Java Service Launcher.

Categories

Resources