Search in sources :

Example 16 with HtmlUnitDriver

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);
}
Also used : HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 17 with HtmlUnitDriver

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);
            }
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) BaseFrameElement(com.gargoylesoftware.htmlunit.html.BaseFrameElement) IOException(java.io.IOException) FrameWindow(com.gargoylesoftware.htmlunit.html.FrameWindow) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) WebClient(com.gargoylesoftware.htmlunit.WebClient) IncorrectnessListener(com.gargoylesoftware.htmlunit.IncorrectnessListener) URL(java.net.URL) SeleniumOperationException(com.axway.ats.uiengine.exceptions.SeleniumOperationException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Field(java.lang.reflect.Field) WebRequest(com.gargoylesoftware.htmlunit.WebRequest) TargetLocator(org.openqa.selenium.WebDriver.TargetLocator) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 18 with HtmlUnitDriver

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();
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver)

Example 19 with HtmlUnitDriver

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);
}
Also used : BrowserVersion(com.gargoylesoftware.htmlunit.BrowserVersion) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Before(org.junit.Before)

Example 20 with HtmlUnitDriver

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());
        }
    }
}
Also used : FluentWebElement(org.fluentlenium.core.domain.FluentWebElement) WebElement(org.openqa.selenium.WebElement) FluentWebElement(org.fluentlenium.core.domain.FluentWebElement) HtmlUnitDriver(org.openqa.selenium.htmlunit.HtmlUnitDriver) Test(org.junit.Test) FluentTest(org.fluentlenium.adapter.junit.FluentTest)

Aggregations

HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)39 WebDriver (org.openqa.selenium.WebDriver)12 WebElement (org.openqa.selenium.WebElement)10 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)9 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)9 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)7 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)6 Before (org.junit.Before)5 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)5 Test (org.junit.Test)4 SafariDriver (org.openqa.selenium.safari.SafariDriver)4 PublicAtsApi (com.axway.ats.common.PublicAtsApi)3 BrowserVersion (com.gargoylesoftware.htmlunit.BrowserVersion)3 WebClient (com.gargoylesoftware.htmlunit.WebClient)3 File (java.io.File)3 URL (java.net.URL)3 TimeoutException (org.openqa.selenium.TimeoutException)3 EdgeDriver (org.openqa.selenium.edge.EdgeDriver)3 PhantomJSDriver (org.openqa.selenium.phantomjs.PhantomJSDriver)3 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)3