-
Notifications
You must be signed in to change notification settings - Fork 16
/
HtmlUnitPlugin.java
99 lines (85 loc) · 3.2 KB
/
HtmlUnitPlugin.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.nordstrom.automation.selenium.plugins;
import java.lang.reflect.Constructor;
import java.util.Map;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import com.nordstrom.automation.selenium.SeleniumConfig;
import net.bytebuddy.implementation.Implementation;
import net.bytebuddy.implementation.MethodCall;
public class HtmlUnitPlugin extends RemoteWebDriverPlugin {
public HtmlUnitPlugin() {
super(HtmlUnitCaps.DRIVER_NAME);
}
/**
* <b>org.openqa.selenium.htmlunit.HtmlUnitDriver</b>
*
* <pre><dependency>
* <groupId>org.seleniumhq.selenium</groupId>
* <artifactId>htmlunit-driver</artifactId>
* <version>2.70.0</version>
*</dependency></pre>
*/
private static final String[] DEPENDENCY_CONTEXTS = {
"org.openqa.selenium.htmlunit.HtmlUnitDriver", "org.openqa.selenium.By",
"org.openqa.selenium.support.FindBy", "com.gargoylesoftware.htmlunit.Version",
"org.apache.commons.lang3.CharSet", "org.apache.commons.text.WordUtils",
"org.apache.http.client.HttpClient", "org.apache.http.HttpHost",
"org.apache.http.entity.mime.MIME", "org.apache.commons.codec.Encoder",
"org.apache.commons.io.IOUtils", "org.apache.commons.logging.Log",
"org.eclipse.jetty.websocket.client.WebSocketClient",
"org.eclipse.jetty.util.IO", "org.eclipse.jetty.io.EndPoint",
"org.eclipse.jetty.websocket.common.Parser",
"org.eclipse.jetty.websocket.api.Session",
"net.sourceforge.htmlunit.xpath.XPath",
"net.sourceforge.htmlunit.corejs.javascript.Token",
"net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter",
"com.gargoylesoftware.css.util.LangUtils",
"org.apache.commons.net.io.Util", "org.eclipse.jetty.client.Origin",
"org.eclipse.jetty.http.Syntax", "org.brotli.dec.Utils"
};
private static final String WEB_ELEMENT_CLASS_NAME =
"org.openqa.selenium.htmlunit.HtmlUnitWebElement";
/**
* {@inheritDoc}
*/
@Override
public String[] getDependencyContexts() {
return DEPENDENCY_CONTEXTS;
}
/**
* {@inheritDoc}
*/
@Override
public String getCapabilities(SeleniumConfig config) {
return HtmlUnitCaps.getCapabilities();
}
/**
* {@inheritDoc}
*/
@Override
public Map<String, String> getPersonalities() {
return HtmlUnitCaps.getPersonalities();
}
/**
* {@inheritDoc}
*/
@Override
public String[] getPropertyNames(String capabilities) {
return HtmlUnitCaps.getPropertyNames(capabilities);
}
/**
* {@inheritDoc}
*/
@Override
public Implementation getWebElementCtor(WebDriver driver, Class<? extends WebElement> refClass) {
if (refClass.getName().equals(WEB_ELEMENT_CLASS_NAME)) {
try {
Constructor<?> ctor = refClass.getConstructors()[0];
return MethodCall.invoke(ctor).onSuper().with(driver).with(0).with((Object) null);
} catch (SecurityException eaten) {
// nothing to do here
}
}
return null;
}
}