public static void main(String[] args) throws Exception { HttpUnitOptions.setScriptingEnabled(false); HttpUnitOptions.setExceptionsThrownOnScriptError(false); HttpUnitOptions.setExceptionsThrownOnErrorStatus(false); WebConversation client = new WebConversation(); doAnonymousLogin(client, "Player 1"); System.out.println(); doJoinGame(client); }
public WebResponse loginForm(String username, String password) throws Exception { WebConversation conversation = new WebConversation(); HttpUnitOptions.setScriptingEnabled(false); HttpUnitOptions.setExceptionsThrownOnScriptError(false); WebRequest request = new GetMethodWebRequest("http://localhost:8084/LeaveApp/index.jsp"); WebResponse response = conversation.getResponse(request); WebForm loginform = response.getForms()[0]; loginform.setParameter("username", username); loginform.setParameter("password", password); request = loginform.getRequest("submitbutton"); response = conversation.getResponse(request); return response; }
private String getMessageEncoding() { return _messageEncoding == null ? /* Fixing 1705925: HttpUnitUtils.DEFAULT_CHARACTER_SET */ HttpUnitOptions.getDefaultCharacterSet() : _messageEncoding; }
private void refreshMembersList() { if (HttpUnitOptions.isScriptingEnabled()) { tester.clickLink("refresh-dependant-fields"); } else { tester.submit("refresh"); } }
private static String useGoogleTranslator(String text, TranslationType type) { String response = ""; String urlString = "http://translate.google.com/translate_t?text=" + text + "&langpair=" + type.getID(); // disable scripting to avoid requiring js.jar HttpUnitOptions.setScriptingEnabled(false); // create the conversation object which will maintain state for us WebConversation wc = new WebConversation(); // Obtain the google translation page WebRequest webRequest = new GetMethodWebRequest(urlString); // required to prevent a 403 forbidden error from google webRequest.setHeaderField("User-agent", "Mozilla/4.0"); try { WebResponse webResponse = wc.getResponse(webRequest); // NodeList list = webResponse.getDOM().getDocumentElement().getElementsByTagName("div"); try { NodeList list2 = XPathAPI.selectNodeList(webResponse.getDOM(), "//span[@id='result_box']/span/text()"); for (int i = 0; i < list2.getLength(); ++i) { response = response + list2.item(i).getNodeValue() + " "; } } catch (TransformerException e) { Log.warning("Translator error", e); } // int length = list.getLength(); // for (int i = 0; i < length; i++) { // Element element = (Element)list.item(i); // if ("result_box".equals(element.getAttribute("id"))) { // Node translation = element.getFirstChild(); // if (translation != null) { // response = translation.getNodeValue(); // } // } // } } catch (MalformedURLException e) { Log.error("Could not for url: " + e); } catch (IOException e) { Log.error("Could not get response: " + e); } catch (SAXException e) { Log.error("Could not parse response content: " + e); } return response; }
public void setUp() throws Exception { logger.info("Entered setUp for TC18"); HttpUnitOptions.setScriptingEnabled(false); // open the session session = HibernateUtil.getSessionFactory().openSession(); userDao = new UserDao(session); bookDao = new BookDao(session); loandao = new LoanDao(session); userService = new UserService(userDao, loandao); bookService = new BookService(bookDao, loandao); loanService = new LoanService(loandao); logger.info("Exited setUp for TC18"); }
protected void onSetUp() { super.onSetUp(); HttpUnitOptions.setExceptionsThrownOnErrorStatus(true); HttpUnitOptions.setExceptionsThrownOnScriptError(false); HttpUnitOptions.setScriptingEnabled(true); ClientProperties.getDefaultProperties().setAcceptCookies(true); ClientProperties.getDefaultProperties().setAutoRedirect(true); IDatabaseConnection connection = null; try { connection = getConnection(); DatabaseOperation.DELETE_ALL.execute(connection, getDataSet()); DatabaseOperation.CLEAN_INSERT.execute(connection, getDataSet()); } catch (Exception ex) { ex.printStackTrace(); } finally { if (connection != null) { try { connection.getConnection().close(); } catch (SQLException e) { e.printStackTrace(); } } } }
public void tearDown() { HttpUnitOptions.setScriptingEnabled(false); super.tearDown(); }
public void setUp() { super.setUp(); restoreData("TestDraftWorkflow.xml"); HttpUnitOptions.setScriptingEnabled(true); }
public void setUp() { super.setUp(); administration.restoreData("TestEditNestedGroups.xml"); HttpUnitOptions.setScriptingEnabled(true); }
public void testSimpleUser() throws Exception { WebConversation connection = new WebConversation(); WebResponse loginPage = connection.getResponse(buildUrl("silverpeas/")); assertNotNull(loginPage); WebForm loginForm = loginPage.getFormWithName("EDform"); assertNotNull(loginForm); loginForm.setParameter("Login", "SilverAdmin"); loginForm.setParameter("Password", "SilverAdmin"); HttpUnitOptions.setScriptingEnabled(false); WebResponse welcomePage = loginForm.submit(); assertNotNull(welcomePage); String[] frameNames = welcomePage.getFrameNames(); assertEquals(5, frameNames.length); WebResponse navigationFrame = connection.getFrameContents("bottomFrame"); assertNotNull(navigationFrame); navigationFrame = connection.getFrameContents("SpacesBar"); assertNotNull(navigationFrame); WebLink mailingListLink = navigationFrame.getLinkWith("Liste de diffusion"); assertNotNull(mailingListLink); HttpUnitOptions.setScriptingEnabled(false); WebResponse activityPage = connection.getResponse(buildUrl(mailingListLink.getURLString())); assertNotNull(activityPage); WebTable browseBar = activityPage.getTableWithID("browseBar"); assertNotNull(browseBar); assertEquals("MGI Coutier > Liste de diffusion > Activité", browseBar.getCellAsText(0, 0)); assertEquals( "Main", browseBar.getTableCell(0, 0).getLinkWith("Liste de diffusion").getURLString()); WebTable tableDescription = activityPage.getTableWithID("description"); assertNotNull(tableDescription); String description = tableDescription.getCellAsText(1, 0); assertEquals("Liste de diffusion de test", description); WebTable tableAddress = activityPage.getTableWithID("subscribedAddress"); assertNotNull(tableAddress); String subscribedAddress = tableAddress.getCellAsText(1, 0); assertEquals("*****@*****.**", subscribedAddress); WebTable tableHistory = activityPage.getTableWithID("activities"); assertNotNull(tableHistory); assertEquals("Historique des Messages", tableHistory.getCellAsText(0, 0)); assertEquals("2007", tableHistory.getCellAsText(2, 0)); assertEquals("", tableHistory.getCellAsText(2, 1)); assertEquals("", tableHistory.getCellAsText(2, 2)); assertEquals("", tableHistory.getCellAsText(2, 3)); assertEquals("", tableHistory.getCellAsText(2, 4)); assertEquals("", tableHistory.getCellAsText(2, 5)); assertEquals("", tableHistory.getCellAsText(2, 6)); assertEquals("", tableHistory.getCellAsText(2, 7)); assertEquals("", tableHistory.getCellAsText(2, 8)); assertEquals("", tableHistory.getCellAsText(2, 9)); assertEquals("", tableHistory.getCellAsText(2, 10)); assertEquals("2", tableHistory.getCellAsText(2, 11)); assertEquals("2", tableHistory.getCellAsText(2, 12)); assertEquals("1", tableHistory.getCellAsText(3, 1)); assertEquals("3", tableHistory.getCellAsText(3, 2)); assertEquals("3", tableHistory.getCellAsText(3, 3)); assertEquals("", tableHistory.getCellAsText(3, 4)); assertEquals("", tableHistory.getCellAsText(3, 5)); assertEquals("", tableHistory.getCellAsText(3, 6)); assertEquals("", tableHistory.getCellAsText(3, 7)); assertEquals("", tableHistory.getCellAsText(3, 8)); assertEquals("", tableHistory.getCellAsText(3, 9)); assertEquals("", tableHistory.getCellAsText(3, 10)); assertEquals("", tableHistory.getCellAsText(3, 11)); assertEquals("", tableHistory.getCellAsText(3, 12)); assertEquals( "list/mailinglist45/currentYear/2007/currentMonth/11", tableHistory.getTableCell(2, 12).getLinkWith("2").getURLString()); assertEquals( "list/mailinglist45/currentYear/2008/currentMonth/2", tableHistory.getTableCell(3, 3).getLinkWith("3").getURLString()); WebTable tableMessages = activityPage.getTableWithID("messages"); assertNotNull(tableMessages); assertEquals("Message récents", tableMessages.getCellAsText(0, 0)); assertEquals("Simple database message 3", tableMessages.getCellAsText(1, 0)); assertEquals( MESSAGE_BASE + 3, tableMessages.getTableCell(1, 0).getLinkWith("Simple database message 3").getURLString()); assertEquals( "[email protected] - 02/03/2008 10:34:15", tableMessages.getCellAsText(2, 0)); assertEquals( "Bonjour famille Simpson, j\'espère que vous allez bien. Ici " + "tout se passe bien et Krusty est très sympathique. Surtout depuis que " + "Tahiti Bob est retourné en prison. Je dois remplacer l\'homme canon " + "dans ...", tableMessages.getCellAsText(3, 0)); assertEquals(MESSAGE_BASE + 3, tableMessages.getTableCell(3, 0).getLinks()[0].getURLString()); assertEquals("Simple database message 4", tableMessages.getCellAsText(4, 0)); assertEquals( MESSAGE_BASE + 4, tableMessages.getTableCell(4, 0).getLinkWith("Simple database message 4").getURLString()); assertEquals( "[email protected] - 02/03/2008 10:12:15", tableMessages.getCellAsText(5, 0)); assertEquals( "Bonjour famille Simpson, j\'espère que vous allez bien. Ici " + "tout se passe bien et Krusty est très sympathique. Surtout depuis que " + "Tahiti Bob est retourné en prison. Je dois remplacer l\'homme canon " + "dans ...", tableMessages.getCellAsText(6, 0)); assertEquals(MESSAGE_BASE + 4, tableMessages.getTableCell(6, 0).getLinks()[0].getURLString()); assertEquals("Simple database message 1", tableMessages.getCellAsText(7, 0)); assertEquals( MESSAGE_BASE + 1, tableMessages.getTableCell(7, 0).getLinkWith("Simple database message 1").getURLString()); assertEquals( "[email protected] - 01/03/2008 10:34:15", tableMessages.getCellAsText(8, 0)); assertEquals( "Bonjour famille Simpson, j\'espère que vous allez bien. Ici " + "tout se passe bien et Krusty est très sympathique. Surtout depuis que " + "Tahiti Bob est retourné en prison. Je dois remplacer l\'homme canon " + "dans ...", tableMessages.getCellAsText(9, 0)); assertEquals(MESSAGE_BASE + 1, tableMessages.getTableCell(9, 0).getLinks()[0].getURLString()); assertEquals("Simple database message 11", tableMessages.getCellAsText(10, 0)); assertEquals( MESSAGE_BASE + 11, tableMessages.getTableCell(10, 0).getLinkWith("Simple database message 11").getURLString()); assertEquals( "[email protected] - 21/02/2008 10:34:15", tableMessages.getCellAsText(11, 0)); assertEquals( "Bonjour famille Simpson, j\'espère que vous allez bien. Ici " + "tout se passe bien et Krusty est très sympathique. Surtout depuis que " + "Tahiti Bob est retourné en prison. Je dois remplacer l\'homme canon " + "dans ...", tableMessages.getCellAsText(12, 0)); assertEquals(MESSAGE_BASE + 11, tableMessages.getTableCell(12, 0).getLinks()[0].getURLString()); WebTable tableTabbedPane = activityPage.getTableWithID("tabbedPane"); assertNotNull(tableTabbedPane); tableTabbedPane = tableTabbedPane.getTableCell(0, 0).getTables()[0]; assertNotNull(tableTabbedPane); assertEquals("Activité", tableTabbedPane.getCellAsText(0, 2)); assertEquals("Liste des Messages", tableTabbedPane.getCellAsText(0, 5)); assertFalse(activityPage.getText().indexOf("Modération") > 0); assertFalse(activityPage.getText().indexOf("Abonnés Extérieurs") > 0); }
public void login() throws Exception { wc = new WebConversation(); // wc.setProxyServer("127.0.0.1", 8888); HttpUnitOptions.setDefaultCharacterSet("utf-8"); HttpUnitOptions.setScriptingEnabled(false); HttpUnitOptions.setExceptionsThrownOnScriptError(false); // HttpUnitOptions.setLoggingHttpHeaders(true); HttpUnitOptions.setAcceptCookies(true); wc.setUserAgent( "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.83 Safari/535.11"); ClientProperties.getDefaultProperties().setAcceptCookies(true); WebResponse rs; // rs= wc.getResponse("http://web2.qq.com/"); // setCookie(rs); String url = "http://ptlogin2.qq.com/check?uin=" + this.id + "&appid=1003903&r=0.2842747748363763"; rs = wc.getResponse(url); setCookie(rs); log.info("response:" + rs.getText()); String verifycode = rs.getText().split(",")[1].replaceAll("'", "").replace(");", ""); log.info(this.toString() + " verifycode:" + verifycode); // 需要输入验证码 if (verifycode.length() > 10) { log.error("需要验证码!"); log.info( "验证码地址:" + "http://captcha.qq.com/getimage?aid=1003903&r=0.3318515357095748&uin=" + this.id); BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); verifycode = stdin.readLine(); // throw new Exception("需要验证码!"); } String p = PasswordEncrypt.passwordEcrypt(this.password, verifycode); log.info("p:" + p); ; GetMethodWebRequest get = new GetMethodWebRequest("http://ptlogin2.qq.com/login"); get.setParameter("u", this.id); get.setParameter("p", p); get.setParameter("verifycode", verifycode); get.setParameter("webqq_type", "10"); get.setParameter("remember_uin", "1"); get.setParameter("login2qq", "1"); get.setParameter("aid", "1003903"); get.setParameter("u1", "http://web2.qq.com/loginproxy.html?login2qq=1&webqq_type=10"); get.setParameter("h", "1"); get.setParameter("ptredirect", "0"); get.setParameter("ptlang", "2052"); get.setParameter("from_ui", "1"); get.setParameter("pttype", "1"); get.setParameter("dumy", ""); get.setParameter("fp", "loginerroralert"); get.setParameter("action", "2-21-6717"); get.setParameter("mibao_css", "m_webqq"); rs = wc.getResponse(get); setCookie(rs); log.info("response:" + rs.getText()); rs = wc.getResponse("http://web2.qq.com/loginproxy.html?login_level=3"); setCookie(rs); PostMethodWebRequest post = new PostMethodWebRequest("http://d.web2.qq.com/channel/login2"); String ptwebqq = wc.getCookieValue("ptwebqq"); log.info("ptwebqq:" + ptwebqq); String r = "{\"status\":\"online\",\"ptwebqq\":\"" + ptwebqq + "\",\"passwd_sig\":\"\",\"clientid\":\"64768904\",\"psessionid\":null}"; // {"status":"online","ptwebqq":"94355c82e5692825e17a1d95c672b6371e71dec45399845b6d3f14fb23557dfb","passwd_sig":"","clientid":"42599326","psessionid":null} // {"status":"","ptwebqq":"7896466821f021f41ba65eb83d689e671d7b08eb02c0c165ef8589bb772cf9db","passwd_sig":"","clientid":"64768904","psessionid":null} post.setParameter("r", r); wc.setHeaderField("Referer", "http://d.web2.qq.com/proxy.html?v=20110331002&callback=2"); // setCookie(rs); // wc.putCookie("pgv_pvid", "215336480"); // wc.putCookie("pgv_flv", "10.1 r102"); // wc.putCookie("pgv_info", "pgvReferrer=&ssid=s7792437458"); rs = wc.getResponse(post); log.info("login response:" + rs.getText()); JSONObject result = new JSONObject(rs.getText()).getJSONObject("result"); this.psessionid = result.getString("psessionid"); this.vfwebqq = result.getString("vfwebqq"); log.info("psessionid:" + psessionid); }