use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project ats-framework by Axway.
the class HiddenBrowserDriver method start.
@Override
@PublicAtsApi
public void start() {
webDriver = new HtmlUnitDriver(this.browserVersion);
webDriver.setJavascriptEnabled(true);
setProxyIfAvailable();
fixHtmlUnitBehaviour();
log.info("Opening URL: " + url);
webDriver.get(url);
}
use of org.openqa.selenium.htmlunit.HtmlUnitDriver in project ats-framework by Axway.
the class AbstractHtmlEngine method reloadFrames.
@PublicAtsApi
public void reloadFrames() {
// real browsers reloads the frames automatically
if (webDriver instanceof HtmlUnitDriver) {
Field webClientField = null;
boolean fieldAccessibleState = false;
try {
// Retrieve current WebClient instance (with the current page) from the Selenium WebDriver
TargetLocator targetLocator = webDriver.switchTo();
webClientField = targetLocator.getClass().getDeclaringClass().getDeclaredField("webClient");
fieldAccessibleState = webClientField.isAccessible();
webClientField.setAccessible(true);
WebClient webClient = (WebClient) webClientField.get(targetLocator.defaultContent());
HtmlPage page = (HtmlPage) webClient.getCurrentWindow().getEnclosedPage();
for (final FrameWindow frameWindow : page.getFrames()) {
final BaseFrameElement frame = frameWindow.getFrameElement();
// use == and not equals(...) to identify initial content (versus URL set to "about:blank")
if (frame.getEnclosedPage().getWebResponse().getWebRequest().getUrl() == WebClient.URL_ABOUT_BLANK) {
String src = frame.getSrcAttribute();
if (src != null && !src.isEmpty()) {
final URL url;
try {
url = ((HtmlPage) frame.getEnclosedPage()).getFullyQualifiedUrl(src);
} catch (final MalformedURLException e) {
String message = "Invalid src attribute of " + frame.getTagName() + ": url=[" + src + "]. Ignored.";
final IncorrectnessListener incorrectnessListener = webClient.getIncorrectnessListener();
incorrectnessListener.notify(message, this);
return;
}
if (isAlreadyLoadedByAncestor(url, ((HtmlPage) frame.getEnclosedPage()))) {
String message = "Recursive src attribute of " + frame.getTagName() + ": url=[" + src + "]. Ignored.";
final IncorrectnessListener incorrectnessListener = webClient.getIncorrectnessListener();
incorrectnessListener.notify(message, this);
log.info("Frame already loaded: " + frame.toString());
return;
}
try {
final WebRequest request = new WebRequest(url);
request.setAdditionalHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9, text/*;q=0.7, */*;q=0.5");
if (frameWindow.getName() == null || frameWindow.getName().isEmpty()) {
frameWindow.setName("frame_" + page.getFrames().indexOf(frameWindow));
}
webClient.loadWebResponseInto(webClient.loadWebResponse(request), frameWindow);
log.info("Frame loaded: " + frame.toString());
} catch (IOException e) {
log.error("Error when getting content for " + frame.getTagName() + " with src=" + url, e);
}
}
} else {
log.info("Frame already loaded: " + frame.toString());
}
}
} catch (Exception e) {
throw new SeleniumOperationException("Error retrieving internal Selenium web client", e);
} finally {
if (webClientField != null) {
webClientField.setAccessible(fieldAccessibleState);
}
}
}
}
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 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 org.openqa.selenium.htmlunit.HtmlUnitDriver in project archiva by apache.
the class WebDriverTest method simpletest.
@Test
public void simpletest() throws Exception {
String url = WebdriverUtility.getBaseUrl() + "/index.html?request_lang=en";
goTo(url);
// wait until topbar-menu-container is feeded
// await().atMost(20, TimeUnit.SECONDS).until($("#topbar-menu")).present();
await().untilPredicate((fl) -> $("#topbar-menu").present());
await().atMost(10, TimeUnit.SECONDS).untilPredicate((fl) -> el("#create-admin-link-a").conditions().clickable() || el("#login-link-a").conditions().clickable());
FluentList<FluentWebElement> elements = find("#create-admin-link-a");
if (!elements.isEmpty() && elements.get(0).displayed()) {
WebElement webElement = elements.get(0).getElement();
Assert.assertEquals("Create Admin User", webElement.getText());
} else {
elements = find(By.id("login-link-a"));
for (FluentWebElement element : elements) {
log.info("Found login link: " + element.getElement().getTagName() + " " + element.getElement().getText());
}
WebElement webElement = elements.get(0).getElement();
if (getDriver() instanceof HtmlUnitDriver) {
Assert.assertEquals("LOGIN", webElement.getText().toUpperCase());
} else {
Assert.assertEquals("LOGIN", webElement.getText());
}
}
}
Aggregations