Ajaxã¾ããã®testãã§ããªãã¦æ©ãã§ãã話
ãä»äºã§ä½ã£ã¦ããwebã¢ããªã±ã¼ã·ã§ã³ã¯Ajaxããã£ããåãå ¥ãã¦ããã®ã§ãããæ®å¿µãªããWicketTesterã§Ajaxã¾ããã®ãã¹ãã¯ã§ããªãã®ã§ãã
Seleniumãªãã§ããããªã¼ã¨æã£ã¦å®é¨ãã¦ã¿ãã®ã ãã©ããã£ãããã§ããªãã£ã話ã
TextFieldã«ãããæ°åãï¼ä¹ãã¦ã¨ãªãã®Labelã«è¡¨ç¤ºãã¦ãããç°¡åãªãã¼ã¸ãä½ã£ã¦ãã¹ãã
package jp.ne.hatena.syoko_sasaki; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.OnChangeAjaxBehavior; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.basic.Label; import org.apache.wicket.markup.html.form.TextField; import org.apache.wicket.model.PropertyModel; public class AjaxPage extends WebPage { private static final long serialVersionUID = 1L; private final Integer num1 = 0; private Integer num2 = 0; public AjaxPage() { TextField<Integer> num1Field = new TextField<Integer>("num1", new PropertyModel<Integer>(this, "num1")); final Label num2Label = new Label("num2", new PropertyModel<Integer>( this, "num2")); num2Label.setOutputMarkupId(true); num1Field.add(new OnChangeAjaxBehavior() { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget target) { if (num1 != null) { num2 = num1 * num1; } target.add(num2Label); } }); add(num1Field); add(num2Label); } }
<html> <head> <title>ã«ãããï¼</title> </head> <body> äºä¹ãããï¼<br> <input type="text" wicket:id="num1" /> <span wicket:id="num2" /> </body> </html>
è¦ãç®ã¯ãããªæã
Seleniumã®ãã¹ãã¯ãããªæãã
@Override public void setUp() throws Exception { setUp("http://localhost:8080/?0", "*firefox"); } public void testname() throws Exception { selenium.open("/"); selenium.type("xpath=//input", "3"); ããããã//ããã§ã¨ã©ã¼ã0ãå ¥ã£ã¦ãã¾ãã£ã¦è¨ãããã assertThat(selenium.getValue("xpath=//span"), is("9")); selenium.waitForPageToLoad("30000"); }
debugå®è¡ãã¦èµ·åããfirefoxè¦ã¦ã¿ãã¨ãnum1ã«ã¯ï¼ãå
¥ã£ã¦ããã®ã§ãããnum2ã¯åæå¤0ã®ã¾ã¾ã
å³ã¯ãªãã¯ã§ã½ã¼ã¹ã表示ããããselenium.getHtmlSource()ãã¦ã¿ãã¨ãããããnum1ã®valueã¯0ã§ããããããã¸ãã¯Ajaxã®ä»æ§ãªã®ãï¼
ãã¼ããAjaxã¾ããã®ãã¹ããHudsonããã«æ¯æ¥ã¾ããã¦ãããè¨ç»ãããã
æåãã¹ãå«ããªã®ã§ããªã«ãããæ¹æ³ãã£ããæãã¦ã»ããã§ãã