Tuesday, October 12, 2010

Selenium RC Experience

So I have decided to give Selenium RC a shot and try to automate some of our web app GUI tests. I worked with WinRunner in the past on a waterfall government project and was familiar with ‘record and playback’ features and editing TSL scripts. On that project we abandoned automated tools as scripts updating became too time-consuming and labor-intensive due to the fact that our test environment was never stable enough for automated regression testing. We successfully ran a few automated tests to validate URL links that we had a ton of and for navigation mapping. I both loved and hated using automated tools at the time. Execution time was fast when scripts worked. Debugging and re-writing scripts was not fun however.
In the case with Selenium RC I ran into a 1) lack of programming experience in Java and 2) lack of knowledge of the current application code issues.
I installed Selenium IDE (Firefox Plugin), recorded a couple of simple tests where I would validate user login and a few other actions, exported these tests into Eclipse (I added a JUnit test) and tried to run it. I got an error Response_Code = 401 Error_Message = Unauthorized error. Odd, I thought. I ran the same test in Firefox and was able to log into the app without a problem. So why would not it work from Eclipse?

I checked Selenium documentation and according to it 'open' should have worked -
void open (java.lang.String url) Opens an URL in the test frame. This accepts both relative and absolute URLs. The "open" command waits for the page to load before proceeding, ie. the "AndWait" suffix is implicit. Note: The URL must be on the same domain as the runner HTML due to security restrictions in the browser (Same Origin Policy). If you need to open an URL on another domain, use the Selenium Server to start a new browser session on that domain.

Parameters: url - the URL to open; may be relative or absolute

Here is a partial sample code of what I had -
public void setUp() throws Exception {
 setUp("http://blahhost:port/index.jsp/", "*firefox");
       }
      public void testLogin() throws Exception {
        selenium.open("http://blahhost:port/index.jsp");
        selenium.type(("j_username", "someusername");
        selenium.type("j_password", "somepassword");
        more code.........
      }
I Googled for more info and sent a couple of emails to Agile experts whose blogs I occasionally visit. I did not want to bug programmers on my team yet as they were busy. I gave up however as I got obsessed with it and asked one of the programmers who is sympathetic to automated testing. He searched our code and concluded that we are returning Unauthorized error  when the user logs in. He did not write the code and was not sure why we had it set up this way (response.setStatus(HttpServletResponse.SC_UNAUTHORIZED );)

He then modified the following part that allowed this darn test to run -
public void setUp() throws Exception {
     selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://blahhost:port/") {
      public void open(String url) {
      commandProcessor.doCommand("open", new String[] {url,"true"});
      }
   };
   selenium.start();
}
He was genuinely excited about the tool and promised to help with writing tests and training me when he has time. I felt grateful but discouraged at the same time. How long will it take me to learn the ropes in order to become effective? We are busy as it is and as much as I would like to learn Java programming and figuring out how to write these tests, I do not want to become overwhelmed.

By the way I never heard back from the Agile gurus. It is possible that they either did not receive or did not read my emails. It was certainly easier to get help from James Bach when I really needed it.

3 comments:

  1. Thank you Lena, for this post regarding SeleniumRC for testing web apps using Firefox web browser. Denial of XSS {Cross Site Scripting} or in other words adhering to Same Origin Policy , also seems to be the issue I am running into.

    Nice to see Firefox plucking up this potential security vulnerability. Strangely, I ran the same test suite using SeleniumRC & IE8 and it did not seem to complain. Not sure if any configuration has disabled XSS check.
    It obviously has a XSS filter as indicated here :
    http://blogs.msdn.com/b/ie/archive/2008/07/02/ie8-security-part-iv-the-xss-filter.aspx

    Will try testing with Google Chrome & explore the proxy options that SeleniumRC documents as supported

    ReplyDelete
  2. According to http://fijiaaron.wordpress.com/2009/09/10/interacting-with-seleniumrc-directly/ ->
    'Chrome refers to the base version of Firefox, which has elevated privileges (and thus can avoid cross-site scripting limitations. The equivalent for Internet Explorer is “iehta” '

    ReplyDelete
  3. Amit, thank you for your feedback and info! Please share your Selenium findings with me. I set up a goal to learn this tool so will appreciate your help. Email just in case - cyberian0101@gmail.com

    ReplyDelete