use of com.gargoylesoftware.htmlunit.BrowserVersion in project twitter4j by yusuke.
the class OAuthTest method getAccessToken.
private AccessToken getAccessToken(Twitter twitter, String url, RequestToken rt, String screenName, String password, boolean pinRequired) throws TwitterException {
BrowserVersion browserVersion = BrowserVersion.getDefault();
browserVersion.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15");
HtmlUnitDriver driver = new HtmlUnitDriver(browserVersion);
driver.get(rt.getAuthorizationURL());
driver.findElement(By.name("session[username_or_email]")).sendKeys(screenName);
driver.findElement(By.name("session[password]")).sendKeys(password);
driver.findElement(By.id("allow")).click();
if (pinRequired) {
return twitter.getOAuthAccessToken(rt, driver.findElementsByTagName("code").get(0).getText());
} else {
String oauthVerifier = driver.getCurrentUrl().replaceFirst(".*&oauth_verifier=([a-zA-Z0-9]+)$", "$1");
return twitter.getOAuthAccessToken(rt, oauthVerifier);
}
}
use of com.gargoylesoftware.htmlunit.BrowserVersion in project tuerauf-backend-java by dsteinkopf.
the class DashboardTest method setup.
@Before
public void setup() {
final BrowserVersion browserVersion = BrowserVersion.FIREFOX_24;
driver = new HtmlUnitDriver(browserVersion);
((HtmlUnitDriver) driver).setJavascriptEnabled(true);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
use of com.gargoylesoftware.htmlunit.BrowserVersion in project wechat by dllwh.
the class HtmlUnitHandler method getWebClient.
/**
* ----------------------------------------------------- Fields start
*/
/**
* ----------------------------------------------------- Fields end
*/
/**
* ----------------------------------------------- [私有方法]
*/
/**
* @方法描述: 模拟特定浏览器
* @param browser
* @param proxy
* @return
*/
private WebClient getWebClient(CrawlParameter crawlPara) {
/**
* 模拟一个浏览器,可以选择IE、Chrome、Firefox等等
*/
WebClient webClient = null;
BrowserVersion browser = crawlPara.getBrowse();
if (null == crawlPara.getProxy()) {
webClient = new WebClient(browser);
} else {
// 代理服务器的配置,代理的配置很简单,只需要配置好地址、端口、用户名与密码即可
ProxyBean proxy = crawlPara.getProxy();
webClient = new WebClient(browser, proxy.getProxyHost(), proxy.getProxyPort());
}
/**
* 设置webClient的相关参数
*/
// 启用JavaScript解释器,默认为true(对于某些动态页面,这是必须的)
webClient.getOptions().setJavaScriptEnabled(crawlPara.isUseJs());
// 禁用css支持,可避免自动二次请求CSS进行渲染(对于某些动态页面,这是必须的)
webClient.getOptions().setCssEnabled(false);
// 启动客户端重定向
// webClient.getOptions().setRedirectEnabled(true);
// 忽略ssl认证
webClient.getOptions().setUseInsecureSSL(true);
// JavaScript运行错误时,是否抛出异常
webClient.getOptions().setThrowExceptionOnScriptError(false);
// JavaScript运行错误时,是否抛出 response 的错误
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
// 设置连接超时时间 ,这里是10S。如果为0,则无限期等待
webClient.getOptions().setTimeout(10 * 1000);
// 设置Ajax异步
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.setJavaScriptTimeout(600 * 1000);
webClient.getOptions().setActiveXNative(false);
return webClient;
}
use of com.gargoylesoftware.htmlunit.BrowserVersion in project wechat by dllwh.
the class SeleniumHandler method getDriver.
/**
* @方法描述:
* @属性:
* <ul>
* <li>getTitle:用于返回当前网页的标题</li>
* <li>getCurrentUrl:用于获取当前网页的URL:</li>
* <li>getText:用于存储某个元素的文本值.例如链接、纯文本等</li>
* <li>isSelected:用于存储复选框或单选框的勾选情况,返回值为true(勾选)或false(未勾选)</li>
* <li>getTagName:用于获取元素的标记名称</li>
* <li>isEnabled:用于存储input等元素的可编辑状态,如果可以编辑,则返回true, 否则返回false</li>
* </ul>
* @param crawlPara
* @return
*/
private WebDriver getDriver(CrawlParameter crawlPara) {
WebDriver driver = null;
// 模拟浏览器
BrowserVersion browser = crawlPara.getBrowse();
if (browser.isFirefox()) {
// 启动firefox
driver = getFirefoxDriver();
} else if (browser.isChrome()) {
// 启动chrome
driver = getChromeDriver();
} else if (browser.isIE()) {
// 启动IE
driver = getIEDriver();
}
return driver;
}
use of com.gargoylesoftware.htmlunit.BrowserVersion in project saga by timurstrekalov.
the class InstrumentingProxyServerIT method setUp.
@Before
public void setUp() throws Exception {
final InstanceFieldPerPropertyConfig config = new InstanceFieldPerPropertyConfig();
proxyServer = new InstrumentingProxyServer(new HtmlUnitBasedScriptInstrumenter(config));
fileServer = new FileServer(new File(getClass().getResource("/tests").toURI()).getAbsolutePath());
proxyServerPort = proxyServer.start();
fileServerPort = fileServer.start();
final String proxyUrl = "localhost:" + proxyServerPort;
final Proxy proxy = new Proxy().setProxyType(Proxy.ProxyType.MANUAL).setHttpProxy(proxyUrl).setSslProxy(proxyUrl);
final DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
desiredCapabilities.setCapability(CapabilityType.PROXY, proxy);
desiredCapabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
desiredCapabilities.setBrowserName(BrowserType.FIREFOX);
driver = new HtmlUnitDriver(desiredCapabilities) {
@Override
protected WebClient newWebClient(final BrowserVersion version) {
config.setBrowserVersion(version);
return WebClientFactory.newInstance(config);
}
};
}
Aggregations