Testing internationalized sites
jabko Feb 20, 2008 6:15 PMHi,
I wanted to test if I display correct messages on a page regarding action taken by a user. I use polish letters and therefore I have some problems with it. As far as I know pages are encoded in UTF-8 standard in JSF by default . I load my messages from bundles (properties file) and they are displayed correctly in the browser. If you check the source of the page I can see polish letters encoded with UTF-8 i.e.
<span id="loginForm:passwordOut">Has'an encoded UTF-8 letter goes here'o:</span>
Of course messages loaded from bundle are decoded correctly ( I see them in debug mode ;) )
The problem appears when I want to check if a message loaded from the bundle message is equal to the message in html element. My test scenario: I send action to the server and than I want to get response and compare text within elements with a given text from Bundle Messages. See code below:
public void testWrongLogin() throws MalformedURLException, IOException, SAXException{ JSFClientSession client = new JSFClientSession("/pages/login/signin.jsf"); RichFacesClient rfClient = new RichFacesClient(client); JSFServerSession server = new JSFServerSession(client); //set a wrong login client.setParameter("loginForm:loginIn", "wrongLogin"); //if the login is wrong password doesn't matter client.setParameter("loginForm:passwordIn", "passwordNotImportant"); rfClient.ajaxSubmit("loginForm:loginAction"); String wrongLoginMessage = BundleUtil.getMessageResourceString("loginMsg", "signin_wrongLoginOrPassword", null, server.getFacesContext()); WebResponse webResponse = client.getWebResponse(); HTMLElement element = webResponse.getElementWithID("loginForm:loginErrorPanel"); assertEquals(wrongLoginMessage, element.getText()); }
In that case as a text within checked element I get text with '?' instead of polish letters. Why these text isn't decoded correctly into String in Java. Do you know what can be the problem? Any workaround?
P.s. If I check encoding in browsers (IE, Firefox) it's still UTF-8.
Thanks for help
jabko