Search in sources :

Example 1 with UnsupportedCommandException

use of org.openqa.selenium.UnsupportedCommandException in project acceptance-test-harness by jenkinsci.

the class FallbackConfig method createWebDriver.

/**
 * Creates a {@link WebDriver} for each test, then make sure to clean it up at the end.
 */
@Provides
@TestScope
public WebDriver createWebDriver(TestCleaner cleaner, TestName testName, ElasticTime time) throws IOException {
    WebDriver base = createWebDriver(cleaner, testName);
    // Make sure the window has minimal resolution set, even when out of the visible screen.
    // Note - not maximizing here any more because that doesn't do anything.
    Dimension oldSize = base.manage().window().getSize();
    if (oldSize.height < 1050 || oldSize.width < 1680) {
        base.manage().window().setSize(new Dimension(1680, 1050));
    }
    final EventFiringWebDriver d = new EventFiringWebDriver(base);
    d.register(new Scroller());
    try {
        d.manage().timeouts().pageLoadTimeout(time.seconds(PAGE_LOAD_TIMEOUT), TimeUnit.MILLISECONDS);
        d.manage().timeouts().implicitlyWait(time.seconds(IMPLICIT_WAIT_TIMEOUT), TimeUnit.MILLISECONDS);
    } catch (UnsupportedCommandException e) {
        // sauce labs RemoteWebDriver doesn't support this
        LOGGER.info(base + " doesn't support page load timeout");
    }
    cleaner.addTask(new Statement() {

        @Override
        public void evaluate() {
            switch(getBrowser()) {
                case "firefox":
                case "saucelabs-firefox":
                case "remote-webdriver-firefox":
                    // https://github.com/mozilla/geckodriver/issues/1151
                    // https://bugzilla.mozilla.org/show_bug.cgi?id=1264259
                    // https://bugzilla.mozilla.org/show_bug.cgi?id=1434872
                    d.navigate().to("about:mozilla");
                    Alert alert = ExpectedConditions.alertIsPresent().apply(d);
                    if (alert != null) {
                        alert.accept();
                        d.navigate().refresh();
                    }
            }
            d.quit();
        }

        @Override
        public String toString() {
            return "Close WebDriver after test";
        }
    });
    return d;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) RemoteWebDriver(org.openqa.selenium.remote.RemoteWebDriver) UnsupportedCommandException(org.openqa.selenium.UnsupportedCommandException) Statement(org.junit.runners.model.Statement) EventFiringWebDriver(org.openqa.selenium.support.events.EventFiringWebDriver) Alert(org.openqa.selenium.Alert) Dimension(org.openqa.selenium.Dimension) Scroller(org.jenkinsci.test.acceptance.selenium.Scroller) TestScope(org.jenkinsci.test.acceptance.guice.TestScope) Provides(com.google.inject.Provides)

Example 2 with UnsupportedCommandException

use of org.openqa.selenium.UnsupportedCommandException in project selenium_java by sergueik.

the class BaseTest method createWindow.

// based on
// http://automated-testing.info/t/kak-ya-mogu-otkrit-v-firefox-dve-vkladki-i-perehodit-s-odnoj-na-vtoruyu-pri-neobhodimosti/1741/4
// Creates a new window / browser tab using script injection
// Loads a specified url there
protected String createWindow(String url) {
    Set<String> oldHandles = driver.getWindowHandles();
    parentHandle = driver.getWindowHandle();
    // Inject an anchor element
    String name = "Window_" + instanceCount++;
    executeScript("var anchorTag = document.createElement('a'); " + "anchorTag.appendChild(document.createTextNode('nwh'));" + "anchorTag.setAttribute('id', arguments[0]);" + "anchorTag.setAttribute('href', arguments[1]);" + "anchorTag.setAttribute('target', '_blank');" + "anchorTag.setAttribute('style', 'display:block;');" + "var firstElement = document.getElementsByTagName('body')[0].getElementsByTagName('*')[0];" + "firstElement.parentElement.appendChild(anchorTag);", name, url);
    // common error with this approach: Element is not clickable at point
    // HTML, HEAD, BODY, some element
    WebElement element = driver.findElement(By.id(name));
    sleep(1000);
    try {
        // element.getLocation()
        System.err.println("Scrolling to " + element.getLocation().y);
        scroll(element.getLocation().x, element.getLocation().y);
    } catch (UnsupportedCommandException e) {
    }
    scrolltoElement(element);
    // Click on the anchor element
    element.click();
    Set<String> newHandles = driver.getWindowHandles();
    newHandles.removeAll(oldHandles);
    // the remaining item is the new window handle
    for (String handle : newHandles) {
        return handle;
    }
    return null;
}
Also used : UnsupportedCommandException(org.openqa.selenium.UnsupportedCommandException) WebElement(org.openqa.selenium.WebElement)

