| | 1 | 前段时间,公司passport系统升级,jWebUnit 小弑牛刀! |
| | 2 | {{{ |
| | 3 | /* |
| | 4 | * To change this template, choose Tools | Templates |
| | 5 | * and open the template in the editor. |
| | 6 | */ |
| | 7 | package cn.pconline.junit; |
| | 8 | |
| | 9 | import net.sourceforge.jwebunit.junit.WebTester; |
| | 10 | import org.junit.Before; |
| | 11 | import org.junit.Test; |
| | 12 | |
| | 13 | /** |
| | 14 | * |
| | 15 | * @author pc |
| | 16 | */ |
| | 17 | public class ItbbsPassportTest { |
| | 18 | |
| | 19 | private WebTester tester; |
| | 20 | |
| | 21 | @Before |
| | 22 | public void setUp() { |
| | 23 | tester = new WebTester(); |
| | 24 | tester.setBaseUrl("http://itbbs.pconline.com.cn"); |
| | 25 | } |
| | 26 | |
| | 27 | /** |
| | 28 | * 测试前台登陆 |
| | 29 | */ |
| | 30 | @Test |
| | 31 | public void login() { |
| | 32 | |
| | 33 | tester.beginAt("/index.jsp"); |
| | 34 | tester.setTextField("username", "chenyaokang"); |
| | 35 | tester.setTextField("password", "chenyaokang"); |
| | 36 | tester.submit(); |
| | 37 | |
| | 38 | tester.assertTextPresent("欢迎回来"); |
| | 39 | tester.assertCookiePresent("common_session_id"); |
| | 40 | tester.assertCookieValueEquals("cmu", "chenyaokang"); |
| | 41 | } |
| | 42 | |
| | 43 | /** |
| | 44 | * 测试前台退出 |
| | 45 | */ |
| | 46 | @Test |
| | 47 | public void logout() { |
| | 48 | tester.beginAt("/index.jsp"); |
| | 49 | tester.setTextField("username", "chenyaokang"); |
| | 50 | tester.setTextField("password", "chenyaokang"); |
| | 51 | tester.submit(); |
| | 52 | |
| | 53 | tester.clickLinkWithText("[退出]", 0); |
| | 54 | tester.assertTextNotPresent("chenyaokang"); |
| | 55 | } |
| | 56 | |
| | 57 | /** |
| | 58 | * 测试后台登陆 |
| | 59 | */ |
| | 60 | @Test |
| | 61 | public void loginAdmin(){ |
| | 62 | |
| | 63 | tester.beginAt("/admin/login.jsp"); |
| | 64 | tester.setTextField("username", "xxxx"); |
| | 65 | tester.setTextField("password", "xxxx"); |
| | 66 | tester.submit(); |
| | 67 | |
| | 68 | tester.assertTextPresent("前台帐号登陆"); |
| | 69 | tester.assertTextPresent("itbbscy"); |
| | 70 | |
| | 71 | tester.setTextField("password", "itbbscy"); |
| | 72 | tester.submit(); |
| | 73 | |
| | 74 | tester.assertTextPresent("感谢您使用论坛后台管理系统"); |
| | 75 | |
| | 76 | } |
| | 77 | |
| | 78 | } |
| | 79 | |
| | 80 | |
| | 81 | }}} |