org.fluentlenium.adapter.spock.FluentSpecification.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fluentlenium-spock Show documentation
Show all versions of fluentlenium-spock Show documentation
Spock Adapter for FluentLenium
package org.fluentlenium.adapter.spock
import org.fluentlenium.adapter.FluentTestRunnerAdapter
import org.fluentlenium.adapter.junit.FluentTestRule
import org.fluentlenium.core.domain.FluentList
import org.fluentlenium.core.domain.FluentWebElement
import org.fluentlenium.core.search.SearchFilter
import org.junit.ClassRule
import org.junit.Rule
import org.junit.rules.TestRule
import org.junit.runner.Description
import org.junit.runners.model.Statement
import org.openqa.selenium.By
import org.openqa.selenium.WebElement
import spock.lang.Specification
class FluentSpecification extends Specification {
@Delegate
private FluentSpecificationAdapter fl = new FluentSpecificationAdapter()
FluentList $(List rawElements) {
return fl.$(rawElements)
}
FluentList $(By locator, SearchFilter... filters) {
return fl.$(locator, filters)
}
FluentList $(String selector, SearchFilter... filters) {
return fl.$(selector, filters)
}
FluentList $(SearchFilter... filters) {
return fl.$(filters)
}
@Rule
public TestRule watchman = new FluentTestRule(this) {
@Override
void starting(Description description) {
super.starting(description)
specStarting(description.getTestClass(), description.getDisplayName())
}
@Override
void finished(Description description) {
super.finished(description)
specFinished(description.getTestClass(), description.getDisplayName())
}
@Override
void failed(Throwable e, Description description) {
super.failed(e, description)
specFailed(e, description.getTestClass(), description.getDisplayName())
}
}
@ClassRule
public static TestRule classWatchman = new TestRule() {
@Override
Statement apply(Statement base, Description description) {
return new Statement() {
@Override
void evaluate() throws Throwable {
try {
base.evaluate()
} finally {
FluentTestRunnerAdapter.afterClass(description.getTestClass())
}
}
}
}
}
}