Example 3 with UnsupportedCommandException

use of org.openqa.selenium.UnsupportedCommandException in project mycore by MyCoRe-Org.

the class SideBarIT method testSideBarResize.

@Test
public /**
 * Ignored because https://github.com/mozilla/geckodriver/issues/233
 */
void testSideBarResize() throws Exception {
    this.setTestName(getClassname() + "-testSideBarResize");
    this.getDriver();
    this.getAppController().openViewer(this.getDriver(), getTestDerivate());
    ImageViewerController controller = this.getViewerController();
    ToolBarController tbController = controller.getToolBarController();
    SideBarController sbController = controller.getSideBarController();
    tbController.pressButton(ToolBarController.BUTTON_ID_SIDEBAR_CONTROLL);
    tbController.clickElementById(ImageOverviewController.IMAGE_OVERVIEW_SELECTOR);
    int sbWidthStart = sbController.getSideBarWidth();
    try {
        // Firefox does not support actions so we just let the test pass.
        sbController.dragAndDropByXpath("//div[contains(@class,\"sidebar\")]/span[@class=\"resizer\"]", 50, 0);
    } catch (UnsupportedCommandException e) {
        LOGGER.warn("Driver does not support Actions", e);
        return;
    }
    int sbWidthEnd = sbController.getSideBarWidth();
    assertLess(sbWidthEnd, sbWidthStart, "Sidebar width schould be increased!");
}
Also used : UnsupportedCommandException(org.openqa.selenium.UnsupportedCommandException) SideBarController(org.mycore.iview.tests.controller.SideBarController) ImageViewerController(org.mycore.iview.tests.controller.ImageViewerController) ToolBarController(org.mycore.iview.tests.controller.ToolBarController) Test(org.junit.Test)

Example 4 with UnsupportedCommandException

use of org.openqa.selenium.UnsupportedCommandException in project mycore by MyCoRe-Org.

the class SideBarIT method testOverviewLayout.

@Test
public void testOverviewLayout() throws InterruptedException {
    this.setTestName(getClassname() + "-testOvervieLayout");
    this.getDriver();
    this.getAppController().openViewer(this.getDriver(), getTestDerivate());
    ImageViewerController controller = this.getViewerController();
    ToolBarController tbController = controller.getToolBarController();
    SideBarController sbController = controller.getSideBarController();
    tbController.pressButton(ToolBarController.BUTTON_ID_SIDEBAR_CONTROLL);
    tbController.clickElementById(ImageOverviewController.IMAGE_OVERVIEW_SELECTOR);
    int before = sbController.countThumbnails();
    try {
        sbController.dragAndDropByXpath("//div[contains(@class,'sidebar')]/span[@class='resizer']", 300, 0);
    } catch (UnsupportedCommandException e) {
        LOGGER.warn("Driver does not support Actions", e);
        return;
    }
    Thread.sleep(1000);
    int after = sbController.countThumbnails();
    Assert.assertEquals(2 * before, after);
}
Also used : UnsupportedCommandException(org.openqa.selenium.UnsupportedCommandException) SideBarController(org.mycore.iview.tests.controller.SideBarController) ImageViewerController(org.mycore.iview.tests.controller.ImageViewerController) ToolBarController(org.mycore.iview.tests.controller.ToolBarController) Test(org.junit.Test)

Aggregations

UnsupportedCommandException (org.openqa.selenium.UnsupportedCommandException)4 Test (org.junit.Test)2 ImageViewerController (org.mycore.iview.tests.controller.ImageViewerController)2 SideBarController (org.mycore.iview.tests.controller.SideBarController)2 ToolBarController (org.mycore.iview.tests.controller.ToolBarController)2 Provides (com.google.inject.Provides)1 TestScope (org.jenkinsci.test.acceptance.guice.TestScope)1 Scroller (org.jenkinsci.test.acceptance.selenium.Scroller)1 Statement (org.junit.runners.model.Statement)1 Alert (org.openqa.selenium.Alert)1 Dimension (org.openqa.selenium.Dimension)1 WebDriver (org.openqa.selenium.WebDriver)1 WebElement (org.openqa.selenium.WebElement)1 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)1 EventFiringWebDriver (org.openqa.selenium.support.events.EventFiringWebDriver)1