Java Programming: Something like Watir-Webdriver running in background - java

I have written a program in Ruby that checks a web page every so often, and performs some actions if data is found. I have written this using Watir-Webdriver.
I also want this program to run as a "daemon". The problem I had with Watir-Webdriver was that I could not run it without a browser popping up everytime.
I actually need to write this in Java? Which is best Java package thats similar in functionality to Watir-Webdriver?
Is there any way to implement this in Java - to check a webpage and do specific actions - all in the background?
Also, I would like this to be cross-platform.
Thank you in advance to help

You are looking for Selenium WebDriver. It can be written in Java and many other languages.
Yes. Webdriver can run different types of browsers. You are looking for what we call a headless driver. The most popular headless drivers are HtmlUnitDriver or GhostDriver. I personally prefer GhostDriver, as it runs a more modern version of Javascript.
All Java code can be run on different platforms, so that shouldn't be a problem.

Related

Java Native Interface (JNI)

I'm using Java and Selenium on a VPS. I need to execute a specific set of Selenium code under a different windows user account. I know Java does not support this functionality. I came across Java Native Interface which supposedly supports this functionality - can anyone show me how I'd use this to run code under another user account?
Note: I'm aware of Selenium Grid however there's certain functionality Selenium Grid does not support therefore I want to execute standard Selenium code under a different windows user account (locally).
Thanks

Crash testing with Javascript or python on Java

I need to 'crash test' a couple of Java applications with mainly Javascript.
By crash test I mean I need to pass the Java class or method all different types of random inputs until it crashed then record it. But I have ran into the problem that I don't know the most efficient way to call a certain Java class or method from Javascript.
Then I also do not know which scripting language would be better for the job, python or javascript. Both languages have to work offline and I don't know if I will have access to the command prompt / admin privileges to use the command line to call the classes or methods. So what do I do?
2 Questions:
How do I call Java classes and Methods in Javascript?
Would python be better for this job?
How do I call Java classes and Methods in Javascript?
Java runs in JVM, Javascript runs in Javascript engine like v8. so first you need a layer which Java and Javascript can both run in. For now there are some ways to run Javascript in JVM, these ways all provide interoperability between Javascript and Java. you can Google 'Javascript JVM' to go ahead.
Would python be better for this job?
'better' depends on much. for programming language, I like Javascript. Javascript and the libraries mainly designed for web development, Python is more like a common programming language. also Python cloud run in JVM with help of JPython

Trying to understand selenium and its various components

For integration testing I want to use selenium, also for my TDD/BDD workflow but also for my remote build server to run through the tests etc.
What components do I need for this?
I know there is a browser add-in, but that is for helping to bootstrap the code (you can export the code, then tweak as necessary).
I find it slow to run the tests locally as it fires up the browser, is there a way to do this w/o the browser opening?
How does this work on the build server, is there a headless mode?
Can someone outline the various selenium tools and how they fit together and where they are used in the development cycle.
e.g. I see selenium drivers, selenium rc, browser add-on etc.
I want to use this for both rails and java.
I never tried Selenium with Java, only with Ruby, but your interaction should be similar. I don't think Selenium has a headless mode, you would have to use a different driver for that. For ruby, there is capybara-webkit, for example, which runs a headless webkit based browser.
I can tell you from my own experience, we had a lot of problems on CI (build server) with the headless browser so we ended up switching back to Selenium and Google Chrome running on top of Xvfb, which is kind of a virtual screen manager for unix that lets you run graphical apps in a headless environment. Most of the problems are related to inconsistent behavior between the webkit headless browser and an actual real driver. However, depending on how your app looks like and how you're going to drive it, it might work for you, you should give it a try.
So the only components you need are the Selenium server (that driver the browser) and the client, that sends the command to the server. They have java and ruby clients, so you can choose whichever language you prefer.
It is indeed a slow process and very flaky as well, as your tests might fail for no reason sometimes due to timeouts, 3rd party APIs that are down, etc. There are tons of things that can go wrong and cause your integration tests to fail.
Anyways it is still an invaluable tool and you should definitely use it. Just be aware that you should not rely entirely only on these kinds of tests to assure the quality of your app, however, these should only test a smaller surface of your system. Unit and component tests should make up the majority of your test suite.
Hope this helps clarify your questions.
I have evaluated Selenium somewhat myself and as I understand it you should use the Firefox add-on to record your tests. Then export to whatever code you want. Then, when the time comes and you want to test your system, boot the Selenium RC which acts as a server that you can then use to run your tests. The Selenium WebDrivers are part of this and allow the server to open and "drive" the browsers using your recorded tests.
Note that recording tests in browsers other to Firefox is more difficult as there is no handy add-on for use. Instead you have to build your own tests from scratch, which is time consuming.
app.test from Fabasoft (http://www.apptest.com/en/) is another free alternative that does the same job but in a different way, maybe take a look at that before you get too involved with Selenium.

How do we test our Java UI?

We're looking at record and playback type test tools to automate some of our UI functional testing.
We've looked at most of the usual suspects from Silke to QTP and none of them work.
They all fall over when a right click is required to select something off a right click menu, or when you have to choose a value in a drop down list in a grid.
Does anyone know any tools that can handle this type of UI?
We have made good experiences with Squish. You can identify UI elements by IDs or record mouse actions.
Are you talking about a stand-alone Java application, or is it web-based, with Java on the server, but HTML delivered to the client?
Assuming it's a stand-alone Java application, SilkTest and QTP ought to play nicely with Java. (Are you using the appropriate Java add-in/plugin for Java support? QTP has a separate add-in for Java support.) Another tool to consider would be IBM Rational Functional Tester. It's built in Java and works well with Java apps. I've used all 3 tools, though never SilkTest on a Java app. In my experience, both QTP and RFT performed well with Java apps.
That having been said, on every test automation project, there are going to be UI controls that do not work great out of the box with the selected automation tool. (3rd party controls are usually the culprit). In these cases, you will need to manually code a work-around. In the example of right-clicks not working as expected, I have often needed to forego clicking to select an item from a right-click menu in favor of using keystrokes to select the desired item. What this really points to is that you have to let go of the notion of record/playback being an effective means of automation.
Additionally, it might be instructive for you to post the actual code that was recorded, and at which line it fails to select the item in question. The actual script code could give me some clues as to what is actually going on.
Sahi is good option for recording and playback like testing stuff.
Here is a sample tutorial.

Is there a way to make a very simple IE browser with java?

I have a small project that i was wondering if it is possible to do with java.
I know that VB .net has the ability to make a simple web browser using an Internet explorer interface. I was wanting to do the same thing with java. Unless somebody knows how to compile VB on linux and would like to explain it to me.
Please tell me if you need anymore information.
JEditorPane has limited HTML rendering support, but no javascript engine
If you want Internet Explorer specifically, it's not going to be possible in the same way. VB.net uses the part of Internet Explorer that is built into the system. In other words, it is referencing a part of the Windows system, so you need to be running Windows to use it, regardless of the language.
You would need to use a tool such as http://www.ezjcom.com/ to get a COM wrapper in Java, from there you can embed IE as an ActiveX object.
All of these pieces might make it a little slow or cumbersome, but it should be possible.

Categories