Er... what's going on. I unsubbed from this list in June...
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Julien HENRY Sent: Friday, August 10, 2007 10:15 AM To: Usage problems for JWebUnit Subject: [JWebUnit-users] RE : Verifying Alert messages Hi Michael, JavaScript alert/confirm/input support is not as good as it should be. The problem is I wanted to find an API that could hide the differences between HtmlUnit and Selenium. HtmlUnit uses a listener design pattern. You should register listeners for alert/confirm/input, and when an alert raises, the listener is activated. Basically, the programming model could be: myHandler = new MyAlertHandlerThatStoreAlert(); webClient.addAlertHandler(myHandler); //call something that raises an alert ... assertEquals("foo", myHandler.getLatestAlert()) Selenium works differently. When an alert occurs, you have to check for its presence just after the last call of a Selenium command. If not, an exception is thrown. Of course for input and confirm, you have to tell Selenium in advance what it should respond. The first limitation of Selenium is it can't handle 2 consecutive alert/confirm/input. The second limitation is you have to know the full content of the JavaScript dialog. AFAIK you can't retrieve the content of the box for future usage. How can you write your test if the alert returns the current date/time ? A code example: selenium.chooseCancelOnNextConfirmation(); selenium.click(...) selenium.assertConfirmation("foo"); With JWebUnit, I would like to find the easiest way to: 1) Tell what to respond for input(s) and confirmation(s) 2) Assert/Retrieve the text of the alert(s)/confirm(s)/input(s) (retrieve is currently impossible with Selenium) In your case, you should use: tester.setExpectedJavaScriptAlert(message); //Put "message" in a queue tester.clickButton("Forward"); // If an alert with message "message" occurs, it is removed from the queue tester.closeBrowser(); //When you close the browser, there is a check to see if no expected JavaScript alert do not occured. The problem is it force you to close conversation and end the test. We should add a new assertion like: tester.assertExpectedJavaScriptDialogQueueEmpty() or something like that... Hope I was of any help ++ Julien --- [EMAIL PROTECTED] a écrit : > I am trying to verify that an alert message is fired > when I push a > button. > > I have tried using the setExpectedJavaScriptAlert() > method but I > couldn't get it to work. > > Does someone have any examples on how to test > Javascript Alert messages? > > > > > To be able to test something I used the following > code. > > try { > tester.clickButton("Forward"); > fail("Expected an alert wih message: " + message); > } catch (RuntimeException e) { > assertTrue(0 < e.getMessage().indexOf(message)); > } > > > > > > Regards, Michael Danielsson > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? > Stop. > Now Search log events and configuration files using > AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/> _______________________________________________ > JWebUnit-users mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/jwebunit-users > _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ JWebUnit-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jwebunit-users ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ JWebUnit-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jwebunit-users
