Archive

Archive for the ‘General’ Category

Automating web flow with Selenium and Eclipse IDE

November 21st, 2009

Some of you may already know Selenium. Basically it’s free and open source tool for web application functional testing. It’s mainly know as replacement for HP’s QuickTestProfessional. I’ve recently discovered Selenium as very helpful for automating data setup for load testing.

Here is a small description howto setup Eclipse and run Selenium script through it.

1) Download Eclipse IDE from http://www.eclipse.org/downloads/
2) Download Selenium RC from http://seleniumhq.org/download/
3) Download Junit from http://www.junit.org/
4) Create new project in Eclipse:

  • Go to File -> New -> Java Project
  • enter project name e.g. “Sample”
  • Click “Finish” button

5) Import Selenium and JUnit packages into the project:

  • In Package Explorer right click project “Sample” and select Properties
  • Go to “Java Build Path” then select “Libraries” tab
  • Click “Add External JARs” and import junit-4.7.jar and selenium-java-client-driver.jar

Now our Eclipse environment should be ready. Next step is to prepare a test case in Selenium IDE. I’ve prepared small test that searches for “linux” word in google. To export test case as Java, in Selenium IDE go to Options -> Format -> Java (Junit) Selenium RC. As a result you should get something like this:

  1. package com.example.tests;
  2.  
  3. import com.thoughtworks.selenium.*;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Untitled extends SeleneseTestCase {
  7.         public void setUp() throws Exception {
  8.                 setUp("http://change-this-to-the-site-you-are-testing/", "*chrome");
  9.         }
  10.         public void testUntitled() throws Exception {
  11.                 selenium.open("/");
  12.                 selenium.type("q", "linux");
  13.                 selenium.click("btnG");
  14.         }
  15. }

Default Junit code generated by Selenium doesn’t use Selenium RC. Because of that I updated the code a little bit to connect to localhost Selenium RC on port 4444. Here is updated version:

  1. package com.example.tests;
  2.  
  3. import com.thoughtworks.selenium.*;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Untitled extends SeleneseTestCase {
  7.         public DefaultSelenium selenium;
  8.         public void setUp() throws Exception {
  9.                 selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
  10.                 selenium.start();
  11.         }
  12.         public void testUntitled() throws Exception {
  13.                 selenium.open("/");
  14.                 selenium.type("q", "linux");
  15.                 selenium.click("btnG");
  16.         }
  17. }

Now, lets add it in our Eclipse project:

  • In Package Explorer right click on our “Sample” project and select New -> Class
  • Enter class name “Untitled” and package name “com.example.tests”
  • Click “Finish” button

Before we run our test, we need to start Selenium RC. For that open command line and under selenium-remote-control-1.0.1/selenium-server-1.0.1 run command “java -jar selenium-server.jar”. It will run Selenium RC server on default port 4444.

Now, to start the test just select Run -> Run As -> Junit test. It should open two IE browsers. One for Selenium RC and second with Google results for “linux” word.

Because we run Java code, it’s only up to us how we want to run the test. Below is our example update to search for “linux” word in a loop 5 times with 5 seconds intervals.

  1. package com.example.tests;
  2.  
  3. import com.thoughtworks.selenium.*;
  4. import java.util.regex.Pattern;
  5.  
  6. public class Untitled extends SeleneseTestCase {
  7.         public DefaultSelenium selenium;
  8.         public void setUp() throws Exception {
  9.                 selenium = new DefaultSelenium("localhost", 4444, "*iexplore", "http://www.google.com/");
  10.                 selenium.start();
  11.         }
  12.         public void testUntitled() throws Exception {
  13.                 for(int i = 0; i < 5; i++)
  14.                 {
  15.                         selenium.open("/");
  16.                         selenium.type("q", "linux");
  17.                         selenium.click("btnG");
  18.                         selenium.waitForPageToLoad("10000");
  19.                         Thread.sleep(5000);
  20.                 }
  21.                
  22.         }
  23. }

General ,

GUI flow fuzzing

March 31st, 2009

Fuzz testing is an automated way for checking how application reacts on unexpected input data. This is a type of negative testing. This is also very know technique for automated vulnerability finding.

But I didn’t hear anything about tool that will operate on the GUI in a fuzzy way (or maybe my Google search “kung-fu” isn’t so good). Instead of providing incorrect, trashy data we could provide input values correctly but in wrong order, etc. In general an application should receive not only correct data but correct data in correct order. Example: you shouldn’t be able to save child user while parent user is still not stored in db (this can end up with an exception).

Some kind of GUI fuzzing tool would find it by providing correct data and using correct steps but in completely unexpected order. The other problem is how to fuzz with application logic. Providing input data is simple, but providing steps that user performs on the GUI and then fuzzing the whole logic… hmmm… maybe I could use QTP.

General

WSDL from source code

February 25th, 2009

One (if not the biggest) anti pattern for me is when developer generates WSDL file from source code. Have you ever tried to create HTML page in MS Word? If so, then you know that 90% of the code is crappy. WSDL is a service description. How you want to understand or test it if the code looks like a mess?

Another thing – service description depends on your business. Do you really want to leave it for automated tools? Do they know your business area better?

So, next time when someone gives you WSDL generated from source code, you don’t even have to look at it to reject it.

General ,

HTTP POST or GET

January 27th, 2009

Some time ago I made a little test comparing web services performance using HTTP GET and POST methods. I used the same script, in the same environment with the same web service. HTTP method was the only difference.

I discovered that POST method is twice much faster than request sent using GET method.
You should also know that request size with GET method can be limited, although RFC2616 says:

The HTTP protocol does not place any a priori limit on the length of
   a URI. Servers MUST be able to handle the URI of any resource they
   serve, and SHOULD be able to handle URIs of unbounded length if they
   provide GET-based forms that could generate such URIs.

So if you are planning some web services performance testing or you want to speed up your tests a little bit before customer demo :) you should consider POST HTTP method.

General

Hello on my blog

January 13th, 2009

Hello and welcome on Waldemar’s blog.

General