2017-04-22 38 views
0

我是htmlunit的新手,需要爲使用htmlunit編寫的網頁進行測試。該登錄頁面中沒有任何表單。htmlunit knockout js不工作。點擊提交按鈕返回相同頁面

下面是用戶名,密碼的HTML代碼,並提交按鈕 - 現在

<div class="loader-mask" data-bind="visible: false"> 
        <div class="loader"> Loading Form...</div> 
       </div> 
       <div class="form-group"> 
        <label class="control-label">Email ID:</label> 
        <input type="text" name="username" class="form-control" placeholder="[email protected]" data-bind=" 
         value: loginHandler.userEmail, 
         enterKey: signIn 
        "> 
       </div><!-- /.form-group --> 
       <div class="form-group"> 
        <label class="control-label">Password:</label> 
        <input type="password" name="password" class="form-control" placeholder="Passwords are case-sensitive" data-bind=" 
         value: loginHandler.userPassword, 
         enterKey: signIn 
        "> 
       </div><!-- /.form-group --> 
       <div class="text-right"> 
        <p><button type="button" id="qaSignIn" class="btn btn-default" data-bind=" 
         click: signIn, 
         disable: loginHandler.isLoggingIn, 
         continueOn: userLoggedIn, 
         continueLink: { link: 'dashboard.html', params: {} } 
        "> 

,在的HtmlUnit,我能夠得到的用戶名,密碼和按鍵容易,我能夠爲用戶名設定值和密碼字段,但當我點擊按鈕,它返回相同的HTML登錄頁面。我已經嘗試使用瀏覽器的憑據登錄,並且可以在那裏登錄。所以憑證很好。

我的代碼的HtmlUnit是 -

HtmlTextInput htmlInputUsername = (HtmlTextInput) loginPage.getElementByName("username"); 
htmlInputUsername.setValueAttribute("myUserName"); 
HtmlPasswordInput htmlInputPassword = (HtmlPasswordInput) loginPage.getElementByName("password"); 
htmlInputPassword.setValueAttribute("myPassword"); 
HtmlButton htmlButton = (HtmlButton) loginPage.getElementById("qaSignIn"); 
loginPage = htmlButton.click(); 

我之前並點擊登錄按鈕,但其返回相同的XML頁面後試圖打印page.asXml()。任何想法我做錯了什麼? 我甚至嘗試設置這些選項 - 提前

webClient.getOptions().setUseInsecureSSL(true); 
webClient.getCookieManager().setCookiesEnabled(true); 
webClient.getOptions().setJavaScriptEnabled(false); 
webClient.getOptions().setCssEnabled(true); 
webClient.getOptions().setRedirectEnabled(true); 
webClient.setAjaxController(new NicelyResynchronizingAjaxController()); 
webClient.waitForBackgroundJavaScript(30000); 

感謝。

回答

1

不知道網址來分析你的網頁我只能猜測。

在第一次嘗試啓用javascript

webClient.getOptions().setJavaScriptEnabled(true); 

在第二

webClient.waitForBackgroundJavaScript(30000); 

不是一個選項。在WebClient安裝過程中這樣做毫無用處。您必須在點擊後發出此呼叫

loginPage = htmlButton.click(); 
webClient.waitForBackgroundJavaScript(30000); 

也許這是一個使用WETATOR(www.wetator.org)進行測試的選項。與網頁的互動非常簡單,所有等待魔法都會自動完成。

+0

沒有什麼幫助。謝謝 ,但現在的下一個問題 - 當我登錄到瀏覽器中的應用程序,我看到提交按鈕被禁用了一段時間,然後它重定向到下一頁。 在我們的代碼中,點擊按鈕返回的頁面有按鈕被禁用,就是這樣。之後沒有任何事情發生。這不是重新引導到下一頁。 –

+0

還有一件事我檢查了我的頁面,有很多

0

JS的AJAX可能有這樣的代碼 「window.location.href」。那麼你應該做這樣的代碼:

List<WebWindow> webWindows = client.getWebWindows(); 
WebWindow webWindow = webWindows.get(0); 
HtmlPage page = (HtmlPage) webWindow.getEnclosedPage();