From: Orod <rez...@ya...> - 2008-02-11 00:59:07
|
Hi Ahmed, Thanks for your reply. Unfortunately, I got sidetracked, and didn't check back to see your reply. The test that you had mentioned does pass, but if you check the page's source, then you'll see it is not the whole page, but only the content of one of the iframes in the page. I did download and used the latest build as you had suggested; however, now the page doesn't even include that iframe, but just empty. Per your suggestion, I have created the following test case that you can run and see the result yourself. Note that I am stumped in the first step since I can't even get the login page correctly, let alone navigate the page and set fields or click on any element. --------------------------- package core.biz.services.sites; import java.io.File; import java.io.FileWriter; import junit.framework.TestCase; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.ThreadedRefreshHandler; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.xml.XmlPage; public class IFrameTestCase extends TestCase { protected WebClient wc = null; private static final String LOGIN_PAGE = "http://my.monster.com/Login.aspx"; private static final String NAME_OF_LOGIN_FORM = "login_form"; private static final String NAME_OF_USER_NAME_FIELD = "login"; private static final String NAME_OF_PASSWORD_FIELD = "passwd"; private static final String NAME_OF_SUBMIT_BUTTON_ELEMENT = ".save"; @org.junit.Before protected void setUp() throws Exception { super.setUp(); wc = new WebClient(BrowserVersion.FIREFOX_2); wc.setJavaScriptEnabled(true); wc.setCookiesEnabled(true); wc.setThrowExceptionOnScriptError(false); wc.setRedirectEnabled(true); wc.setRefreshHandler(new ThreadedRefreshHandler()); } @org.junit.Test public void testCase1() { HtmlPage loginPage = null; try { try { loginPage = (HtmlPage) wc.getPage(LOGIN_PAGE); } catch(Exception e) { e.printStackTrace(); } assertNotNull(loginPage); printPageSource(loginPage, "monsterLoginPage_1.htm"); HtmlForm loginForm = loginPage.getFormByName(NAME_OF_LOGIN_FORM); assertNotNull(loginForm); HtmlInput userNameField = loginForm.getInputByName(NAME_OF_USER_NAME_FIELD); HtmlInput passwordField = loginForm.getInputByName(NAME_OF_PASSWORD_FIELD); assertNotNull(userNameField); assertNotNull(passwordField); userNameField.setValueAttribute("userName"); passwordField.setValueAttribute("password"); HtmlInput submitButton = loginForm.getInputByName(NAME_OF_SUBMIT_BUTTON_ELEMENT); printPageSource(loginPage, "monsterLoginPage_2.htm"); HtmlPage pageAfterLogin = (HtmlPage) submitButton.click(); printPageSource(pageAfterLogin, "monsterLoginPage_2.htm"); assertNotNull(pageAfterLogin); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }//End of try/catch block. } @org.junit.After protected void tearDown() throws Exception { super.tearDown(); } /* just a utility method for saving the page source to a file */ protected void printPageSource(Page page, String fileNameToSaveTheSourceAs) { try { File fileToSavePageTo = new File(fileNameToSaveTheSourceAs); fileToSavePageTo.createNewFile(); FileWriter fileWriter = new FileWriter(fileToSavePageTo); if (page instanceof XmlPage) { fileWriter.write(((XmlPage) page).getContent()); } else if (page instanceof HtmlPage) { fileWriter.write(((HtmlPage) page).asXml()); } fileWriter.flush(); fileWriter.close(); //log.error(((HtmlPage) page).asXml()); } catch (Exception e) { e.printStackTrace(); } }//End of printPageSource(). }//End of class IFrameTestCase. -------------------------- -- View this message in context: http://www.nabble.com/Iframe-With-JavaScript-as-Src-attribute-tp15341965p15403832.html Sent from the HtmlUnit - General mailing list archive at Nabble.com. |