提交 23276180 编写于 作者: T Tom Fennelly

Merge pull request #1918 from tfennelly/htmlunit-fixes

[Fixed JENKINS-31631] Handle YUI submit <button> clicks
......@@ -150,6 +150,12 @@ THE SOFTWARE.
<groupId>org.jvnet.hudson</groupId>
<artifactId>embedded-rhino-debugger</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>org.jvnet.hudson</groupId>
<artifactId>htmlunit-core-js</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- for testing JNLP launch. -->
......
......@@ -28,6 +28,9 @@ import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebClientUtil;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
/**
* {@link HtmlElement} helper methods.
......@@ -58,4 +61,16 @@ public class HtmlElementUtil {
WebClientUtil.waitForJSExec(webClient);
}
}
/**
* Does the supplied element define the specified HTML "class" name.
* @param element The element to check.
* @param className The HTML "class" name to check for.
* @return {@code true} if the element defines the specified class, otherwise {@code false}.
*/
public static boolean hasClassName(HtmlElement element, String className) {
String classAttribute = element.getAttribute("class");
Set<String> classes = new HashSet<>(Arrays.asList(classAttribute.split(" ")));
return classes.contains(className);
}
}
......@@ -37,6 +37,7 @@ import com.gargoylesoftware.htmlunit.WebResponseListener;
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlElementUtil;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlImage;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
......@@ -1341,9 +1342,12 @@ public class JenkinsRule implements TestRule, MethodRule, RootAction {
*/
public HtmlPage submit(HtmlForm form, String name) throws Exception {
for( HtmlElement e : form.getHtmlElementsByTagName("button")) {
HtmlElement p = (HtmlElement)e.getParentNode().getParentNode();
if(e instanceof HtmlButton && p.getAttribute("name").equals(name)) {
return (HtmlPage)HtmlFormUtil.submit(form, (HtmlButton) e);
HtmlElement p = (HtmlElement)e.getParentNode().getParentNode();
if (p.getAttribute("name").equals(name) && HtmlElementUtil.hasClassName(p, "yui-submit-button")) {
// For YUI handled submit buttons, just do a click.
return (HtmlPage) HtmlElementUtil.click(e);
} else if (e.getAttribute("name").equals(name)) {
return (HtmlPage) HtmlFormUtil.submit(form, e);
}
}
throw new AssertionError("No such submit button with the name "+name);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册