use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project archiva by apache.
the class AbstractSeleniumTest method goToLoginPage.
// Go to Login Page
public void goToLoginPage() {
logger.info("Goto login page");
loadPage(baseUrl, 30);
WebDriverWait wait = new WebDriverWait(getWebDriver(), 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("topbar-menu")));
wait.until(ExpectedConditions.or(ExpectedConditions.visibilityOfElementLocated(By.id("logout-link")), ExpectedConditions.visibilityOfElementLocated(By.id("login-link-a"))));
// are we already logged in ?
if (// isElementPresent( "logoutLink" ) )
isElementVisible("logout-link")) {
logger.info("Logging out ");
// so logout
clickLinkWithLocator("logout-link-a", false);
}
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login-link-a")));
clickLinkWithLocator("login-link-a", false);
// TODO: Check after changing jquery, bootstrap or htmlunit version
if (getWebDriver() instanceof HtmlUnitDriver) {
((JavascriptExecutor) getWebDriver()).executeScript("$('#modal-login').show();");
}
// END OF WORKAROUND
wait = new WebDriverWait(getWebDriver(), 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("modal-login")));
assertLoginModal();
}
use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project selenified by Coveros.
the class TestSetup method setupDriver.
/**
* this creates the webdriver object, which will be used to interact with
* for all browser web tests
*
* @param browser - what browser is being tested on
* @param capabilities - what capabilities are being tested with
* @return WebDriver: the driver to interact with for the test
* @throws InvalidBrowserException If a browser that is not one specified in the
* Selenium.Browser class is used, this exception will be thrown
*/
public static WebDriver setupDriver(Browser browser, DesiredCapabilities capabilities) throws InvalidBrowserException {
WebDriver driver;
// check the browser
switch(browser) {
case HTMLUNIT:
capabilities.setBrowserName("htmlunit");
capabilities.setJavascriptEnabled(true);
System.getProperties().put("org.apache.commons.logging.simplelog.defaultlog", "fatal");
java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("org.apache.http").setLevel(Level.OFF);
driver = new HtmlUnitDriver(capabilities);
break;
case FIREFOX:
FirefoxDriverManager.getInstance().forceCache().setup();
FirefoxOptions firefoxOptions = new FirefoxOptions(capabilities);
if (System.getProperty(HEADLESS_INPUT) != null && "true".equals(System.getProperty(HEADLESS_INPUT))) {
firefoxOptions.setHeadless(true);
}
driver = new FirefoxDriver(firefoxOptions);
break;
case CHROME:
ChromeDriverManager.getInstance().forceCache().setup();
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions = chromeOptions.merge(capabilities);
if (System.getProperty(HEADLESS_INPUT) != null && "true".equals(System.getProperty(HEADLESS_INPUT))) {
chromeOptions.setHeadless(true);
}
driver = new ChromeDriver(chromeOptions);
break;
case INTERNETEXPLORER:
InternetExplorerDriverManager.getInstance().forceCache().setup();
InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions(capabilities);
driver = new InternetExplorerDriver(internetExplorerOptions);
break;
case EDGE:
EdgeDriverManager.getInstance().forceCache().setup();
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions = edgeOptions.merge(capabilities);
driver = new EdgeDriver(edgeOptions);
break;
case SAFARI:
SafariOptions safariOptions = new SafariOptions(capabilities);
driver = new SafariDriver(safariOptions);
break;
case OPERA:
OperaDriverManager.getInstance().forceCache().setup();
driver = new OperaDriver(capabilities);
break;
case PHANTOMJS:
PhantomJsDriverManager.getInstance().forceCache().setup();
driver = new PhantomJSDriver(capabilities);
break;
// if the browser is not listed, throw an error
default:
throw new InvalidBrowserException("The selected browser " + browser + " is not an applicable choice");
}
return driver;
}
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 {
// Allow invoking click on non-visible elements. Prevents HtmlUnit check for currently visible element
// TODO: remove this possibility by removing UiEngineConfigurator#workWithInvisibleElements()
// 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 {
// Restore accessibility modifier
if (getElementForOperationMethod != null) {
getElementForOperationMethod.setAccessible(getElementForOperationMethodAccessible);
}
if (moveOutIfNeededMethod != null) {
moveOutIfNeededMethod.setAccessible(moveOutIfNeededMethodAccessible);
}
if (updateActiveElementMethod != null) {
updateActiveElementMethod.setAccessible(updateActiveElementMethodAccessible);
}
}
}
use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project acceptance-test-harness by jenkinsci.
the class Scroller method scrollIntoView.
/**
* The framework is expected to take care of the correct scrolling. When you are tempted to scroll from PageObjects
* or tests, there is likely a framework problem to be fixed.
*/
public void scrollIntoView(WebElement e, WebDriver driver) {
if (driver instanceof HtmlUnitDriver || (driver instanceof WrapsDriver && ((WrapsDriver) driver).getWrappedDriver() instanceof HtmlUnitDriver)) {
return;
}
WebElement element = e;
if (Objects.equals(element.getTagName(), "option")) {
// scroll select into view not option
element = e.findElement(By.xpath(".."));
}
final int eYCoord = element.getLocation().getY();
final int eXCoord = element.getLocation().getX();
final String id = element.getAttribute("id");
final JavascriptExecutor executor = (JavascriptExecutor) driver;
// Wait until web element is successfully scrolled.
try {
new Wait<>(Boolean.TRUE).withTimeout(5, // Wall-clock time
TimeUnit.SECONDS).until(() -> (Boolean) executor.executeScript(scrollJs, eYCoord, eXCoord, id));
} catch (TimeoutException ex) {
// Scrolling failed, but sometimes the element to click is already visible, let the test continue and eventually fail later
// This log message should be sufficient to diagnose the issue
LOGGER.log(Level.WARNING, "Scrolling failed, letting the test to continue anyways, but \"Element is not clickable\" error will likely be thrown", ex);
}
}
use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project cia by Hack23.
the class AbstractRoleSystemTest method getWebDriver.
/**
* Gets the web driver.
*
* @return the web driver
*/
protected final synchronized WebDriver getWebDriver() {
WebDriver driver = null;
if ("firefox".equals(browser)) {
final DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
driver = new FirefoxDriver(capabilities);
driver.manage().window().maximize();
} else if ("chrome".equals(browser)) {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--allow-insecure-localhost", "--start-maximized");
driver = new ChromeDriver(chromeOptions);
} else if ("htmlunit-firefox".equals(browser)) {
final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.FIREFOX_45);
htmlUnitDriver.setJavascriptEnabled(true);
driver = htmlUnitDriver;
} else if ("htmlunit-ie11".equals(browser)) {
final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.INTERNET_EXPLORER);
htmlUnitDriver.setJavascriptEnabled(true);
driver = htmlUnitDriver;
} else if ("htmlunit-edge".equals(browser)) {
final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.EDGE);
htmlUnitDriver.setJavascriptEnabled(true);
driver = htmlUnitDriver;
} else if ("htmlunit-chrome".equals(browser)) {
final HtmlUnitDriver htmlUnitDriver = new HtmlUnitDriver(BrowserVersion.CHROME);
htmlUnitDriver.setJavascriptEnabled(true);
driver = htmlUnitDriver;
} else {
fail("No valid browser parameter:" + browser);
}
driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);
webDriverMap.put(browser, driver);
return driver;
}
Aggregations