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.
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.
ReplyDeleteNice 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
According to http://fijiaaron.wordpress.com/2009/09/10/interacting-with-seleniumrc-directly/ ->
ReplyDelete'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” '
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