package nl.hsac.fitnesse.fixture.slim.web.xebium;

import nl.hsac.fitnesse.fixture.slim.SlimFixtureException;
import nl.hsac.fitnesse.fixture.slim.web.BrowserTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;

/**
 * BrowserTest with some extra methods to assist HsacSeleniumDriverFixture.
 */
public class HsacXebiumBrowserTest extends BrowserTest {

    public HsacXebiumBrowserTest() {
        waitMilliSecondAfterScroll(250);
    }

    public boolean clickByXPath(String xPath) {
        WebElement element = findByXPath(xPath);
        return clickElement(element);
    }

    public boolean waitForXPathVisible(final String xPath) {
        By by = By.xpath(xPath);
        return waitForVisible(by);
    }

    public boolean waitForVisible(final By by) {
        return waitUntil(new ExpectedCondition<Boolean>() {
            @Override
            public Boolean apply(WebDriver webDriver) {
                Boolean result = Boolean.FALSE;
                WebElement element = getSeleniumHelper().findElement(by);
                if (element != null) {
                    scrollIfNotOnScreen(element);
                    result = element.isDisplayed();
                }
                return result;
            }
        });
    }

    public SlimFixtureException asSlimFixtureException(Throwable t) {
        return  (SlimFixtureException) handleException(null, null, t);
    }
}

@@ -191,142 +191,8 @@
 .By;
-%0Aimport org.openqa.selenium.WebDriver;%0Aimport org.openqa.selenium.WebElement;%0Aimport org.openqa.selenium.support.ui.ExpectedCondition;
 %0A%0A/*
@@ -334,235 +334,21 @@
 t %7B%0A
-%0A
     
-public HsacXebiumBrowserTest() %7B%0A        waitMilliSecondAfterScroll(250);%0A    %7D%0A%0A    public boolean clickByXPath(String xPath) %7B%0A        WebElement element = findByXPath(xPath);%0A        return clickElement(element);%0A    %7D%0A
+@Override
 %0A   
@@ -374,13 +374,8 @@
 tFor
-XPath
 Visi
@@ -388,621 +388,55 @@
 nal 
-String xPath) %7B%0A        By by = By.xpath(xPath);%0A        return waitForVisible(by);%0A    %7D%0A%0A    public boolean waitForVisible(final By by) %7B%0A        return waitUntil(new ExpectedCondition%3CBoolean%3E() %7B%0A            @Override%0A            public Boolean apply(WebDriver webDriver) %7B%0A                Boolean result = Boolean.FALSE;%0A                WebElement element = getSeleniumHelper().findElement(by);%0A                if (element != null) %7B%0A                    scrollIfNotOnScreen(element);%0A                    result = element.isDisplayed();%0A                %7D%0A                return result;%0A            %7D%0A        %7D
+By by) %7B%0A        return super.waitForVisible(by
 );%0A 

Simplify class, using methods now available in its superclass.