I'm very new to JUnit, but I want to set up some tests which does the following..
Tests a range of server to server API calls - verifying the responses are correct - I can do that fine.
Open a web page, enter data onto it and verify what happens on submit - This I am struggling with. Is it even possible?
I am thinking that I could call a web page using a server side http web request, but I'm not sure how I can interact with the site itself, i.e. enter data into the forms.
Any thoughts?
Thanks
Steve
You could use Selenium for this. I suggest you use the version 2 which is currently in development and should have a beta available soon (alphas are already available).
Have a look at Selenium, it's a system to test web applications (and de facto websites) you can write all your tests in java. There is an ather project named Tellurium, based on Selenium but Tellurium works with groovy and a DSL, it might be easier to handle at first.
How does this works ?
First you create tests in java (Selenium) or groovy (Tellurium)
Then you start your tests. It will work with your web browser. The application will interact with your browser to test every inch of your application (as you coded it)
At the end it give you a report about yours tests, just as JUnit do.
You can also exploit the nature of the web. There's no real reason to render a form, fill it out and submit it to test the form processing code. The display of the form is one HTTP request, and the submission is another. It's perfectly reasonable to test form submission code by mocking up what a browser would send and asserting that it's handled correctly.
You do need to make sure that the form rendering and submission test code are in sync, but you don't necessarily need a full integration for this either.
There are tools that allow testing without booting up a browser... one that springs to mind is HTMLUnit (and there are others). If you find that Selenium is a pain to write, or the tests brittle or flakey, look for simpler tools like this.
I suggest you to try the Robot Framework. This is an open source testing framework developed by engineers in Nokia Siemens Networks.
It is primarily built on python and the Selenium testing libraries. It also includes support for testing Java/J2EE server side code through Jython libraries. I personally use it in my work sometimes, and writing a test case is just as easy as describing an end-to-end flow through the use of Keywords (most of required ones are already inbuilt). You could go ahead and give this a shot if you find Selenium a li'l tough to work with. The Robot framework provides a fairly simple abstraction over raw selenium, coupled with the power to make Java/J2EE server-side calls too.
Regards,
Nagendra U M
Related
Our application is 'Online Trading Platform'.
Now we need to implement automation for this application.
Is it possible to automate a trading platform which gets live streaming data.
Application is developed based on C#.Net.
If possible, how can we do it using Selenium.
Yes, As long as your application runs on Web Browser.
According to Seleniumhq.org
What is Selenium?
Selenium automates browsers. That's it! What you do with that power is entirely up to you. Primarily, it is for automating web
applications for testing purposes, but is certainly not limited to
just that. Boring web-based administration tasks can (and should!)
also be automated as well.
Like any modern application, the data, controls bound to be changed and hence captured. You may need to define some variable for example LastPrice, CurrPrice and once they are stored you can do the calculations and execute next steps.
I need to run performance tests on a web application and was wondering if the following can be accomplished with Apache JMeter.
I need to simulate approximately 300 users accessing an application over a set time frame (e.g. 300 users over 10 minutes) and doing some actions, for example:
Logging in
Navigating to different pages
Inputting data
Submitting forms
I'm quite new to JMeter and performance testing in general and was wondering if this is possible? Otherwise are there any better (free) alternatives?
Many thanks.
Of course, it is possible using JMeter.
I would recommend using JMeter/ Blazemeter Chrome extension. BlazeMeter's Chrome extension let you test your application without prior scripting knowledge. It is very easy to create a test with BlazeMeter's Google Chrome extension. Here are some blogs that will help or guide you to use Chrome extension and forth.
There is another option, that is JMeter build in Test Script Recorder. Go through This thread for further detail.
Follow any one of the two procedures to record your scenario and then customize the imported script according to your requirement.
First, record your scenario using Chrome Extension.
Import the generated .jmx file to your Jmeter.
Configure the Test plan according to your requirement.
Actually this is what JMeter is designed for.
For the basics following documentation chapters are very useful:
Building a Web Test Plan
Building an Advanced Web Test Plan
When it comes to the load distribution just use separate Thread Groups to represent different groups of virtual users (like some users are logging in, another are navigating pages, etc.). If you have only one group of virtual users and several actions to simulate you can go for Throughput Controller
I want to automate a server health check that is configured using weblogic. I have to login to weblogic console to view server's health. If I think about automating this process, then the only way known to me is selenium. But i dont want to use it. Is there any other way through which i can login to weblogic console and get the health status of server in java
I think it is pretty simple: if you don't have components at hand that provide you the functionality you are looking for; then you will have to see what it takes to implement it by yourself.
You could start here for example. Or for a slightly different approach there.
You can do the API automation, instead of UI automation. You have to find out if there are any API exposed to get the data. If there are APIs available then you can use httpClient library in java for API automation.
I am developing my first Java web application (Spring/Hibernate/Freemarker) and my only concern is development speed.
I used to develop in PHP, where it was sufficient just to reload the browser to see the result. With Java, I need to always click on "update resources" in my IDE just to see changes done to templates. It seems to me that this way of developing is really inefficient as the redeployment takes up to seconds.
Also, I am not the one who will be preparing the templates - it will be just a graphic guy and he will want to test them as well. Does he need to have its own application server and keep redeploying the application or is there some more "PHP" way where you just "reload" the page?
Yes, development speed is a major concern and drawback compared to dynamic languages and platforms like PHP or Rails. Obviously Java wins in different areas, but here are few tips:
Prefer unit-testing to redeployment - if you feel comfortable with unit testing, you greatly reduce the amount of redeployments. I found myself deploying complete feature only once, when it's done. All the logic is already tested so I don't have to deploy over and over, wasting seconds or minutes.
Also when I start to work on GUI, I don't have to back to the back-end, since I now it works. Once I see repetitive redeployments I try to test it using JUnit instead.
Use better frameworks. Spring MVC is very conservative, albeit being very good and pure. I've heard Play! framework can reduce turnaround time by recompiling classes on the fly.
On the other hand modern JVM frameworks like Grails can speed-up your development because they create domain, CRUD and GUI for you.
Some frameworks promote loose-coupling of templates. If you are using Freemarker or plain JSPs, it is hard to work separately on GUI. But frameworks like Wicket decouple to a great degree Java code from templates written in plain HTML. Also I am currently working on an application that is only serving static HTML and the dynamic content is updated via AJAX/REST services and JavaScript.
Consider purchasing JRebel and have a look at built-in hot-swapping features in the JVM. Sometimes changing the code does not mean redeployment.
IntelliJ IDEA can update modified resources (HTML, JavaScript) on the fly when the window goes background. This means that your resources are updated the moment you switch window from IDE to the browser. Probably other IDEs can do this as well.
You can customize your IDE to update your deployment automatically. Changes to web pages does not really require to redeploy an application, because Java servers updates them on-the-fly. Regarding your second question - you can create some common installation visible on number of computers, and customize IDE (or write scripts) that copy new pages to the deployment.
You might want to take a look at the Play framework which does just that - it lets you update your code (HTML, CSS, Java) and see the results immediately after pressing the refresh button in your browser, without the need to redeploy you application.
I'm building a Spring web app and up until now all of my testing is using a browser.
This involves starting the server, opening a browser window and checking to see if accessing any of the pages causes an error.
This is starting to get repetitive and doesn't seem to be the most efficient way to do this.
Since the Junit jar file is already in my project, could it be used as an alternative to this browser testing and, if so, any tips on how to get started making JUnit simulate the act of opening a browser to access the web app?
Take a look at Selenium. It allows you to script functional tests using JUnit or TestNG and execute them in a browser, automatically.
You can use the HTMLUnit extension to script to drive the web site from JUnit.
I used a while back and worked fine for thi site I was doing then.
see http://htmlunit.sourceforge.net/
I suggest you to try the Robot Framework. This is an open source testing framework developed by engineers in Nokia Siemens Networks.
It is primarily built on python and the Selenium testing libraries. It also includes support for testing Java/J2EE server side code through Jython libraries. I personally use it in my work sometimes, and writing a test case is just as easy as describing an end-to-end flow through the use of Keywords (most of required ones are already inbuilt). You could go ahead and give this a shot if you find Selenium a li'l tough to work with. The Robot framework provides a fairly simple abstraction over raw selenium, coupled with the power to make Java/J2EE server-side calls too.
Regards,
Nagendra U M