use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project cucumber-jvm by cucumber.
the class RentACarSupport method createCars.
public void createCars(int availableCars) {
WebDriver driver = new HtmlUnitDriver();
try {
driver.get("http://localhost:9878/rentit/create");
WebElement numberOfCarsToCreate = driver.findElement(By.id("numberOfCars"));
numberOfCarsToCreate.clear();
numberOfCarsToCreate.sendKeys("" + availableCars);
WebElement createButton = driver.findElement(By.id("createButton"));
createButton.click();
} finally {
driver.close();
}
}
use of org.openqa.selenium.htmlunit.HtmlUnitDriver 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);
}
};
}
use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project ats-framework by Axway.
the class HiddenHtmlElementUtils method mouseClick.
@PublicAtsApi
public static void mouseClick(HtmlUnitWebElement webElement) {
Method getElementForOperationMethod = null;
boolean getElementForOperationMethodAccessible = false;
Method moveOutIfNeededMethod = null;
boolean moveOutIfNeededMethodAccessible = false;
Method updateActiveElementMethod = null;
boolean updateActiveElementMethodAccessible = false;
try {
// change access modifiers of some methods
getElementForOperationMethod = HtmlUnitMouse.class.getDeclaredMethod("getElementForOperation", Coordinates.class);
getElementForOperationMethodAccessible = getElementForOperationMethod.isAccessible();
getElementForOperationMethod.setAccessible(true);
moveOutIfNeededMethod = HtmlUnitMouse.class.getDeclaredMethod("moveOutIfNeeded", DomElement.class);
moveOutIfNeededMethodAccessible = moveOutIfNeededMethod.isAccessible();
moveOutIfNeededMethod.setAccessible(true);
updateActiveElementMethod = HtmlUnitMouse.class.getDeclaredMethod("updateActiveElement", DomElement.class);
updateActiveElementMethodAccessible = updateActiveElementMethod.isAccessible();
updateActiveElementMethod.setAccessible(true);
// get the target element
HtmlUnitDriver htmlUnitDriver = (HtmlUnitDriver) webElement.getWrappedDriver();
HtmlUnitMouse mouse = (HtmlUnitMouse) htmlUnitDriver.getMouse();
HtmlElement element = (HtmlElement) getElementForOperationMethod.invoke(mouse, webElement.getCoordinates());
moveOutIfNeededMethod.invoke(mouse, element);
if (htmlUnitDriver.isJavascriptEnabled()) {
if (!(element instanceof HtmlInput)) {
element.focus();
}
element.mouseOver();
element.mouseMove();
}
HtmlUnitKeyboard keyboard = (HtmlUnitKeyboard) htmlUnitDriver.getKeyboard();
element.click(keyboard.isShiftPressed(), keyboard.isCtrlPressed(), keyboard.isAltPressed());
updateActiveElementMethod.invoke(mouse, element);
} catch (IOException ioe) {
throw new WebDriverException(ioe);
} catch (ScriptException e) {
// we need only our exception if such exists
Throwable uiEngineException = e.getCause();
while (uiEngineException != null && !uiEngineException.getClass().getName().toLowerCase().contains("com.axway.ats")) {
uiEngineException = uiEngineException.getCause();
}
if (uiEngineException != null) {
throw (RuntimeException) uiEngineException;
}
// Log the exception with level WARN, because in the main Selenium implementation
// (HtmlUnitMouse.click(coordinates)) the exception is even skipped
log.warn("Script error while clicking web element. " + webElement.toString(), e);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (getElementForOperationMethod != null) {
getElementForOperationMethod.setAccessible(getElementForOperationMethodAccessible);
}
if (moveOutIfNeededMethod != null) {
moveOutIfNeededMethod.setAccessible(moveOutIfNeededMethodAccessible);
}
if (updateActiveElementMethod != null) {
updateActiveElementMethod.setAccessible(updateActiveElementMethodAccessible);
}
}
}
Aggregations