提交 920f20fd 编写于 作者: K Kohsuke Kawaguchi

Fixing a test

Previously, when the 2nd `e.click()` is called, the page has already transitioned to another page, so the anchor objects have become invalid.

HtmlUnit somehow still manages to follow a link, except when there's some JavaScript attached to the onclick() handler it's going to execute in a strange environment. Some management link requires a POST, and that was done via JavaScript. So that broke the test.
上级 ac878e01
......@@ -31,6 +31,7 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.JenkinsRule.WebClient;
import java.util.List;
......@@ -47,11 +48,15 @@ public class ManagementLinkTest {
*/
@Test
public void links() throws Exception {
HtmlPage page = j.createWebClient().goTo("manage");
List<?> anchors = DomNodeUtil.selectNodes(page, "id('management-links')//*[@class='link']/a[not(@onclick)]");
assertTrue(anchors.size()>=8);
for(HtmlAnchor e : (List<HtmlAnchor>) anchors) {
e.click();
WebClient wc = j.createWebClient();
for (int i=0; ; i++) {
HtmlPage page = wc.goTo("manage");
List<?> anchors = DomNodeUtil.selectNodes(page, "id('management-links')//*[@class='link']/a[not(@onclick)]");
assertTrue(anchors.size()>=8);
if (i==anchors.size()) return; // done
((HtmlAnchor)anchors.get(i)).click();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册